Category: Program
WshShell object
ProgID Wscript. Shell
File Name WSHom. Ocx
CLSID F935DC22-1CF0-11d0-ADB9-00C04FD58A0B
IID F935DC21-1CF0-11d0-ADB9-00C04FD58A0B
The following table describes the properties related to the WshShell object.
Attribute description
Environment returns the WshEnvironment collection object.
SpecialFolders uses the WshSpecialFolders object to provide access to Windows shell Folders, such as desktop folders, Start Menu folders, and personal document folders.
The following table describes the methods related to the WshShell object.
Method description
CreateShortcut is created and the WshShortcut object is returned.
ExpandEnvironmentStrings extends the PROCESS environment variables and returns the result string.
Popup displays the message window containing the specified message.
RegDelete deletes the specified key or value from the registry.
RegRead returns the specified key or value from the registry.
RegWrite sets the specified key or value in the registry.
Run creates a new process and runs the specified command in the specified window style.
WshShell. Environment
The Environment attribute returns the WshEnvironment object.
Syntax
WshShell. Environment ([strType]) = ob1_shenvironment
Note
If strType specifies the location of the environment variable, the values may be "System", "User", "Volatile", and "Process ". If strType is not provided, this method retrieves system environment variables in Windows NT or process environment variables in Windows 95.
For Windows 95, the strType parameter only supports "Process ".
The following variables are provided by the Windows operating system. The script can also obtain environment variables set by other applications.
Description
NUMBER_OF_PROCESSORS: Number of processors running on the computer.
PROCESSOR_ARCHITECTURE the type of processor used by the user workstation.
PROCESSOR_IDENTIFIER the processor ID of the user workstation.
PROCESSOR_LEVEL the processor level of the user workstation.
PROCESSOR_REVISION the processor version of the user workstation.
The operating system used by the OS user workstation.
COMSPEC is the command used to run the "command prompt" window (usually cmd.exe ).
HOMEDRIVE local master drive (usually C drive ).
The default path of the HOMEPATH user (usually usersdefault on Windows NT ).
PATH environment variable.
The extension of the PATHEXT executable file (usually. com,. exe,. bat, or. cmd ).
PROMPT command PROMPT (usually $ P $ G ).
The local drive where the SYSTEMDRIVE system is located (for example, c :).
SYSTEMROOT system directory (for example, c: winnt ). Same as WINDIR.
WINDIR system directory (for example, c: winnt ). Same as SYSTEMROOT.
TEMP stores the directory of temporary files (for example, c: temp ). Users can change the value.
TMP directory for storing temporary files (for example, c: temp ). Users can change the value.
Example
''Retrieve the NUMBER_OF_PROCESSORS system environment variable
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
Set WshSysEnv = WshShell. Environment ("SYSTEM ")
Wscript. Echo WshSysEnv ("NUMBER_OF_PROCESSORS ")
See
WshEnvironment object
WshEnvironment object
The WshEnvironment object is not provided directly and can be accessed using the WshShell. Environment attribute.
ProgID N/
File Name WSHom. Ocx
CLSID
IID
The following table describes the attributes associated with the WshEnvironment object.
Attribute description
Item.
Count refers to the number of enumerated items.
The number of length enumeration items (JScript ).
The following table describes the methods associated with the WshEnvironment object.
Method description
Remove deletes the specified environment variable.
WshShell. SpecialFolders
The SpecialFolders property provides the WshSpecialFolders object to Access Windows shell Folders, such as desktop folders, Start Menu folders, and personal document folders.
Syntax
WshShell. SpecialFolders = obw.shspecialfolders
Example
''This code fragment shows how to access the desktop folder
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
MsgBox "Your desktop is" & WshShell. SpecialFolders ("Desktop ")
See
WshSpecialFolders object
WshSpecialFolders object
This object is not provided directly. To obtain the WshSpecialFolders object, use the WshShell. SpecialFolders attribute.
ProgID N/
File Name WSHom. Ocx
CLSID
IID
The following table describes the attributes associated with the WshSpecialFolders object.
Attribute description
Item specifies the full path of the folder (default ).
Count refers to the number of enumerated items.
The number of length enumeration items (JScript ).
WshSpecialFolders. Item
The full path of the folder specified by strFolderName is returned. It is the default property.
Syntax
WshShell. SpecialFolders. Item ("strFolderName") = strFolderPath
WshShell. SpecialFolders ("strFolderName") = strFolderPath
Note
If the requested folder (strFolderName) is unavailable, WshShell. SpecialFolders ("strFolderName") returns NULL. For example, Windows 95 does not have the AllUsersDesktop folder. If strFolderName = AllUsersDesktop, NULL is returned.
Windows 95 and Windows NT 4.0 provide the following specified folders:
AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates
Example
''This fragment returns the full path for the Windows Desktop folder
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
StrMyDesktop = WshShell. SpecialFolders ("Desktop ")
''List all special folders
For Each strFolder In WshShell. SpecialFolders
MsgBox strFolder
Next
See
WshShell. SpecialFolders attributes
WshShell. CreateShortcut
The CreateShortcut method creates a WshShortcut object and returns it. If the shortcut title ends with a. url, the WshURLShortcut object is created.
Syntax
WshShell. CreateShortcut (strPathname) = objShortcut
Example
''This code fragment creates a shortcut
''To the currently executing script
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
Set oShellLink = WshShell. CreateShortcut ("Current Script. lnk ")
OShellLink. TargetPath = Wscript. ScriptFullName
OShellLink. Save
Set oUrlLink = WshShell. CreateShortcut ("Microsoft Web Site. URL ")
OUrlLink. TargetPath = "http://www.microsoft.com"
OUrlLink. Save
See
WshShortcut object and WshUrlShortcut object
WshShortcut object
This object is not provided directly. To obtain the WshShortcut object, use the WshShell. CreateShortcut method.
ProgID N/
File Name WSHom. Ocx
CLSID F935DC28-1CF0-11d0-ADB9-00C04FD58A0B
IID F935DC27-1CF0-11d0-ADB9-00C04FD58A0B
The following table describes the properties related to the WshShortcut object.
Attribute description
Parameters of the Arguments shortcut object.
Description of the shortcut object.
The Hotkey of the shortcut object.
The icon position of the IconLocation shortcut object.
The target path of the TargetPath shortcut object.
Window style of the WindowStyle shortcut object.
The working directory of the WorkingDirectory shortcut object.
The following table describes the methods related to the WshShortcut object.
Method description
Save saves shortcuts to the specified file system.
WshShortcut. Arguments
The Arguments attribute provides the parameters of the shortcut object.
Syntax
WshShortcut. Arguments = strArguments
WshShortcut. Description
The Description attribute describes the shortcut objects.
Syntax
WshShortcut. Description = strDescription
WshShortcut. Hotkey
The HotKey attribute provides the HotKey of the shortcut object. The hotkey is the keyboard shortcut for starting or Switching programs.
Syntax
WshShortcut. HotKey = strHotKey
Note
The strHotKey BNF syntax is as follows:
Hotkey: = modifier * keyname
Modifier: = "ALT +" | "CTRL +" | "SHIFT +" | "EXT +"
Keyname: = "A" .. "Z" |
"0"... "9" |
"Back" | "Tab" | "Clear" | "Return" |
"Escape" | "Space" | "Prior" |...
The names of all keys can be found in WINUSER. H. The hotkeys are case insensitive.
The hotkey can only activate shortcuts on Windows desktop or Windows Start Menu.
Windows resource manager does not accept ESC, ENTER, TAB, SPACE, print screen, or BACKSPACE, even if WshShortcut. Hotkey follows Win32 API support. Therefore, we recommend that you do not use these keys in shortcuts.
Example
Set WshShell = Wscript. CreateObject ("Wscript. WshShell ")
StrDesktop = WshShell. SpecialFolders ("Desktop ")
Set oMyShortcut = WshShell. CreateShortcut (strDesktop & "a_key.lnk ")
OMyShortcut. TargetPath = "%windir#notepad.exe"
OMyShortCut. Hotkey = "ALT + CTRL + F"
OMyShortCut. Save
Wscript. Echo oMyShortCut. HotKey = "Alt + Ctrl + F"
See
WshSpecialFolders object
WshShortcut. IconLocation
The IconLocation attribute provides the icon location of the shortcut object. The format of the icon position should be "Path, index ".
Syntax
WshShortcut. IconLocation = strIconLocation
WshShortcut. TargetPath
The TargetPath attribute provides the target path of the shortcut object.
Syntax
WshShortcut. TargetPath = strTargetPath
WshShortcut. WindowStyle
The WindowStyle attribute provides the window style of the shortcut object.
Syntax
WshShortcut. WindowStyle = natWindowStyle
WshShortcut. WorkingDirectory
WorkingDirectory provides a working directory for a shortcut object.
Syntax
WshShortcut. WorkingDirectory = strWorkingDirectory
WshShortcut. Save
The Save method saves the shortcut object to the location specified by the FullName attribute.
Syntax
WshShortcut. Save
WshUrlShortcut object
This object is not provided directly. To obtain the WshUrlShortcut object, you can use the WshShell. CreateShortcut method.
ProgID N/
File Name WSHom. Ocx
CLSID
IID