Add a domain user or lease to a local group
Set objGroup = GetObject ("WinNT: //./Administrators ")
Set objUser = GetObject ("WinNT: // testnet/Engineers ")
ObjGroup. Add (objUser. ADsPath)
Modify the local administrator password
Set objcnlar = GetObject ("WinNT: //./administrator, user ")
Objcnla. SetPassword "P @ ssW0rd"
Objcnla. SetInfo
The YES or NO dialog box is displayed, and different codes are executed for different options.
IntAnswer = Msgbox ("Do you want to delete these files? ", VbYesNo,
"Delete Files ")
If intAnswer = vbYes Then
Msgbox "You answered yes ."
Else Msgbox "You answered no ."
End If
Run the CMD command line
Set obshell = wscript. createobject ("wscript. shell ")
Obshell. run ("ipconfig"), true
If the command to be run contains double quotation marks, use & chr (34) & instead
Ignore code errors and continue execution
On Error Resume Next
Placed at the beginning of the Code. When the Code fails to run, it does not stop jumping out, but continues to execute the next one. Appropriate applications will be very effective.
Modify/read/delete/create a registry
Set wso = CreateObject ("WScript. Shell") 'Declaration
Wso. RegWrite "% Path %" 'create a subkey
Wso. RegWrite "% Path %", "% Value %" 'modify "default" key Value
Wso. RegWrite "% Path %", % Value %, % RegType % 'modify the key Value of a specific type
'(The string value REG_SZ can expand the string value REG_EXPAND_SZ DWORD Value REG_DWORD binary value REG_BINARY)
Set WSHShell = Wscript. CreateObject ("Wscript. Shell ")
WSHShell. RegRead (% Path %) 'reads the registry subkey or key value (generally used to determine whether an event is executed)
Set wso = CreateObject ("WScript. Shell ")
Wso. RegDelete "% Path %" 'Delete the subkey or key value
'(Root Key abbreviation HKEY_CLASSES_ROOT HKCR HKEY_CURRENT_USER HKCU HKEY_LOCAL_MACHINE HKLM, others none)
Program code
Set wso = CreateObject ("Wscript. Shell ")
Wso. RegWrite "HKLMSOFTWAREMicrosftWindows NT #1"
Wso. RegWrite "HKLMSOFTWAREMicrosftWindows NT #1", "0"
Wso. RegWrite "HKLMSOFTWAREMicrosftWindows NT #1 #2", 0, REG_BINARY
Wso. RegDelete "HKLMSOFTWAREMicrosftWindows NT #1"
Wscript. quit
Copy/delete/create/Write a file
Set fso = Wscript. CreateObject ("Scripting. FileSystemObject") 'Declaration
Set f = fso. CreateTextFile ("% PATH %") 'to create a file, where f can be arbitrary, including the thumbnail name
F. WriteLine ("VBS") 'writes the file content. This command is too simple. Currently, it can only be used for TXT files.
F. Close
Set c = fso. getfile ("% path %") 'copy an object
C. copy ("% PATH2 %") 'copy the file to the specified location
Fso. deletefile ("% PATH %") 'deletes an object
Wscript. quit
Program code
Set fso = Wscript. CreateObject ("Scripting. FileSystemObject ")
Set f = fso. CreateTextFile ("C: Sample.txt ")
WriteLine ("VBS ")
F. close
Set e = fso. getfile (C: Sample.txt)
E. copy ("D: Sample.txt ")
Fso. deletefile (C: Sample.txt)
Wscript. quit
Output simple explain commands to applications
Dim program1 'declare the variable program1
Program1 = "% Path %" 'Application Path
Set wshshell = createobject ("wscript. shell") 'declares the drinking Function
Set oexec=wshell.exe c (program1) 'run the program
Wscript. sleep 2000 '(this command is unknown. It is estimated that the delay is set. Please advise)
Wshshell. appactivate "% WindowsName %" 'activate the application window
Wshshell. sendkeys "+ {% KeyBoardName %}" 'add +
Wshshell. sendkeys "555555" 'in the program input column, enter the use of this series of commands, you must first determine that the program can perform the keyboard operation of the ghost, which is the most suitable for QQ login, as shown in the following example.
Program code
Dim program1
Program1 = "D: Program FilesTencentcoralQQ.exe"
Set wshshell = CreateObject ("wscript. shell ")
Set oexec=wshell.exe c (program1)
Wscript. sleep 2000
Wshshell. appactivate "QQ login"
Wshshell. sendkeys "+ {TAB }"
Wsh shell. sendkeys "250481892"
Wscript. sleep 2000
Wshshell. sendkeys "{TAB }"
Wshshell. sendkeys "****************"
Wscript. sleep 2000
Wshshell. sendkeys "{ENTER }"
Wscript. quit
Folder operations
Set fso = Wscript. CreateObject ("Scripting. FileSystemObject") 'Declaration
Set f = fso. CreateFolder ("% PATH %") create a folder
Set e = getFolder (% PATH %) is similar to "binding target"
E. copy ("% PATH2 %") copy the folder
Fso. deletefolder (% PATH %) delete a folder
Program code
Set fso = Wscript. CreateObject ("Scripting. FileSystemObject ")
Set f = fso. CreateObject ("C: sample ")
F. copy ("D: sample ")
Fso. deletefolder ("C: sample ")
'(From the above example, we can see that many folder operations are the same as file operations, so the VBS file has a lot of command Uniformity)
Converts all read-only files in a specified folder into readable files.
Const ReadOnly = 1' set the value of the read-only attribute to 1
Set FSO = CreateObject ("Scripting. FileSystemObject") 'Declaration
Set Folder = FSO. GetFolder ("% PATH %") 'bind a Folder
Set colFiles = Folder. Files all Files in the Folder
For Each objFile in colFiles the following statement applies to all files in the folder
If File. Attributes AND ReadOnly Then 'is the key. Here the If judgment statement is applied to check whether the File attribute is read-only.
File. Attributes = File. Attributes XOR ReadOnly
'True (default value: True) 'executes the XOR logic operation and changes it to readable.
End If 'End judgment
Next
Save a Word file as a text file
Const wdFormatText = 2' set constant value
(When this value is 8, it is saved as an HTML document, and when it is 11, it is saved as an XML document)
Set objWord = CreateObject ("Word. Application") 'declares to call a function
Set objDoc = objWord. Documents. Open ("% Path %") 'Open a DOC file
ObjDoc. SaveAs "% PATH2 %", save wdFormatText ......
ObjWord. Quit
Program code
Const wdFormatText = 2
Set objWord = CreateObject ("Word. Application ")
Set objDoc = objWord. Documents. Open ("d: doc1.doc ")
ObjDoc. SaveAs "g: doc1.txt", wdFormatText
ObjWord. Quit