4

I can uninstall NVIDIA Graphics Driver from PowerShell but I am unable to figure out how to do it silently. The normal code looks like this:

#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

Once the process is started it displays the NVIDIA Uninstaller dialog box for manual selection/click of the UNINSTALL button to proceed further. My UninstallString looks like:

"C:\Windows\SysWOW64\RunDll32.EXE" "C:\Program Files\NVIDIA Corporation\Installer2\InstallerCore\NVI2.DLL",UninstallPackage Display.Driver

I have tried following ways but nothing seems to work.

Start-Process -FilePath "C:\Windows\SysWOW64\RunDll32.EXE" -ArgumentList "/X $argList /quiet" -Wait

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

Please guide me, how to do silent uninstallation.

Ali Furqan
  • 45
  • 5
  • 2
    The parameter appears to be `-silent`, but it might force a reboot of the machine. See https://forums.developer.nvidia.com/t/silent-driver-uninstallation-without-a-forced-reboot-solved/62882 – zett42 Aug 19 '22 at 12:14
  • `-silent` works with `cmd /c $un.UninstallString -silent -deviceinitiated` command and `-deviceinitiated` avoids the restart. But in my case I need to do it with `Start-Process` command and `-silent` throws back an error if I write it like `Start-Process $filePath -ArgumentList $argList -Wait -silent`. – Ali Furqan Aug 19 '22 at 12:22
  • 3
    `-silent` should be part of the $argList. It is not a valid parameter for the PowerShell `Start-Process` cmdlet – Theo Aug 19 '22 at 12:25
  • 1
    `$argList += '-silent', '-deviceinitiated'` should do it then. – zett42 Aug 19 '22 at 12:33
  • `$argList += ' -silent', '-deviceinitiated'` has worked. Thank you very much. – Ali Furqan Aug 19 '22 at 12:55
  • @zett42 - Propose this as an Answer rather than just comments. – Jeff Zeitlin Aug 19 '22 at 13:05
  • @AliFurqan In my answer I've just added the arguments as a single string, because `$argList` actually is a single string (I was mislead to think it were an array), so it makes more sense to append a string instead of an array. – zett42 Aug 19 '22 at 13:19
  • You probably can't uninstall the driver if it's in use. – js2010 Aug 19 '22 at 13:46

1 Answers1

2

To summarize the comments into an answer:

#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

The key is to add any arguments intended for rundll32.exe to the $argList string.

zett42
  • 25,437
  • 3
  • 35
  • 72