1

I have made a batch file that should create vbscript that creates a shortcut of a certain file depicted by the choice command. The only problem is I keep getting a expected end of statement error. I'm assuming it's a Syntax error. (sorry I don't explain it well as I am new to Vbs) here is the code

@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

any help will be appreciated

IsaacWP121
  • 111
  • 1
  • 10

2 Answers2

0

Powershell has great uses, Try this:

@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
John Kens
  • 1,615
  • 2
  • 10
  • 28
  • unfortunately that didn't work I got this-At line:1 char:177 + ... etPath='"C:\Users\Salina\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dr ... + ~ Unexpected token 'S' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken – IsaacWP121 Sep 29 '18 at 02:51
  • @ImaGonnaDie Yeah just change `$s.TargetPath='"%DIR%"'` to `$s.TargetPath='%DIR%'` As your for statements already quote the path. – John Kens Sep 29 '18 at 04:55
  • Also just noticed `set DIR=""%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA""` is double quoted. Try not quoting and doing `set "DIR=%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\BUU'S FURY\Dragonball Z Buu's Fury.GBA"` instead – John Kens Sep 29 '18 at 04:57
  • thanks guys for all your help but I have finished the project already and I have broken each Platform/series into individual batch files but the master/controller bat file code is here https://pastebin.com/KQdKNv7R – IsaacWP121 Oct 02 '18 at 05:54
0

try calling the vbscript like this:

@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>
npocmaka
  • 55,367
  • 18
  • 148
  • 187