NSIS无法运行驱动程序安装程序批处理文件

时间:2017-02-08 05:10:47

标签: windows batch-file installer driver nsis

更新:每个人都在努力使用NSI安装程序来安装INF文件。这实际上有效。

我制作了一个批处理文件,可以在管理员模式下成功安装设备驱动程序。如果我将其复制到C:\ Users \ Me \ AppData \ Local \ Temp \ Driver以及驱动程序,它可以成功执行并安装驱动程序。

但是,当我尝试使用ExecWait从NSIS安装程序调用此完全批处理文件时,它不会运行批处理文件。如上所述,文件将处理到完全位置。

您如何成功地从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"

更新: 如果我改变了#34; .cmd"在NSIS文件中" .bat"我得到cmd窗口有以下错误。

enter image description here

1 个答案:

答案 0 :(得分:1)

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 $0
${EnableX64FSRedirection}
DetailPrint $0
SectionEnd