找不到“语句的预期结尾在”的位置

时间:2019-02-13 16:33:41

标签: vbscript

因此,我正在VBS中创建代码以自动设置计算机。我的代码的第1步运行良好,第2步在此示例中未实现,但运行良好,第3步在Command_3A处抛出“语句的预期结尾”错误。

我要设置的字符串为start "Lightspeed" /wait /i "Programs\Lightspeed\UserAgentx64 V2.1.14.msi"

我已经尝试过这些方法,但是我缺少一些东西。

Command_3A = "start "Lightspeed" /wait /i "Programs\Lightspeed\UserAgentx64 V2.1.14.msi" "`
Command_3A = "start " ""Lightspeed"" " /wait /i " ""Programs\Lightspeed\UserAgentx64 V2.1.14.msi"" "`
Command_3A = (start "Lightspeed" /wait /i "C:\Users\ccollins\Desktop\ThumbDrive\Programs\Lightspeed\UserAgentx64 V2.1.14.msi" )`

这是我的代码:

'Dim objShell
Set objShell = WScript.CreateObject ("WScript.Shell")

Drive_Letter = "C:"
File_Path = "C:\Users\ccollins\Desktop\ThumbDrive\"

' Step 1 - Set Power Settings
Command_1A = "powercfg /change standby-timeout-ac 0"
Command_1B = "powercfg /change standby-timeout-dc 15"
Command_1C = "powercfg /change monitor-timeout-ac 0"
Command_1D = "powercfg /change monitor-timeout-dc 15"
Command_1E = "powercfg /change hibernate-timeout-ac 0"
Command_1F = "powercfg /change hibernate-timeout-dc 15"

objShell.Run "cmd /k " & Command_1A & "&" & Command_1B & "&" & Command_1C & "&" & Command_1D & "&" & Command_1E & "&" & Command_1F & "& exit"

' Step 2 - Remove Bloatware (Win10Apps)

' Step 3 - Install wanted programs
Command_3A = (start "Lightspeed" /wait /i "C:\Users\ccollins\Desktop\ThumbDrive\Programs\Lightspeed\UserAgentx64 V2.1.14.msi" )
Command_3B = "start "Acrobat" /wait "Programs\AcroRdrDC1801120058_en_US.exe" /sAll "
Command_3C = "start "AZMerit" /wait /I "Programs\AzMERITSecureBrowser10.4-2018-08-02.msi" /passive "
Command_3D = "start "Java" /wait "Programs\jre-8u201-windows-x64.exe" /s "
Command_3E = "start "Chrome" /wait "Programs\ChromeStandaloneSetup64.exe" /silent /install "
Command_3F = "start "Eset" /wait "Programs\ESet Rip and Replace.exe" "

objShell.Run "cmd /k " & Drive_Letter & "&" & Command_3A & "&" & Command_3B & "&" & Command_3C & "&" & Command_3D & "&" & Command_3E & "&" & Command_3F & "& exit"

Set oShell = Nothing'

我肯定会丢失一些东西,只需要另一双眼睛即可查看我的代码。

1 个答案:

答案 0 :(得分:-1)

这就是我想出的。我必须在要作为命令一部分插入的代码中为Chr(34)使用"。我还插入了一个用于sPath和UAC控件的输入框。

Set wshShell = WScript.CreateObject("WScript.Shell")
    dim sPath

' ----------------------------------------------------------' 
' UAC Control
    If WScript.Arguments.Length = 0 Then
      Set objShell = CreateObject("Shell.Application")
      objShell.ShellExecute "wscript.exe" _
        , Chr(34) & WScript.ScriptFullName & Chr(34) & " RunAsAdministrator", , "runas", 1
      WScript.Quit
    End If

'Step 0 - Set Drive Letter or File Path

    sPath = InputBox("Enter the Path to the Drive. If entering just drive letter then add :, if file path remove the end \")

    ' Step 1 - Set Power Settings

    ' Step 2 - Remove Bloatware (Win10Apps)

    ' Step 3 - Install wanted programs
    Function GetOsBits()
        Set shell = CreateObject("WScript.Shell")
        If shell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then
             GetOsBits = 64
        Else
            GetOsBits = 32
        End If
    End Function

    Command_3A = Chr(34) & sPath & "\Programs\Lightspeed\UserAgentx64 V2.1.14.msi" & Chr(34)
    Command_3B = Chr(34) & sPath & "\Programs\Lightspeed\UserAgentx86 V2.1.14.msi" & Chr(34)
    Command_3C = Chr(34) & sPath & "\Programs\AcroRdrDC1801120058_en_US.exe" & Chr(34) & "& /sAll "
    Command_3D = Chr(34) & sPath & "\Programs\Java\jre-8u201-windows-x64.exe" & Chr(34) & "& /s "
    Command_3E = Chr(34) & sPath & "\Programs\Java\jre-8u201-windows-i586.exe" & Chr(34) & "& /s "
    Command_3F = Chr(34) & sPath & "\Programs\Chrome\ChromeStandaloneSetup64.exe" & Chr(34) & "& /silent /install "
    Command_3G = Chr(34) & sPath & "\Programs\Chrome\ChromeStandaloneSetupi586.exe" & Chr(34) & "& /silent /install "
    Command_3H = Chr(34) & sPath & "\Programs\ESet Rip and Replace.exe" & Chr(34)

    If GetOsBits = 64 Then
            wshShell.Run(Command_3A) 'LightSpeed
        wscript.Sleep 4000 
            wshShell.Run(Command_3C) 'Adobe Reader
        wscript.Sleep 30000 
            wshShell.Run(Command_3D) 'Java
        wscript.Sleep 30000 
            wshShell.Run(Command_3F) 'Chrome
        wscript.Sleep 30000
            wshShell.Run(Command_3H) 'Eset
        wscript.Sleep 30000
    Else
            wshShell.Run(Command_3B) 'LightSpeed x86
        wscript.Sleep 4000 
            wshShell.Run(Command_3C) 'Adobe Reader
        wscript.Sleep 4000 
            wshShell.Run(Command_3E) 'Java x86
        wscript.Sleep 30000 
            wshShell.Run(Command_3G) 'Chrome x86
        wscript.Sleep 30000
            wshShell.Run(Command_3H) 'Eset
        wscript.Sleep 30000
    End If


    Set oShell = Nothing