简体   繁体   English

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

[英]NSIS failing to run driver installer batch file

UPDATE: Everyone struggling to use an NSI installer to install an INF file look no further.更新:每个人都在努力使用 NSI 安装程序来安装 INF 文件,别再看了。 This actually works.这实际上有效。

I have made a batch file that successfully installs a device driver in administrator mode.我制作了一个批处理文件,可以在管理员模式下成功安装设备驱动程序。 If I copy this into C:\\Users\\Me\\AppData\\Local\\Temp\\Driver along with the driver it can successfully execute and install the driver.如果我将其与驱动程序一起复制到 C:\\Users\\Me\\AppData\\Local\\Temp\\Driver 中,它可以成功执行并安装驱动程序。

However, when I attempt to call this exact batch file from an NSIS installer using ExecWait it doesn't run the batch file.但是,当我尝试使用 ExecWait 从 NSIS 安装程序调用这个确切的批处理文件时,它不会运行批处理文件。 The files are coped into the exact location as mentioned above.文件被处理到上面提到的确切位置。

How on earth do you successfully call a batch file from a NSIS file?你到底是如何从 NSIS 文件中成功调用批处理文件的?

Relevant snippet from 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安装.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"

Update: If I change ".cmd" in the NSIS file to ".bat" I get cmd windows with the following errors.更新:如果我将 NSIS 文件中的“.cmd”更改为“.bat”,我会得到带有以下错误的 cmd 窗口。

在此处输入图片说明

pnputil.exe only exists in the 64-bit system32 folder . pnputil.exe 仅存在于64 位 system32 文件夹中

You can disable the filesystem redirection applied to 32-bit apps:您可以禁用应用于 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM