使用卸载字符串静默卸载NVIDIA显示驱动程序

4
我可以在PowerShell中卸载NVIDIA图形驱动程序,但我无法弄清楚如何静默执行此操作。正常的代码如下:
#Get Uninstall String from Registry
$us = Get-childItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object {$_.DisplayName -like "*NVIDIA Graphics Driver*"} | select DisplayName, UninstallString

# Splitting the Uninstall String into executable and argument list
$unused, $filePath, $argList = $us.UninstallString -split '"', 3

# Any of the following command can start the process 
Start-Process -FilePath "C:\Windows\SysWOW64\RunDll32.EXE" -ArgumentList $argList -Wait
# or
Start-Process $filePath $argList -Wait

一旦进程启动,它会显示 NVIDIA 卸载程序对话框 (NVIDIA Uninstaller dialog box),以手动选择/点击“卸载”按钮继续进行。我的 UninstallString 如下:
"C:\Windows\SysWOW64\RunDll32.EXE" "C:\Program Files\NVIDIA Corporation\Installer2\InstallerCore\NVI2.DLL",UninstallPackage Display.Driver

我尝试了以下几种方式,但似乎没有任何效果。
Start-Process -FilePath "C:\Windows\SysWOW64\RunDll32.EXE" -ArgumentList "/X $argList /quiet" -Wait

Start-Process $filePath -ArgumentList $argList "/S" -Wait

请指导我如何进行静默卸载。

2
该参数似乎是“-silent”,但它可能会强制重启计算机。请参见https://forums.developer.nvidia.com/t/silent-driver-uninstallation-without-a-forced-reboot-solved/62882。 - zett42
-silent 可以与 cmd /c $un.UninstallString -silent -deviceinitiated 命令一起使用,而 -deviceinitiated 则避免了重启。但在我的情况下,我需要使用 Start-Process 命令,并且如果我像这样编写它 Start-Process $filePath -ArgumentList $argList -Wait -silent,则会返回错误。 - Ali Furqan
3
-silent 应该作为 $argList 的一部分。它不是 PowerShell Start-Process 命令的有效参数。 - Theo
1
那么 $argList += '-silent', '-deviceinitiated' 就可以了。 - zett42
$argList += ' -silent', '-deviceinitiated' 已经生效。非常感谢。 - Ali Furqan
显示剩余3条评论
1个回答

2

总结评论为答案:

#Get Uninstall String from Registry
$us = Get-childItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object {$_.DisplayName -like "*NVIDIA Graphics Driver*"} | select DisplayName, UninstallString

# Splitting the Uninstall String into executable and argument list
$unused, $filePath, $argList = $us.UninstallString -split '"', 3

# Append arguments for silent uninstall
# -deviceinitiated avoids a system restart
$argList += ' -silent -deviceinitiated'

# Any of the following command can start the process 
Start-Process -FilePath "C:\Windows\SysWOW64\RunDll32.EXE" -ArgumentList $argList -Wait

关键是将任何用于rundll32.exe的参数添加到$argList字符串中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接