簡體   English   中英

NSIS 無法運行驅動程序安裝程序批處理文件

[英]NSIS failing to run driver installer batch file

更新:每個人都在努力使用 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

安裝.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

運行文件

@echo off

powershell -Command "Start-Process 'install.bat' -ArgumentList  '%~dp0\c500.inf' -Verb runAs"

更新:如果我將 NSIS 文件中的“.cmd”更改為“.bat”,我會得到帶有以下錯誤的 cmd 窗口。

在此處輸入圖片說明

pnputil.exe 僅存在於64 位 system32 文件夾中

您可以禁用應用於 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