如果用pnputil -i -a *.inf命令会弹窗信任签名,如何隐藏这个弹窗让自动完成驱动安装?

2023-11-03 07:56:30 浏览数 (1)

用dism命令在系统运行时集成驱动会报:此命令只能与脱机映像一起使用。如果用pnputil -i -a netkvm.inf命令会弹窗信任签名,如何隐藏这个弹窗让自动完成驱动安装?

代码语言:javascript复制
pnputil -i -a viostor.inf
pnputil -i -a netkvm.inf

执行安装的时候弹这个交互窗口

第一次

如果选了左边按钮,就会安装成功,会显示尝试1、成功1

如果选了右边按钮就不会安装,会看到尝试1、成功0

如果安装过至少一次了,是不会弹窗的,会有如下显示

如果没安装过,第一次会弹窗,并且每次安装过程中都会断网几秒钟(一般10秒内恢复)

比如远程状态下安装,断网时就会出现远程断连重试的现象,大概5-10秒恢复

以上过程,不想人工交互,就想自动化,如何实现?

代码语言:javascript复制
$catPath = "C:UsersAdministratorDesktopnetkvm.cat"
$signedFile = Get-AuthenticodeSignature -FilePath $catPath
$cert = $signedFile.SignerCertificate
$certPath = "C:netkvm.cer"
Export-Certificate -Cert $cert -FilePath $certPath
certutil -addstore -f "TrustedPublisher" $certPath
代码语言:javascript复制
#更新netkvm驱动

#更新之前打印一下netkvm驱动版本号
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:WindowsSystem32driversnetkvm.sys")

#下载devcon.exe命令
wget http://windows-1251783334.cos.ap-shanghai.myzijiebao.com/115.159.148.149/devcon.exe -outfile c:windowsdevcon.exe

#下载netkvm.cat对应的证书文件
wget http://windows-1251783334.cos.ap-shanghai.myzijiebao.com/115.159.148.149/netkvm.cer -outfile c:windowsnetkvm.cer

#导入证书可以用Import-Certificate也可以用certutil -addstore -f "TrustedPublisher"
#注意一定是TrustedPublisher,不是Root
Import-Certificate -FilePath C:netkvm.cer -CertStoreLocation Cert:LocalMachineTrustedPublisher -Confirm:$false -ErrorAction SilentlyContinue
#certutil -addstore -f "TrustedPublisher" "C:netkvm.cer"

#更新netkvm.sys
devcon.exe /r update "C:driversnetkvm.inf" "PCIVEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00"
#2012R2/win8.1可能需要重启机器才能完全生效

#更新完成查看netkvm驱动版本号
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:WindowsSystem32driversnetkvm.sys")

这里贴一个完整的脚本,比较挫,需要机器能访问公网,并且需要注意的是:应用这个脚本,if 2012r2 or win8.1, os will restart;if 2016/2019/2022/win10/win11, os will not restart

http://windows-1251783334.cos.ap-shanghai.myzijiebao.com/115.159.148.149/updatenetkvm58009-2012R2willrestart.ps1

代码语言:javascript复制
if((Get-ItemProperty "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion").ProductName -match "2008 R2|Windows 7"){
echo "only support >= Server2012 R2 or >= Windows8.1"
exit
}

cmd.exe /c rd /S /Q c:drivers 2>&1 > $null
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:WindowsSystem32driversnetkvm.sys")

$client = new-object System.Net.WebClient
$client.DownloadFile('http://windows-1251783334.cos.ap-shanghai.myzijiebao.com/wget64.exe',' c:windowswget.exe')
wget.exe http://windows-1251783334.cos.ap-shanghai.myzijiebao.com/115.159.148.149/devcon.exe -O c:windowsdevcon.exe

cmd.exe /c rd /S /Q c:drivers 2>&1 > $null
wget.exe http://windows-1251783334.cos.ap-shanghai.myzijiebao.com/115.159.148.149/netkvm_58009_mitigate_pkt_loss.zip -O c:drivers.zip

$7zPath = "$env:ProgramFiles7-Zip7z.exe"
if (-not (Test-Path -Path $7zPath)) {
$client1 = new-object System.Net.WebClient
$client1.DownloadFile('http://windowsgz-1251783334.cos.ap-guangzhou.myzijiebao.com/ziyan/7z2200-x64.msi','c:7z2200-x64.msi')

msiexec.exe /i c:7z2200-x64.msi /qn
Start-Sleep 30
del c:7z2200-x64.msi 2>$null
}

& "$env:ProgramFiles7-Zip7z.exe" x -aoa c:drivers.zip -oc:drivers

$netkvminf=""
$catPath = ""

if([System.Environment]::OSVersion.Version.Major -eq 10){
$netkvminf="C:driversWin10amd64netkvm.inf"
$catPath="C:driversWin10amd64netkvm.cat"
}
if((Get-ItemProperty "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion").ProductName -match "2012 R2|Windows 8.1"){
$netkvminf="C:driversWin8.1amd64netkvm.inf"
$catPath="C:driversWin8.1amd64netkvm.cat"
}

$signedFile = Get-AuthenticodeSignature -FilePath $catPath
$cert = $signedFile.SignerCertificate
$certPath = "C:netkvm.cer"
Export-Certificate -Cert $cert -FilePath $certPath
certutil -addstore -f "TrustedPublisher" $certPath


if([System.Environment]::OSVersion.Version.Major -eq 10){
$netkvminf;devcon.exe /r update $netkvminf "PCIVEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";
}
#if 2012r2 or win8.1, os will restart; if 2016/2019/2022/win10/win11, os will not restart
if((Get-ItemProperty "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion").ProductName -match "2012 R2|Windows 8.1"){
$netkvminf;devcon.exe /r remove "PCIVEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";devcon.exe /r install $netkvminf "PCIVEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";devcon.exe /r update $netkvminf "PCIVEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";
restart-computer -force
}
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:WindowsSystem32driversnetkvm.sys")

0 人点赞