Batch + VBS错误预期语句的结尾

时间:2018-09-29 00:10:40

标签: batch-file vbscript syntax-error

我制作了一个批处理文件,该文件应创建vbscript,该脚本创建由choice命令描绘的某个文件的快捷方式。唯一的问题是我不断收到预期的语句结束错误。我假设这是一个语法错误。 (对不起,因为我是Vb的新手,所以我不能很好地解释它)这是代码

@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

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

尝试像这样调用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>