Reputation: 1
I have a batch script that writes registry keys for Win7/WinXP so an older video game can run properly, but the batch itself isn't working. The script is as follows:
echo on
setlocal ENABLEEXTENSIONS
set KEY_NAME=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080
set VALUE_NAME=InstallLocation
for /F "usebackq tokens=3*" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do (
set OUTPUT_SEVEN=%%A%%B
)
setlocal ENABLEEXTENSIONS
set KEY_NAME=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080
set VALUE_NAME=InstallLocation
for /F "usebackq tokens=3*" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do (
set OUTPUT_XP=%%A%%B
)
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080"
if %ERRORLEVEL% EQU 0 goto Win7
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080"
if %ERRORLEVEL% EQU 1 goto WinXP
:Win7
(
echo Running Windows 7 Script
REG ADD "HKLM\SOFTWARE\Wow6432Node\Madia\Echelon" /V Path1 /T reg_sz /D "%OUTPUT_SEVEN%\\Data\\" /F
REG ADD "HKLM\SOFTWARE\Wow6432Node\Madia\Echelon" /V Path2 /T reg_sz /D "%OUTPUT_SEVEN%\\Data\\" /F
REG ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Echelon" /V InstallLocation /T reg_sz /D "%OUTPUT_SEVEN%\\" /F
REG ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Echelon" /V InstallSource /T reg_sz /D "%OUTPUT_SEVEN%\\" /F
set QQ=%OUTPUT_SEVEN%
goto exit
)
:WinXP
(
echo Running Windows XP Script
REG ADD "HKLM\SOFTWARE\Madia\Echelon" /V Path1 /T reg_sz /D %OUTPUT_XP%\\Data\\" /F
REG ADD "HKLM\SOFTWARE\Madia\Echelon" /V Path2 /T reg_sz /D %OUTPUT_XP%\\Data\\" /F
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Echelon" /V InstallLocation /T reg_sz /D %OUTPUT_XP%\\" /F
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Echelon" /V InstallSource /T reg_sz /D %OUTPUT_XP%\\" /F
set QQ=%OUTPUT_XP%
goto exit
)
:exit
(
start /d"%QQ%" /wait Game.exe
)
Running the script in the command prompt:
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>gamelauncher.bat
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>echo on
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>setlocal ENABLEEXTENSIONS
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>set KEY_NAME=HKLM\SOFTWARE
\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>set VALUE_NAME=InstallLoca
tion
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>for /F "usebackq tokens=3*
" %A IN (`reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\
Uninstall\Steam App 311080" /v "InstallLocation" 2>nul | find "InstallLocation"`
) do (set OUTPUT_SEVEN=%A%B )
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>(set OUTPUT_SEVEN=C:\Progr
amFiles (x86)\Steam\steamapps\common\Echelon )
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>setlocal ENABLEEXTENSIONS
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>set KEY_NAME=HKLM\SOFTWARE
\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>set VALUE_NAME=InstallLoca
tion
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>for /F "usebackq tokens=3*
" %A IN (`reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\St
eam App 311080" /v "InstallLocation" 2>nul | find "InstallLocation"`) do (set OU
TPUT_XP=%A%B )
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>reg query "HKLM\SOFTWARE\W
ow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 311080"
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninsta
ll\Steam App 311080
DisplayIcon REG_SZ C:\Program Files (x86)\Steam\steam\games\1b116bbca7
813266288d61df77b3baca0297aaab.ico
DisplayName REG_SZ Echelon
HelpLink REG_SZ http://support.steampowered.com/
InstallLocation REG_SZ C:\Program Files (x86)\Steam\steamapps\common\E
chelon
Publisher REG_SZ MADia Entertainment
UninstallString REG_SZ "C:\Program Files (x86)\Steam\steam.exe" steam:
//uninstall/311080
URLInfoAbout REG_SZ http://www.madia.ru/echelon.html
NoRepair REG_DWORD 0x1
NoModify REG_DWORD 0x1
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>if 0 EQU 0 goto Win7
\Steam\steamapps\common\Echelon was unexpected at this time.
c:\Program Files (x86)\Steam\SteamApps\common\Echelon>set QQ=C:\ProgramFiles (x8
6)\Steam\steamapps\common\Echelon
If someone smarter than me could figure out what happened here, I'd be very grateful.
Upvotes: 0
Views: 258
Reputation: 70923
The problem are the parenthesis in the value you are assigning to the variable when
set QQ=C:\ProgramFiles (x86)\Steam\steamapps\common\Echelon
is executed. Change
set QQ=%OUTPUT_SEVEN%
into
set "QQ=%OUTPUT_SEVEN%"
and do the same for the rest of set
commands. This prevents problems with special characters and avoid the inclusion of unneeded spaces at the end of the stored value.
Upvotes: 2