简体   繁体   中英

NSIS failing to run driver installer batch file

UPDATE: Everyone struggling to use an NSI installer to install an INF file look no further. 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.

However, when I attempt to call this exact batch file from an NSIS installer using ExecWait it doesn't run the batch file. 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?

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

Update: If I change ".cmd" in the NSIS file to ".bat" I get cmd windows with the following errors.

在此处输入图片说明

pnputil.exe only exists in the 64-bit system32 folder .

You can disable the filesystem redirection applied to 32-bit apps:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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