Javascript wscript. Shell

Source: Internet
Author: User

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 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

The following table describes the properties related to the wshurlshortcut object.
Attribute description
Full path of the fullname URL Shortcut object.
The target path of the targetpath URL Shortcut object.

The following table describes the methods related to the wshurlshortcut object.
Method description
Save saves the shortcut to the specified file system.
Wshurlshortcut. fullname
The fullname attribute provides the complete path of the shortcut object.
Syntax
Wshurlshortcut. fullname = strfullname
Wshurlshortcut. targetpath
The targetpath attribute provides the target path of the shortcut object.
Syntax
Wshurlshortcut. targetpath = strtargetpath
Wshurlshortcut. Save
The Save method saves a shortcut that points to the location specified by the fullname attribute.
Syntax
Wshurlshortcut. Save
Wshshell. expandenvironmentstrings
The expandenvironmentstrings method extends the process environment variable in strstring and returns the result string. The variable is enclosed by the '%' character.
Environment variables are case insensitive.
Syntax
Wshshell. expandenvironmentstrings (strstring) = strexpandedstring
Example
Msgbox "prompt is" & wshshell. expandenviromentstrings ("% prompt % ")

Wshshell. Popup
The popup method displays a pop-up message box window. The messages contained in the message box are specified by strtext. The title of the message box is specified by strtitle. If strtitle is omitted, the window title is Windows Scripting host.
Syntax
Wshshell. Popup (strtext, [natsecondstowait], [strtitle], [nattype]) = intbutton
Note
If natsecondstowait is provided and its value is greater than zero, the message box is closed after natsecondstowait seconds.
What is nattype in Win32? The MessageBox function is the same. The following table lists the values and meanings of nattype. The values in the following table can be combined.
Button type
Value description
0. The "OK" button is displayed.
1. The "OK" and "cancel" buttons are displayed.
2. The "Terminate", "retry", and "Ignore" buttons are displayed.
3. the "yes", "no", and "cancel" buttons are displayed.
4. the "yes" and "no" buttons are displayed.
5. The "retry" and "cancel" buttons are displayed.

Icon type
Value description
16 show the stop icon
32 display question mark icon
48 display exclamation point icon
64 Display Information Mark icon

The above two tables do not cover all nattype values. For a complete list, see the Win32 documentation.
The returned value intbutton indicates the number of the buttons clicked by the user. If you do not click the button before natsecondstowait seconds, set intbutton to-1.
Value description
1 "OK" button
2 "cancel" button
3 "stop" button
4 "retry" button
5 "Ignore" button
6 "yes" button
7 "no" button

Example
Set wshshell = wscript. Createobject ("wscript. Shell ")
Wshshell. Popup "Where do you want to go today? "
See
Wscript. Echo Method
Wscript. Echo
Echo parameters are displayed in the window (in cscript.exe.
Parameters are separated by spaces. In cscript.exe, this method outputs a carriage return/line feed (cr lf) after the last parameter is displayed ).
Syntax
Wscript. Echo [anyarg...]
Example
Wscript. Echo
Wscript. Echo 1, 2, 3
Wscript. Echo "Windows Scripting host is cool ."
Wshshell. regdelete
Regdelete deletes a key or value named strname from the registry.
Syntax
Wshshell. regdelete strname
Parameters
Strname
If strname ends with a backslash (), this method deletes the key instead of the value.
The strname parameter must start with the root key name of one of the following columns:
Short Root Key name long root key name
Hkcu HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
Hkcr hkey_classes_root
HKEY_USERS
Hkey_current_config

Example
Set wshshell = wscript. Createobject ("wscript. Shell ")
Wshshell. regdelete "hkcuscriptenginevalue" ''delete value "value"
Wshshell. regdelete "hkcuscriptenginekey" ''delete key "key"
See
Wshshell. regread method, wshshell. regwrite Method

Wshshell. regread
The regread method returns the registry key or value named strname.
Syntax
Wshshell. regread (strname) = strvalue
Parameters
Strname
If strname ends with a backslash (), this method returns the key instead of the value.
The strname parameter must start with the root key name of the following column.
Short long
Hkcu HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
Hkcr hkey_classes_root
HKEY_USERS
Hkey_current_config

Note
The regread method only supports the REG_SZ, reg_expand_sz, REG_DWORD, REG_BINARY, and reg_multi_sz data types. If the registry has other data types, regread returns disp_e_typemismatch.
Example
Set wshshell = wscript. Createobject ("wscript. Shell ")
Wshshell. regread ("hkcuscriptengineval") ''read from Value" Val"
Wshshell. regread ("hkcuscriptenginekey") ''read from key" key"
See
Wshshell. regdelete method, wshshell. regwrite Method

Wshshell. regwrite
The regwrite method sets the registry key or value named strname.
Syntax
Wshshell. regwrite strname, anyvalue, [strtype]
Parameters
Strname
If strname ends with a backslash (), this method sets the key instead of the value.
The strname parameter must start with the root key of the following column.
Short long
Hkcu HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
Hkcr hkey_classes_root
HKEY_USERS
Hkey_current_config

Anyvalue
When the strtype is REG_SZ or reg_expand_sz, The regwrite method automatically converts anyvalue to a string. If strtype is REG_DWORD, anyvalue is converted to an integer. If strtype is REG_BINARY, anyvalue must be an integer.
Strtype
The regwrite method supports the following strtypes: REG_SZ, reg_expand_sz, REG_DWORD, and REG_BINARY. If other data types are passed as strtype, regwrite returns e_invalidarg.
Example
Set wshshell = wscript. Createobject ("wscript. Shell ")
Wshshell. regwrite "hkcuscriptenginevalue", "some string value"
Wshshell. regwrite "hkcuscriptenginekey", 1 "REG_DWORD"
See
Wshshell. regdelete method, wshshell. regwrite Method

Wshshell. Run
Run method to create a new process that runs strcommand in the intwindowstyle window.
Syntax
Wshshell. Run (strcommand, [intwindowstyle], [blnwaitonreturn])
Parameters
Strcommand
Environment variables within the strcommand parameter are automatically extended.
Intwindowstyle
This is the value of the wshowwindow element set for the new process in the startupinfo structure. The meaning is the same as that of the ncmdshow parameter in showwindow. One of the following values is recommended. Name Value Meaning
Sw_hide
0. Hide the window and activate another window.
Sw_minimize
6. Minimize the specified window and activate the next top-level window in Z-order.
Sw_restore
9. Activate and display the window. If the window is minimized or maximized, It is restored to the original size and position. Specify this flag when restoring the minimal window of the application.
Sw_show
5. Activate and display the window with the current size and position.
Sw_showmaximized
3. Activate the window and maximize the display.
Sw_showminimized
2. Activate the window and minimize the display of the window.
Sw_showminnoactive
7. Minimize the display window. The activity window maintains the activity.
Sw_showna
8. The window is displayed in the current status. The activity window maintains the activity.
Sw_shownoactivate
4. display by the nearest size and position of the window. The activity window maintains the activity.
Sw_shownormal
1. Activate and display a window. If the window is minimized or maximized, It is restored to its original size and position.

Blnwaitonreturn
If you do not specify blnwaitonreturn or its value is false, this method immediately returns to the script for further execution without waiting for the process to end.
If blnwaitonreturn is set to true, the run method returns any error code returned by the application. If blnwaitonreturn is not specified or its value is false, run Returns Error code 0 (zero ).
Example
''This fragment launches notepad with the current executed script
Set wshshell = wscript. Createobject ("wscript. Shell ")
Wshshell. Run ("Notepad" & wscript. scriptfullname)
Wshshell. Run ("% WINDIR % Notepad" & wscript. scriptfullname)
''This fragment returns the error code from the executed application
Return = wshshell. Run ("Notepad" & wscript. scriptfullname, 1, true)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.