Archive for October, 2009

Windows 32 (x86) or 64 (AMD64) detection in batch files

While there are a lot of ways to detect for a 64 bit version of . you can test for %programFiles(x86)%, but handling the output and writing the IF comparisons is messy.

In , you can easily check for architecture by using the “processor_architecture” variable. x86 versions of windows will have this set to “x86″, and x64 versions “x64″. Heres an easy example:

@echo off
IF %processor_architecture% ==  echo This is a 64-bit version of windows
IF %processor_architecture% == x86 echo this is a 32-bit version of windows.
pause

Uninstall ALL Versions of WinZip Batch Script

I have been struggling with this for quite a while, and ran into a lot of issues with all of the different versions on our network. There are people with 100 line .vbs to do this, and I think this is much simpler:

@echo off
REM
REM
REM    Detects winzip and silently uninstalls
REM    There is a un-stoppable pop-up window. so this will kill
REM    all instances of  IE after the UN-installation.
REM
REM
REM
 /F /IM wzqkpick.exe
 product where "name like '%%winzip%%'" call Uninstall
REM
REM This section is for WinZip <12
REM
If Exist "%programfiles(x86)%\Winzip\winzip32.exe" GOTO 64
If Exist "%programfiles%\Winzip\winzip32.exe" "%programfiles%\WinZip\Winzip32.exe" /Uninstallx
taskkill /F /IM iexplore.exe
GOTO :END
:64
"%programfiles(x86)%\WinZip\Winzip32.exe" /Uninstallx
taskkill /F /IM iexplore.exe
:END

For getting rid of WinZip 12, the magic happens in the 'wmic' line. It searches all of the installed product's names for "winzip" and will uninstall anything it finds. This only works for products that use MSI's. If you ran this outside of a file, you will have to use a single % percentage sign instead of the %% double percentage sign... scripting sucks, and that's just the way it is. Same thing that happens in "FOR" loops.

I never knew anything about the control (wmic) until now, but I will be sure to exploit it's features.