UWP Helper批处理脚本报错:字符串缺少终止符',请求修复
修复UWP Helper批处理脚本的PowerShell终止符错误
问题原因
错误根源是批处理调用PowerShell时使用了单引号'。在批处理环境中,单引号不具备字符串边界的作用,当脚本所在路径包含空格或特殊字符时,批处理会拆分带单引号的参数,导致PowerShell收到不完整的字符串,触发The string is missing the terminator: '错误。
修复后的完整脚本
@echo off color 2 echo UWP Helper & echo. :begin echo 1. Install game echo 2. Install DLC echo 3. Enable Developer Mode echo 4. Disable Developer Mode echo 5. Exit set /p action="Choose action: " IF NOT "%action%" == "1" ( IF NOT "%action%" == "2" ( IF NOT "%action%" == "3" ( IF NOT "%action%" == "4" ( IF NOT "%action%" == "5" ( goto begin ) ) ) ) ) IF "%action%" == "1" ( goto gameinstall ) IF "%action%" == "2" ( goto dlcinstall ) IF "%action%" == "3" ( goto developeron ) IF "%action%" == "4" ( goto developeroff ) IF "%action%" == "5" ( goto exit ) :developeron reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" goto begin :developeroff reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "0" goto begin :gameinstall set file_check="%~dp0AppxSignature.p7x" set file_check_new="AppxSignature.tmp" IF EXIST %file_check% ( REN %file_check% %file_check_new% ) powershell -Command "Add-AppxPackage ""%~dp0AppxManifest.xml"" -Register" goto begin :dlcinstall set dlc_directory="%~dp0MicrosoftStore_DLC\\" set dlc_pattern=AppxManifest.xml set sign_pattern=*.p7x set file_check_new="AppxSignature.tmp" IF EXIST %dlc_directory% ( cd %dlc_directory% ) IF EXIST %dlc_directory% ( FOR /R %%I in (%sign_pattern%) DO IF EXIST "%%I" ( REN "%%I" %file_check_new% ) ) ELSE ( echo DLC directory does not exist. ) IF EXIST %dlc_directory% ( FOR /R %%I in (%dlc_pattern%) DO IF EXIST "%%I" ( powershell -Command "Add-AppxPackage ""%%I"" -Register" ) ) ELSE ( echo DLC directory does not exist. ) IF EXIST %dlc_directory% ( cd .. ) goto begin :exit
关键修复点
- 将调用PowerShell的语句从
powershell Add-AppxPackage '路径' -Register改为powershell -Command "Add-AppxPackage ""路径"" -Register" - 用双引号包裹PowerShell命令,内部路径的双引号用
""转义,确保批处理正确传递完整路径给PowerShell,避免参数拆分问题
内容的提问来源于stack exchange,提问作者Yep
相关产品推荐
相关产品推荐

