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

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

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

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

比如远程状态下安装,断网时就会出现远程断连重试的现象,大概5-10秒恢复
以上过程,不想人工交互,就想自动化,如何实现?

$catPath = "C:\Users\Administrator\Desktop\netkvm.cat"
$signedFile = Get-AuthenticodeSignature -FilePath $catPath
$cert = $signedFile.SignerCertificate
$certPath = "C:\netkvm.cer"
Export-Certificate -Cert $cert -FilePath $certPath
certutil -addstore -f "TrustedPublisher" $certPath#更新netkvm驱动
#更新之前打印一下netkvm驱动版本号
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Windows\System32\drivers\netkvm.sys")
#下载devcon.exe命令
wget http://windows-1251783334.cos.ap-shanghai.myqcloud.com/115.159.148.149/devcon.exe -outfile c:\windows\devcon.exe
#下载netkvm.cat对应的证书文件
wget http://windows-1251783334.cos.ap-shanghai.myqcloud.com/115.159.148.149/netkvm.cer -outfile c:\windows\netkvm.cer
#导入证书可以用Import-Certificate也可以用certutil -addstore -f "TrustedPublisher"
#注意一定是TrustedPublisher,不是Root
Import-Certificate -FilePath C:\netkvm.cer -CertStoreLocation Cert:\LocalMachine\TrustedPublisher\ -Confirm:$false -ErrorAction SilentlyContinue
#certutil -addstore -f "TrustedPublisher" "C:\netkvm.cer"
#更新netkvm.sys
devcon.exe /r update "C:\drivers\netkvm.inf" "PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00"
#2012R2/win8.1可能需要重启机器才能完全生效
#更新完成查看netkvm驱动版本号
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Windows\System32\drivers\netkvm.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.myqcloud.com/115.159.148.149/updatenetkvm58009-2012R2willrestart.ps1
if((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").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:\Windows\System32\drivers\netkvm.sys")
$client = new-object System.Net.WebClient
$client.DownloadFile('http://windows-1251783334.cos.ap-shanghai.myqcloud.com/wget64.exe',' c:\windows\wget.exe')
wget.exe http://windows-1251783334.cos.ap-shanghai.myqcloud.com/115.159.148.149/devcon.exe -O c:\windows\devcon.exe
cmd.exe /c rd /S /Q c:\drivers 2>&1 > $null
wget.exe http://windows-1251783334.cos.ap-shanghai.myqcloud.com/115.159.148.149/netkvm_58009_mitigate_pkt_loss.zip -O c:\drivers.zip
$7zPath = "$env:ProgramFiles\7-Zip\7z.exe"
if (-not (Test-Path -Path $7zPath)) {
$client1 = new-object System.Net.WebClient
$client1.DownloadFile('http://windowsgz-1251783334.cos.ap-guangzhou.myqcloud.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:ProgramFiles\7-Zip\7z.exe" x -aoa c:\drivers.zip -oc:\drivers
$netkvminf=""
$catPath = ""
if([System.Environment]::OSVersion.Version.Major -eq 10){
$netkvminf="C:\drivers\Win10\amd64\netkvm.inf"
$catPath="C:\drivers\Win10\amd64\netkvm.cat"
}
if((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName -match "2012 R2|Windows 8.1"){
$netkvminf="C:\drivers\Win8.1\amd64\netkvm.inf"
$catPath="C:\drivers\Win8.1\amd64\netkvm.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 "PCI\VEN_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:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName -match "2012 R2|Windows 8.1"){
$netkvminf;devcon.exe /r remove "PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";devcon.exe /r install $netkvminf "PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";devcon.exe /r update $netkvminf "PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00";
restart-computer -force
}
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Windows\System32\drivers\netkvm.sys")
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。