WSH is an abbreviated form of "Windows Scripting Host". Its Common Chinese name is "Windows Script Host ".
Main Wscript object
WScript. Echo WScript. BuildVersion
'Build version number of the WSH Script Host
WScript. Echo WScript. FullName
'Return the path where the WSCRIPT or CSCRIPT host is located.
WScript. Echo WScript. Interactive
'Return to the script mode. Only the interaction mode and batch processing mode are returned. The default mode is the interaction mode.
WScript. Echo WScript. name' returns WScript
Object (host Executable File) Name
Wscript. Echo WScript. Path
'Return includes the path name of the executable cscript.exeor wscript.exe.
WScript. Echo WScript. ScriptName
'Return The Name Of The WSF, VBS, or JS file that is being double-clicked.
WScript. Echo WScript. Version
'Return the version number of WSCRIPT or CSCRIPT.
WScript. Echo WScript. ScriptFullName
'Return the complete path of the current running script
WScript. Echo WScript. Arguments. count
'Return the number of drag-and-drop files that the user dragged to the script
WScript. Echo WScript. Arguments (0)
'Return the complete path and name of the 1st files dragged and dropped by the user.
WScript. Sleep 3000
'Keep the program running after a period of time. Unit: haoss. Here, 1000 = 1 second.
Set objname = WScript. CreateObject ("?? ")
'Wsh creates a COM Object ,?? Is the prefix for creating object functions, such as WScript. Network
WScript. ConnectObject
Name of the Variable Connecting to the external script, "string value indicating the function prefix"
WScript. DisconnectObject
Variables that need to be disconnected from external scripts
WScript. Echo "text or variable displayed after the pop-up dialog box" [, optional second message, third message...]
Set
Myobj = GetObject (? [,?], [???])
'? = The file's fully qualified path name ,?? = Optional. The program identifier of the object ,??? = Name of the associated application to be started
WScript. Quit [?]
'Terminate the function that the program continues to run. The statement under it will not be executed ,? = Optional, indicating the return value after exit
You can also use WSH such as Shell Objects in HTML webpages. You can delete a. Shell object.
Set
WshShell = WScript. CreateObject ("WScript. Shell ")
WScript. Echo
WshShell. CurrentDirectory 'returns or changes the current Active Directory
Set sys = WshShell. Environment
'The system status is displayed. For details, refer to the WSH instance of the network programmer's companion.
Wscript. Echo WshShell. SpecialFolders ("Desktop ")
'Simple reference to WINDOW special folders. For details, see the example.
WScript. Echo
WshShell. ExpandEnvironmentStrings ("% WinDir %") 'returns the extended value of the environment variable. For details, see instance
WshShell. Run
"Calc", 0-10 'run a program. For details, see the instance
WshShell. AppActivate "Network programmer companion-Lshdic2002"
'Focus the program or file with the specified title
WshShell. SendKeys "{del }"
'Press the key (as if it was on the keyboard). For details, see the instance.
WshShell. Popup
"Pop-up dialog box body", 0-5/16/32/48/64, "pop-up dialog box title", 0-5/16/32/48/64' pop-up dialog box
WshShell. RegWrite
"HKCU \ Software \ ACME \ FortuneTeller \", 1, "REG_BINARY"
'Refer to the instance for writing the registry.
WshShell. RegDelete "HKCU \ Software \ ACME \ FortuneTeller \ MindReader"
'See the instance for deleting the registry.
Key = WshShell. RegRead ("HKCU \ Software \ ACME \ FortuneTeller \")
'Refer to the instance for reading the registry.
You can also use WSH such as Shell Objects in HTML webpages. This sentence is a comment. You can delete it.
Network object
Set
WshNetwork = WScript. CreateObject ("WScript. Network ")
WScript. Echo "your domain name is :"
& WshNetwork. UserDomain 'returns the user's domain name
WScript. Echo "your computer system name is :"&
WshNetwork. ComputerName 'returns the name of the computer system.
WScript. Echo "you are :"&
WshNetwork. UserName
'Return the computer Username
You can also use WSH such as Shell Objects in HTML webpages. This sentence is a comment. You can delete it.
Complete WSH instance
Wscript. echo
"This is a simple WSH program, and you have learned another new technology [WSH]."
Msgbox "how is it? Msgbox in VBS also works. "& vc &
Vc & "wait for 1500 milliseconds. The JS language dialog box", 32, "WSH instance" is displayed"
WScript. Sleep 1500
'Pause the program for 1500 milliseconds
Pop = WScript. CreateObject ("Wscript. Shell ")
Pop. Popup
("Congratulations! You finally understand ", 48," this is JS ")
Shortcut
Set Shell =
CreateObject ("WScript. Shell ")
Paths = Shell. SpecialFolders ("Desktop ")
'Use the function to specify a special folder. Here is [desktop].
Set link = Shell. CreateShortcut (paths &
"\ Shortcut name. lnk ")
Link. Description = "this sentence is a comment, which is a shortcut created with WSH"
Link. HotKey =
"CTRL + ALT + SHIFT + X" 'This is the shortcut key defined for the shortcut
Link. IconLocation = "pbrush.exe, 0"
'Specify the shortcut icon. Here, we barely use the icon of the plotting program.
Link. TargetPath = "http://www.lshdic.com"
'Specify the connection destination here, and barely use my previous homepage instead.
Link. WindowStyle = 3' form pop-up mode.
Link. WorkingDirectory
= Paths: Specifies the working directory of the shortcut
Msg = msgbox ("are you sure you want to create a shortcut on the desktop? ", 32 + 1," how? ")
If msg =
1 then
Link. Save to make the program take effect immediately
End
If
'Save this file as a wsf suffix.
You can also use WSH such as Shell Objects in HTML webpages. This sentence is a comment. You can delete it.
Registry operation instance
Set
WshShell = WScript. CreateObject ("WScript. Shell ")
WshShell. RegWrite
"HKEY_CURRENT_USER \ Software \ Policies \ Microsoft \ Internet
Explorer \ Control Panel \ homepage ", 1," REG_DWORD"
'Write the Registry (0 = the value to be written, REG_DWORD is in hexadecimal format 16 or 10 or REG_SZ = string
REG_BINARY = binary value integer REG_EXPAND_SZ = extensible string)
Msgbox
WshShell. RegRead
("HKEY_CURRENT_USER \ Software \ Policies \ Microsoft \ Internet
Explorer \ Control Panel \ homepage ")
'Read registry operations
'Note: if the value of homepage is set to 1, the IE homepage setting bar of internet Options of IE browser will be grayed out. Check it in IE browser. If you want to restore it, change the homepage value of the program to 0.
It can be seen that WSH is indeed a very practical technology to operate the registry! To run this file, save it as a simulated input instance of a file with the wsf suffix.
Set
WshShell = WScript. CreateObject ("WScript. Shell ")
WshShell. Run "Notepad", 1
'Run the Notepad program in WINDOWS.
Wscript. sleep 1000
'Pause for 1 second in order to load the Notepad program
WshShell. AppActivate "untitled-Notepad"
'Focus the Notepad program
WshShell. SendKeys "1234567890 hehe" 'starts simulating the button
Wscript. sleep 500
Wshshell. sendkeys "{enter} no not"
Wscript. sleep 500
Wshshell. sendkeys
"{Bs 11 }"
Wscript. sleep 600
Wshshell. sendkeys "hahahahahahaha! Bye bye my
Boby ~ 0_0 ~ "
'Save this file as a wsf suffix.
System detection instance
Set
WshShell = WScript. CreateObject ("WScript. Shell ")
Set
Sys = WshShell. Environment
For each I in sys
'Use the VBS exhaustion method until sys is empty
WScript. Echo
I
Next
'Save the file as a wsf suffix when running the file. If the file is running on the network, keep only the VBS statement.