NSIS 无法 运行 驱动程序安装程序批处理文件
NSIS failing to run driver installer batch file
更新:努力使用 NSI 安装程序安装 INF 文件的每个人都不要再看了。这确实有效。
我制作了一个批处理文件,可以在管理员模式下成功安装设备驱动程序。如果我将其与驱动程序一起复制到 C:\Users\Me\AppData\Local\Temp\Driver 中,它可以成功执行并安装驱动程序。
但是,当我尝试使用 ExecWait 从 NSIS 安装程序调用此 精确 批处理文件时,它不是 运行 批处理文件。如上所述,文件被复制到 exact 位置。
你究竟是如何从 NSIS 文件中成功调用批处理文件的?
来自 NSIS 的相关片段:
# Installer sections
Section -Main SEC0000
# Copy viewer software to PC
SetOverwrite on
#(software stuff) ...
# Copy USB slave driver to PC
SetOutPath $TEMP\Driver
File ..\Driver\c500.cat
File ..\Driver\c500.inf
File ..\Driver\runme.bat
File ..\Driver\install.bat
# Remove the Windows 7/8/10 magic relocated ini file (if it exists)
Delete /REBOOTOK "$LOCALAPPDATA\VirtualStore\Program Files (x86)\CompanyName\C500-510\C500_510.ini"
WriteRegStr HKLM "${REGKEY}\Components" Main 1
SectionEnd
# Install C500 USB slave driver
Section -InstallDriver SEC0001
SetOverwrite on
DetailPrint "Install C500 USB slave driver"
# Install USB slave driver if desired
${If} ${Cmd} `MessageBox MB_YESNO|MB_ICONQUESTION "Install C500 USB slave driver?" IDYES`
ExecWait "$TEMP\Driver\runme.cmd"
${EndIf}
WriteRegStr HKLM "${REGKEY}\Components" InstallDriver 1
SectionEnd
install.bat
set fn=%~dp0c500.inf
echo fn is %fn%
::cd %windir% && %windir%\system32\pnputil.exe -i -a %~dp0\c500.inf
cd %windir%
echo %cd%
pnputil -i -a %fn%
if %errorlevel% == 0 goto success
echo Device installation failed.
echo Try to run install.bat as Administrator
echo Or check if your system has the usbser.sys file
goto end
:success
echo Device installation completed.
:end
pause
runme.bat
@echo off
powershell -Command "Start-Process 'install.bat' -ArgumentList '%~dp0\c500.inf' -Verb runAs"
更新:
如果我将 NSIS 文件中的“.cmd”更改为“.bat”,我会得到带有以下错误的 cmd windows。
pnputil.exe只存在于64-bit system32 folder。
您可以禁用应用于 32 位应用程序的文件系统重定向:
RequestExecutionLevel Admin
!include x64.nsh
Section
${DisableX64FSRedirection}
nsExec::ExecToLog '"$WINDIR\system32\PnPutil.exe" -i -a "$TEMP\Driver\c500.inf"'
Pop [=10=]
${EnableX64FSRedirection}
DetailPrint [=10=]
SectionEnd
更新:努力使用 NSI 安装程序安装 INF 文件的每个人都不要再看了。这确实有效。
我制作了一个批处理文件,可以在管理员模式下成功安装设备驱动程序。如果我将其与驱动程序一起复制到 C:\Users\Me\AppData\Local\Temp\Driver 中,它可以成功执行并安装驱动程序。
但是,当我尝试使用 ExecWait 从 NSIS 安装程序调用此 精确 批处理文件时,它不是 运行 批处理文件。如上所述,文件被复制到 exact 位置。
你究竟是如何从 NSIS 文件中成功调用批处理文件的?
来自 NSIS 的相关片段:
# Installer sections
Section -Main SEC0000
# Copy viewer software to PC
SetOverwrite on
#(software stuff) ...
# Copy USB slave driver to PC
SetOutPath $TEMP\Driver
File ..\Driver\c500.cat
File ..\Driver\c500.inf
File ..\Driver\runme.bat
File ..\Driver\install.bat
# Remove the Windows 7/8/10 magic relocated ini file (if it exists)
Delete /REBOOTOK "$LOCALAPPDATA\VirtualStore\Program Files (x86)\CompanyName\C500-510\C500_510.ini"
WriteRegStr HKLM "${REGKEY}\Components" Main 1
SectionEnd
# Install C500 USB slave driver
Section -InstallDriver SEC0001
SetOverwrite on
DetailPrint "Install C500 USB slave driver"
# Install USB slave driver if desired
${If} ${Cmd} `MessageBox MB_YESNO|MB_ICONQUESTION "Install C500 USB slave driver?" IDYES`
ExecWait "$TEMP\Driver\runme.cmd"
${EndIf}
WriteRegStr HKLM "${REGKEY}\Components" InstallDriver 1
SectionEnd
install.bat
set fn=%~dp0c500.inf
echo fn is %fn%
::cd %windir% && %windir%\system32\pnputil.exe -i -a %~dp0\c500.inf
cd %windir%
echo %cd%
pnputil -i -a %fn%
if %errorlevel% == 0 goto success
echo Device installation failed.
echo Try to run install.bat as Administrator
echo Or check if your system has the usbser.sys file
goto end
:success
echo Device installation completed.
:end
pause
runme.bat
@echo off
powershell -Command "Start-Process 'install.bat' -ArgumentList '%~dp0\c500.inf' -Verb runAs"
更新: 如果我将 NSIS 文件中的“.cmd”更改为“.bat”,我会得到带有以下错误的 cmd windows。
pnputil.exe只存在于64-bit system32 folder。
您可以禁用应用于 32 位应用程序的文件系统重定向:
RequestExecutionLevel Admin
!include x64.nsh
Section
${DisableX64FSRedirection}
nsExec::ExecToLog '"$WINDIR\system32\PnPutil.exe" -i -a "$TEMP\Driver\c500.inf"'
Pop [=10=]
${EnableX64FSRedirection}
DetailPrint [=10=]
SectionEnd