Reputation: 147
I wanted to create shortcut on desktop with icon using batch file like this:
set SCRIPT="%TEMP%\theiboosts1.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%USERPROFILE%\Desktop\Internetovy Booster.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "c:\Booster\booster.bat" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
"%windir%\system32\timeout.exe" /t 5
start wscript.exe "%SCRIPT%"
"%windir%\system32\timeout.exe" /t 10
echo Const DESKTOP = &H10&>>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
echo Set objShell = CreateObject("Shell.Application") >>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
echo Set objFolder = objShell.NameSpace(DESKTOP) >>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
echo Set objFolderItem = objFolder.ParseName("Internetovy Booster.lnk") >>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
echo Set objShortcut = objFolderItem.GetLink >>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
echo objShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll",-16752 >>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
echo objShortcut.Save >>"%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
start wscript.exe "%TEMP%\testboost.vbs"
"%windir%\system32\timeout.exe" /t 5
But it wrote an Error:
Syntex of the command is incorrect
but there is no command between
"%windir%\system32\timeout.exe" /t 10
and
echo Const DESKTOP = &H10&>>"%TEMP%\testboost.vbs"
When i create .vbs file it is working correctly
Const DESKTOP = &H10&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(DESKTOP)
Set objFolderItem = objFolder.ParseName("Internetovy Booster.lnk")
Set objShortcut = objFolderItem.GetLink
objShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll",-16752
objShortcut.Save
Can someone help me?
Upvotes: 2
Views: 5096
Reputation: 6558
The ampersand (&
) is a special character in batch files/the Windows command shell. It signifies that a the current command has ended and a new command is starting.
echo Const DESKTOP = &H10&>>"%TEMP%\testboost.vbs"
Is actually interpreted by the script as:
echo Const DESKTOP =
H10
>>"%TEMP%\testboost.vbs"
Which is incorrect as you just want to print a &
char. The "syntax incorrect" error is actually in regards to the script trying to execute H10
as a command (which doesn't exist).
To print a &
char in a string, you just need to escape it using the batch escape char - a carat ^
.
echo Const DESKTOP = ^&H10^&>>"%TEMP%\testboost.vbs"
Upvotes: 1