我有一个批处理脚本,可以为Win7 / WinXP编写注册表项,因此较旧的视频游戏可以正常运行,但批处理本身并不起作用。脚本如下:
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
)
在命令提示符下运行脚本:
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
如果比我更聪明的人能够弄清楚这里发生了什么,我将非常感激。
答案 0 :(得分:2)
问题是
时分配给变量的值中的括号set QQ=C:\ProgramFiles (x86)\Steam\steamapps\common\Echelon
已执行。变化
set QQ=%OUTPUT_SEVEN%
进入
set "QQ=%OUTPUT_SEVEN%"
并对其余set
命令执行相同操作。这可以防止特殊字符出现问题,并避免在存储值的末尾包含不需要的空格。