Wsh Script Host wscript main object

Source: Internet
Author: User
Wsh Script Host Main wscript object

Wscript. Echo wscript. buildversion 'wsh Script Host generation version number
Wscript. Echo wscript. fullname 'returns the path where the wscript or cscript Script Host is located.
Wscript. Echo wscript. Interactive ': return the Script Mode. Only the interactive mode and batch mode are returned. The default mode is interactive mode.
Wscript. Echo wscript. name' returns the name of the wscript object (executable file of the host ).
Wscript. Echo wscript. Path 'the returned package contains the executable cscript.exeor wscript.exe path name.
Wscript. Echo wscript. scriptname 'returns the name of the WSF, vbs, or JS file that is being double-clicked.
Wscript. Echo wscript. version' returns the version number of wscript or cscript.
Wscript. Echo wscript. scriptfullname 'returns the complete path of the currently 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) 'returns the complete path and name of the 1st files dragged and dropped by the user.
Wscript. Sleep 3000 'Enabled Program Continue execution after a period of time. Unit: Hao second. 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"
Variables in which wscript. disconnectobject is connected to external scripts that need to be disconnected
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

example, you can also use wsh objects such as Shell Objects in HTML webpages. This sentence is a comment. You can delete it. shell object
set wshshell = wscript. createobject ("wscript. shell ")
wscript. echo wshshell. currentdirectory 'returns or changes the current active directory
set sys = wshshell. environment: displays the system status. For details, refer to the wsh instance of the network programmer companion.
wscript. echo wshshell. specialfolders ("desktop") 'is a simple reference to window special folders. For details, see the instance
wscript. echo wshshell. expandenvironmentstrings ("% WINDIR %") 'returns the extended value of the environment variable. For details, see the instance
wshshell. run "calc", 0-10 'to run a program. For details, see the instance
wshshell. appactivate "Network programmer companion-lshdic2002" 'enables the program or file with the specified title to gain focus
wshshell. sendkeys "{del}" '(as if it was a 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" 'to write the registry, see the instance
wshshell. regdelete "hkcu \ Software \ Acme \ fortuneteller \ mindreader" 'to delete the registry, see the instance
key = wshshell. regread ("hkcu \ Software \ Acme \ fortuneteller \") 'to read the registry, see the instance

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 'return the user's domain name
Wscript. Echo "your computer system name is:" & wshnetwork. computername 'return the computer system name
Wscript. Echo "you are:" & wshnetwork. Username 'return the computer user name

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 &" wait for 1500 milliseconds. The JS language version dialog box is displayed. ", 32," wsh instance"
Wscript. Sleep 1500 'causes the program to pause 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 shortcuts
Link. iconlocation = "pbrush.exe, 0" 'specifies the shortcut icon. Here, the icons of the drawing program are barely used.
Link. targetpath = "http://www.lshdic.com" 'specifies the connection destination here and barely replaces it with my previous Homepage
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 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 the Registry

'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, then, change the homepage value of this program to 0 to run. 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 that comes with windows.
Wscript. Sleep 1000 'pause for 1 second in order to load the Notepad program
Wshshell. appactivate "untitled-Notepad" 'enables the Notepad program to focus
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 'uses the vbs exhaustion method until sys is empty
Wscript. Echo I
Next

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.