【问题标题】:Batch+VBS error End of expected statement批处理+VBS错误预期语句结束
【发布时间】:2019-03-04 23:02:38
【问题描述】:

我已经制作了一个批处理文件,它应该创建 vbscript,它会创建由选择命令描述的某个文件的快捷方式。唯一的问题是我不断收到预期的语句结束错误。我假设这是一个语法错误。 (对不起,我没有解释清楚,因为我是 Vbs 新手)这里是代码

@echo off
Title Dragonball Z
cls
echo Please Type The Number Corosponding To Your Chosen Title
more "%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Titles.txt"
%SystemRoot%\System32\choice.exe /C 12345 /N /M ":"
if errorlevel 5 goto tlog2
if errorlevel 4 goto tlog
if errorlevel 3 goto t
if errorlevel 2 goto ssw
if errorlevel 1 goto bf

:bf
set DIR=""%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA""
set game="Buus Fury"
goto END

:ssw
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\SUPERSONIC WARRIORS\DragonBall Z Supersonic Warriors.gba"
set game="Supersonic Warriors"
goto END

:t
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Taiketsu\Dragonball Z Taiketsu.GBA"
set game="Taiketsu"
goto END

:tlog
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\THE LEGACY OF GOKU\Dragonball Z the Legacy of Goku.GBA"
set game="The Legacy of Goku"
goto END

:tlog2
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\THE LEGACY OF GOKU 2\Dragonball Z the Legacy of Goku 2.GBA"
set game="The Legacy of Goku 2"
goto END

:END
set SCRIPT="%USERPROFILE%\Documents\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%USERPROFILE%\Desktop\%game%.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = %DIR% >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
rem Here I keep getting a Expected End Of statement error
pause

任何帮助将不胜感激

【问题讨论】:

  • 这是del %SCRIPT%。不要使用%RANDOM%
  • 这行得通吗?
  • 为变量分配引号的错误做法。只需在需要使用时引用变量即可。
  • 这是一个糟糕的模式来使用像批处理文件中的 vbscript。最好检查一下-> stackoverflow.com/questions/9074476/…

标签: batch-file vbscript syntax-error


【解决方案1】:

尝试像这样调用 vbscript:

@echo off
Title Dragonball Z
cls
echo Please Type The Number Corosponding To Your Chosen Title
more "%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Titles.txt"
%SystemRoot%\System32\choice.exe /C 12345 /N /M ":"
if errorlevel 5 goto tlog2
if errorlevel 4 goto tlog
if errorlevel 3 goto t
if errorlevel 2 goto ssw
if errorlevel 1 goto bf

:bf
set DIR=""%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA""
set game="Buus Fury"
goto END

:ssw
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\SUPERSONIC WARRIORS\DragonBall Z Supersonic Warriors.gba"
set game="Supersonic Warriors"
goto END

:t
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Taiketsu\Dragonball Z Taiketsu.GBA"
set game="Taiketsu"
goto END

:tlog
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\THE LEGACY OF GOKU\Dragonball Z the Legacy of Goku.GBA"
set game="The Legacy of Goku"
goto END

:tlog2
set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\THE LEGACY OF GOKU 2\Dragonball Z the Legacy of Goku 2.GBA"
set game="The Legacy of Goku 2"
goto END

:END
cscript //nologo "%~f0?.wsf" //job:VBS
pause
exit /b %errorlevel%



<package> <job id="VBS"> <script language="VBScript">

  Set wshShell = CreateObject( "WScript.Shell" )
  userProfile = wshShell.ExpandEnvironmentStrings( "%USERPROFILE%" )
  game = wshShell.ExpandEnvironmentStrings( "%game%" )
  dir1 = wshShell.ExpandEnvironmentStrings( "%dir%" )
  Set oWS = WScript.CreateObject("WScript.Shell")
  sLinkFile = userProfile & "\Desktop\" & game & ".lnk"
  Set oLink = oWS.CreateShortcut(sLinkFile)
  oLink.TargetPath = dir1
  oLink.Save

</script> </job> </package>

【讨论】:

    【解决方案2】:

    Powershell 有很大的用处,试试这个:

    @ECHO OFF
    Title Dragonball Z
    cls
    echo Please Type The Number Corosponding To Your Chosen Title
    more "%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Titles.txt"
    %SystemRoot%\System32\choice.exe /C 12345 /N /M ":"
    if errorlevel 5 goto tlog2
    if errorlevel 4 goto tlog
    if errorlevel 3 goto t
    if errorlevel 2 goto ssw
    if errorlevel 1 goto bf
    
    :bf
    set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA"
    set game="Buus Fury"
    goto END
    
    :ssw
    set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\SUPERSONIC WARRIORS\DragonBall Z Supersonic Warriors.gba"
    set game="Supersonic Warriors"
    goto END
    
    :t
    set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Taiketsu\Dragonball Z Taiketsu.GBA"
    set game="Taiketsu"
    goto END
    
    :tlog
    set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\THE LEGACY OF GOKU\Dragonball Z the Legacy of Goku.GBA"
    set game="The Legacy of Goku"
    goto END
    
    :tlog2
    set DIR="%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\THE LEGACY OF GOKU 2\Dragonball Z the Legacy of Goku 2.GBA"
    set game="The Legacy of Goku 2"
    goto END
    
    :END
    powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('"%~dp0%game%.LNK"');$s.TargetPath='"%DIR%"';$s.Save()"
    
    pause
    goto :EOF
    

    【讨论】:

    • 不幸的是,这不起作用我得到了这个-在 line:1 char:177 + ... etPath='"C:\Users\Salina\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dr ... + ~ 表达式或语句中出现意外标记“S”。+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
    • @ImaGonnaDie 是的,只需将 $s.TargetPath='"%DIR%"' 更改为 $s.TargetPath='%DIR%' 因为您的 for 语句已经引用了路径。
    • 也刚刚注意到set DIR=""%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA"" 是双引号。尽量不要引用和做set "DIR=%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA"
    • 感谢大家的帮助,但我已经完成了项目,我已经将每个平台/系列分解为单独的批处理文件,但主/控制器 bat 文件代码在这里pastebin.com/KQdKNv7R
    猜你喜欢
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多