Fix IT Scripts
1 like 0 dislike
52 views

Ever needed to remotely uninstall programs? The following will do just that:
 

asked in Windows OS by (3.1k points)
recategorized by | 52 views

1 Answer

1 like 0 dislike

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products /s > "%TEMP%\reguninstall.txt"
TYPE "%TEMP%\reguninstall.txt" | grep.exe -B 15 -E "Driver & Utility" | grep.exe -o -E "UninstallString.+" | grep.exe -o -E "MsiExec.+" > "%temp%\uninstallcmd.txt"
FOR /F "tokens=1-10 delims={" %%A IN ('TYPE "%temp%\uninstallcmd.txt"') DO msiexec.exe /x {%%B /qb

You'll need to install grep.exe on your computer. I can't remember which one, but it was the native one. 

This script does 3 things.

#1, it pulls every program option from the registry and saves it in a file
#2, it then greps for the program name (in this example, "Driver & Utility". This needs to be specific. Using grep we can ask it to pull lines previous to finding the query. We pull back 15 lines because it's a big key and we need to find the GUID
#3, we make a variable out of the GUID and execute the uninstall command.

The final uninstall command should look like this:

msiexec.exe /x {48435D4A-BDAF-4AC3-B172-B25F1AADE6C6} /qb

This script was setup to be run as a GPO script on shutdown. But you could run it via PSEXEC as well.

answered by (3.1k points)

Related questions

1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
asked Aug 11, 2017 in Windows OS by doughall (3.1k points) | 134 views
0 like 0 dislike
1 answer
asked Aug 11, 2017 in Windows OS by doughall (3.1k points) | 49 views
0 like 0 dislike
1 answer
asked Aug 11, 2017 in Windows OS by doughall (3.1k points) | 75 views
30 questions
24 answers
17 comments
627 users