Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common scripts in VBS

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "what are the commonly used scripts in VBS". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Set

Domain users or rents are added to the 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

Pop-up YES or NO dialog box, different choices to execute different code

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 command

Set obshell=wscript.createobject (wscript.shell)

Obshell.run (ipconfig), true

If the command you want to run contains double quotes, use & chr (34) & instead of

Ignore code errors and continue execution

On Error Resume Next

Place it at the beginning of the code, and when the code goes wrong, it doesn't stop jumping out, but moves on to the next one. Proper application will be very effective.

Modify, read, delete, create registry

Set wso = CreateObject (WScript.Shell) 'declaration

Wso.RegWrite Path%' create subkey

Wso.RegWrite Path%,%Value%' modifies default key value

Wso.RegWrite Path%,%Value%,%RegType% 'modifies a specific type of key value

'(string value REG_SZ Extensible string value REG_EXPAND_SZ DWORD value REG_DWORD binary value REG_BINARY)

Set WSHShell= Wscript.CreateObject (Wscript.Shell)

WSHShell.RegRead (% Path%) 'reads registry subkeys or key values (usually used to determine whether an event is executed)

Set wso = CreateObject (WScript.Shell)

Wso.RegDelete Path% 'delete subkey or key value

'(root key abbreviation HKEY_CLASSES_ROOT HKCR HKEY_CURRENT_USER HKCU HKEY_LOCAL_MACHINE HKLM, other none)

Reference content

Eg:

Set wso = CreateObject (Wscript.Shell)

Wso.RegWrite HKLM\ SOFTWARE\ Microsft\ Windows NT\ # 1

Wso.RegWrite HKLM\ SOFTWARE\ Microsft\ Windows NT\ # 1 Magol 0

Wso.RegWrite HKLM\ SOFTWARE\ Microsft\ Windows NT\ # 1\ # 2.

Wso.RegDelete HKLM\ SOFTWARE\ Microsft\ Windows NT\ # 1

Wscript.quit

Copy, delete, create, and simply write files

Set fso = Wscript.CreateObject (Scripting.FileSystemObject) 'declaration

Set f = fso.CreateTextFile (% PATH%) 'create the file, where f is arbitrary and contains the acronym

F.WriteLine (VBS) 'writes the contents of the file. The function of this command is so simple that it can only be used for TXT files.

F.Close

Set c=fso.getfile (% path%) 'copy a file

C.copy (% PATH2%) 'copy the file to the specified location

Fso.deletefile (% PATH%) 'delete file

Wscript.quit

Reference content

Eg.

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 a simple series of instructions to the application

Dim program1 'declares the variable program1

Program1= Path% 'application path

Set wshshell=createobject (wscript.shell) 'declares drinking function

Set oexec=wshshell.exec (program1) 'run the program

Wscript.sleep 2000'(the function of this command is unknown. It is estimated that it is to set the delay, please give me some advice)

Wshshell.appactivate WindowsName% 'activates the application window

Wshshell.sendkeys + {% KeyBoardName%} 'add + before outputting keyboard keystrokes for the first time

Wshshell.sendkeys 555555 'input in the program input field to use this series of commands must first make sure that the program can perform a series of keyboard operations, which is most suitable for QQ login, such as the following example.

Reference content

Eg.

Dim program1

Program1=D:\ Program Files\ Tencent\ coralQQ.exe

Set wshshell=CreateObject (wscript.shell)

Set oexec=wshshell.exec (program1)

Wscript.sleep 2000

Wshshell.appactivate QQ login

Wshshell.sendkeys + {TAB}

Wshshell.sendkeys 250481892

Wscript.sleep 2000

Wshshell.sendkeys {TAB}

Wshshell.sendkeys *

Wscript.sleep 2000

Wshshell.sendkeys {ENTER}

Wscript.quit

Simple operation of folder

Set fso = Wscript.CreateObject (Scripting.FileSystemObject) 'declaration

Set f = fso.CreateFolder (% PATH%) create folder

Set e = getFolder (% PATH%) is similar to bind target

E.copy (% PATH2%) copy folder

Fso.deletefolder (% PATH%) delete folder

Reference content

Eg.

Set fso = Wscript.CreateObject (Scripting.FileSystemObject)

Set f = fso.CreateObject (C:\ sample)

F.copy (D:\ sample)

Fso.deletefolder (C:\ sample)

'(as you can see from the above example, many folder operations are common to file operations, so VBS files have the unity of many commands.)

Converts all read-only files in a specified folder to readable files

Const ReadOnly = 1 'set the corresponding value of the read-only attribute to 1

Set FSO = CreateObject (Scripting.FileSystemObject) 'declaration

Set Folder = FSO.GetFolder (% PATH%) 'bind folder

Set colFiles = Folder.Files' folder all files

For Each objFile in colFiles' the following statements apply to all files in the folder

If File.Attributes AND ReadOnly Then 'this is the key point, where the If judgment statement is applied to detect whether the file attribute is read-only.

File.Attributes = File.Attributes XOR ReadOnly 'performs the XOR logic operation on the judgment result of Ture (default is True), and makes it readable

End If 'end judgment

Next

Save the Word file as a text file

Const wdFormatText = 2 'set constant value

(save as HTML document when the value is 8 and as XML document at 11:00)

Set objWord = CreateObject (Word.Application) 'declares calling function

Set objDoc = objWord.Documents.Open (% Path%) 'Open a DOC file

ObjDoc.SaveAs% PATH2%, wdFormatText is saved as...

ObjWord.Quit

Reference content

Eg:

Const wdFormatText = 2

Set objWord = CreateObject (Word.Application)

Set objDoc = objWord.Documents.Open (d:\ doc1.doc)

ObjDoc.SaveAs g:\ doc1.txt, wdFormatText

ObjWord.Quit

This is the end of the content of "what are the commonly used scripts for VBS"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report