Favorite classic VBS code

Source: Internet
Author: User

File Operations

Copy codeThe Code is as follows: Set fso = Wscript. CreateObject ("Scripting. FileSystemObject") 'creates a file system object to process drives, folders, and files.
Set WshShell = Wscript. CreateObject ("Wscript. Shell") 'creates a system Shell object to run programs.
If fso. fileexists ("D: \ sword Online \ alreadyexist.txt") then', if the file "D: \ sword Online \ alreadyexist.txt" is found
WshShell. Run ("D: \ sword Online \ sword online.exe") 'Run "D: \ sword Online \ sword online.exe"
Elseif fso. fileexists ("\ gengxin \ update \ dj.exe") then' otherwise, if "\ gengxin \ update \ dj.exe" is found
WshShell. Run ("\ gengxin \ update \ dj.exe") 'Run "\ gengxin \ update \ dj.exe"
Else
WshShell. Run ("D: \ sword Online \ sword online.exe") 'or Run "D: \ sword Online \ sword online.exe"
End if 'ends when the statement is executed according to the condition

Import VBS to the Registry, and then execute the fileCopy codeThe Code is as follows: dim Wsh Set Wsh = WScript. CreateObject ("WScript. Shell ")
Wsh. RegWrite "HKCU \ SOFTWARE \ AUDITION \ AUTOSTART", 0, "REG_DWORD"
Wsh. RegWrite "HKCU \ SOFTWARE \ AUDITION \ PATH", "G: \ online games \ AUDITION 1.5", "REG_SZ"
Wsh. RegWrite "HKCU \ SOFTWARE \ AUDITION \ VERSION", 1010, "REG_DWORD" Wsh. run "patcher.exe"

PING the VBS that shuts down when the intranet connection fails.Copy codeThe Code is as follows: strIP = "192.168.0.254" ': The PING Intranet Machine
Set objShell = CreateObject ("WScript. Shell ")
If Not IsOnline (strIP) Then objShell. run "shutdown-s-t 30-c" & chr (34) & "The Machine is about to close" & chr (34)
End If
Function IsOnline (strComputer) IsOnline = false strCommand = "% comspec %/c ping-n 2-w 500" & strComputer & "" Set objExecObject = objShell. exec (strCommand) Do While Not objExecObject. stdOut. atEndOfStream strText = objExecObject. stdOut. readAll () If Instr (strText, "Reply")> 0 Then IsOnline = true End If Loop End Function

Boot script VBS for ARP BondingCopy codeThe Code is as follows: Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
WshShell. run "arp-s 192.168.0.1 30-18-e5-33-01", 0
WshShell. run "arp-s 192.168.0.5 30-18-e5-33-07", 0

Run the programCopy codeThe Code is as follows: Dim
Set Wsh = WScript. CreateObject ("WScript. Shell ")
A. Run "d: \ online game \ westward journey II \ xy-2.exe"

Run oshell. run "d: \ soft \ hf \ hfgame3 \ GameClient. lnk"

Disconnect a networkCopy codeThe Code is as follows: strNICName = "disable = net pci \*"
Set objShell = CreateObject ("Wscript. Shell ")
StrCommand = "devcon.exe" & strNICName
ObjShell. Run strCommand, 0, False

Start network connectionCopy codeThe Code is as follows: strNICName = "enable = net pci \*"
Set objShell = CreateObject ("Wscript. Shell ")
StrCommand = "devcon.exe" & strNICName
ObjShell. Run strCommand, 0, False

VBS script for deleting filesCopy codeThe Code is as follows: dim fso Set fso = CreateObject ("Scripting. FileSystemObject ")
Fso. CopyFile "\ server \ share \ XXX. lnk", "c: \ target location 1 \", true' add
Fso. CopyFile "\ server \ share \ XXX. lnk", "c: \ target location 2 \", true' add
Fso. DeleteFile "c: \ target location 1 \ XXX. lnk", true' Delete fso. DeleteFile "c: \ target location 2 \ XXX. lnk", true' Delete
Set FSO = NoThing WScript. quit

Automatically detects and installs the iscsi client without any interface, and maps and disconnects the vbs script.

Run the following code to automatically detect and install the iscsi client without a UI and perform automatic ing:Copy codeThe Code is as follows: On Error Resume Next setupfile = "iscsi2.0.exe" 'iscsi Client installation file path
Serverip = "192.168.0.100" 'iscsi Server ip Address
Set oshell = CreateObject ("WScript. Shell ")
Set fso = CreateObject ("Scripting. FileSystemObject ")
If not fso. fileexists (oshell. ExpandEnvironmentStrings ("% WinDir %") + "\ system32 \ iscsicpl. cpl ")
Then oshell. run setupfile & "/q", 1
End if
Oshell. run "iscsicli AddTargetPortal" & serverip & "3260 ",
Oshell. run "iscsicli LoginTarget iqn.2005-02.com. ricecake. iscsi: 00 T *************** 0 ",

The following code deletes an iscsi ing DiskCopy codeThe Code is as follows: filetmp = "c: \ my.txt"
On Error Resume Next
Set Shell = CreateObject ("WScript. Shell ")
Set fso = Wscript. CreateObject ("Scripting. FileSystemObject ")
Shell. run "cmd/c iscsicli sessionlist>" & filetmp, 0, 1
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set theFile = fso. OpenTextFile (filetmp, ForReading)
Aaa = thefile. readall
Thefile. close
Function myreadline ()
X = instr (1, aaa, vbcrlf, vbTextCompare)
Myline = mid (aaa, 1, x-1)
Aaa = right (aaa, len (aaa)-x)
If len (aaa) = <1 then myline = "end"
Myreadline = myline
End function
Do While bbb <> "end"
Bbb = myreadline
If bbb <> "end" then
If bbb <> "" then
If instr (bbb, "Session") <> 0 then
TemID = mid (bbb, instr (bbb, ":") + 1, len (bbb)-instr (bbb ,":"))
Shell. run "iscsicli logouttarget" & temID, 0
End if
End if
End if
Loop
Fso. deletefile (filetmp)

Force deletion of QQ user files cannot be performed. skip this step:Copy codeThe Code is as follows: Dim fso, folderspec, f, f1, fc
Folderspec = "f: \ Program Files \ Tencent \ QQ" 'set your QQ folder
Dim Re
Set Re = New RegExp
Re. Pattern = "^ \ d {4, 13} $"
Set fso = CreateObject ("scripting. FileSystemObject ")
Set f = fso. GetFolder (folderspec)
Set fc = f. SubFolders
For Each f1 in fc If Re. Test (f1.name) Then
On Error Resume Next
F1.Delete (true)
On Error GoTo 0
End If
Next

Run the batch processing program once every 5 minutes.Copy codeThe Code is as follows: Dim Wsh
Set Wsh = WScript. CreateObject ("WScript. Shell ")
Do Wsh. Run "d: \ aaa. bat" 'the batch processing you want to execute
WScript. Sleep (300000)
Loop

To enable automatic running upon startup, disable the program

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.