Friday, November 27, 2009

Uninstall Software From Remote Workstations

To have the ability to uninstall a package/program on a remote computer can be very useful for Systems Administrators and Helpdesk. Following is how you can accomplish it. You can write a batch file that can uninstall a certain software from multiple computers. 

It will require three things.

  1. MsiZap.exe
  2. PSTools – psexec.exe
  3. GUID of the software you need to uninstall

1. –> Microsoft has a tool called MsiZap.exe, for details check the following link

http://msdn.microsoft.com/en-us/library/aa370523%28VS.85%29.aspx

To acquire this tool download Windows Installer Cleanup and open it with 7zip. MsiZap has two versions MsiZapA.exe (for use in Windows 95, Windows 98 and Windows ME), and MsiZapU.exe (for use in Windows NT, Windows 2000, Windows XP, and Windows Server 2003). Extract the one you need and rename it to MsiZap.exe.

2. –> I use PSTools regularly, you can download it and extract it in “%windir%\System32” so it can be used in command prompt anywhere.

3. –> Okay now we have all the tools we need, but we still need the GUID. To find that you can create a batch file with the following command

for /f "tokens=7 delims=\" %%a in ('reg query hklm\software\microsoft\windows\currentversion\uninstall ^| FIND "{"') do for /f "tokens=2,*" %%c in ('reg query hklm\software\microsoft\windows\currentversion\uninstall\%%a ^| find /i "DisplayName"') do echo %%d,%%a>>c:\GUIDProgsList.txt

--> Now run this batch file using psexec on a remote computer

psexce –cds \\computername “path\batchfile.bat”

you will have GUID for all installed software appended to a file called GUIDProgsList.txt on the C drive of the remote computer.  You can also get this list by going to the following registry manually.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

Uninstalling a program remotely

If you have followed the above steps correctly then all you need is to run the following command.

psexec.exe -cd \\computername "path\MsiZap.exe" TW {GUID for the Program to be removed}

Following is an example of removing 7zip from a computer name nyclient01.

psexec.exe -cd \\nyclient01 "path\MsiZap.exe" TW {23170F69-40C1-2701-0457-000001000000}

________________

Word of caution: – MsiZap is powerful commandline tool, use carefully. Always test first.

No comments:

Post a Comment

Leave a comment if you find this post useful or if you have any questions