Batch script to determine 32 or 64 bit Windows Operating Systems and perform an action

I think that’s the longest title I’ve ever made! Anyway, if you’re like me and need to work on different Windows Operating Systems and would like to distinguish between architecture types when executing batch scripts, then you’ve come to the right place.

Check out the below script and use it to make your life easier:

@echo off
::Written by Samontech

SET Version=Unknown

wmic os get osarchitecture | FINDSTR /IL “32” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”32″

wmic os get osarchitecture | FINDSTR /IL “64” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”64″

ECHO The OS architecture of Windows found is %VERSION% bit

IF %VERSION% == “32” GOTO OLD
IF %VERSION% == “64” GOTO NEW
::If no versions are found go to UNKNOWN
GOTO UNKNOWN

:OLD
ECHO Execute script for 32 bit OS
***Insert awesome script work here!
GOTO FINISH

:NEW
ECHO Execute script for 64 bit OS
***Insert awesome script work here!
GOTO FINISH

:FINISH
ECHO Script executed successfully
GOTO END

:UNKNOWN
ECHO OS Architecture Unknown

:END

It’s very similar to my batch script which deletes temporary files on all Windows Operating systems, but, use your imagination and put it to use e.g. upgrading Adobe Reader, Adding Registry keys, the list goes on!

Cleanup Windows & Java Temporary Files using a Batch Script

Recently, there was a breakout of malware tricking people to install a fake “anti-virus” software, which in turn infected their machines. Mind you, the primary reason machines get infected in the first place is because people are browsing dodgy websites so BE CAREFUL or get PROTECTED!

The infected files are usually downloaded to a temporary internet files folder or java temporary folder and are executed/installed from there. It’s always good practice to clear out these temporary files to prevent malicious activity as well as save you some disk space. This batch script can be used as a scheduled task or deployed through your favourite monitoring tool to “cleanup” these temporary files.

This script should work on all Windows platforms so happy cleaning 🙂

Delete All Temporary Files

Note: copy and paste the below code into notepad and save as the text file as a .bat file. Change the “Save as type” to All Files and make sure you add a .bat to the end of the name e.g. Cleanup.batThere is a tutorial post located here.

@echo off
::Written by Samontech
::Determine which version of Windows is installed
::Set Variable Version to unknown

SET Version=Unknown

VER | FINDSTR /IL “5.0” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows 2000″

VER | FINDSTR /IL “5.1.” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows XP”

VER | FINDSTR /IL “5.2.” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows 2003″

VER | FINDSTR /IL “6.0.” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows Vista”

VER | FINDSTR /IL “6.1.” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows 7″

VER | FINDSTR /IL “6.2.” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows 8″

VER | FINDSTR /IL “6.3.” > NUL
IF %ERRORLEVEL% EQU 0 SET Version=”Windows 8.1″

ECHO The version of Windows found is %VERSION%

IF %VERSION% == “Windows XP” GOTO XP
IF %VERSION% == “Windows 2000” GOTO XP
IF %VERSION% == “Windows 2003” GOTO XP
IF %VERSION% == “Windows Vista” GOTO WIN7
IF %VERSION% == “Windows 7” GOTO WIN7
IF %VERSION% == “Windows 8” GOTO WIN7
IF %VERSION% == “Windows 8.1” GOTO WIN7

::If no versions are found go to UNKNOWN
GOTO UNKNOWN

:WIN7
ECHO WIN7 script to execute
cd /D C:\users
ECHO Clean Temp Folder
for /D %%a in (*.*) do DEL /F /S /Q “%%a\AppData\Local\Temp\*.*”
for /D %%a in (*.*) do FOR /D %%b IN (“%%a\AppData\Local\Temp\*.*”) DO RMDIR /S /Q “%%b”
ECHO Clean IE Cache
for /D %%a in (*.*) do DEL /F /S /Q “%%a\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*”
for /D %%a in (*.*) do FOR /D %%b IN (“%%a\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*”) DO RMDIR /S /Q “%%b”
ECHO Clean JAVA Cache
for /D %%a in (*.*) do DEL /F /S /Q “%%a\AppData\LocalLow\Sun\Java\Deployment\cache\*.*”
for /D %%a in (*.*) do FOR /D %%b IN (“%%a\AppData\LocalLow\Sun\Java\Deployment\cache\*.*”) DO RMDIR /S /Q “%%b”

GOTO FINISH

:XP
ECHO XP script to execute
cd /D “C:\Documents and Settings”
ECHO Clean Temp Folder
for /D %%a in (*.*) do DEL /F /S /Q “%%a\Local Settings\Temp\*.*”
for /D %%a in (*.*) do FOR /D %%b IN (“%%a\Local Settings\Temp\*.*”) DO RMDIR /S /Q “%%b”
ECHO Clean IE Cache
for /D %%a in (*.*) do DEL /F /S /Q “%%a\Local Settings\Temporary Internet Files\*.*”
for /D %%a in (*.*) do FOR /D %%b IN (“%%a\Local Settings\Temporary Internet Files\*.*”) DO RMDIR /S /Q “%%b”
ECHO Clean JAVA Cache
for /D %%a in (*.*) do DEL /F /S /Q “%%a\Application Data\Sun\Java\Deployment\cache\*.*”
for /D %%a in (*.*) do FOR /D %%b IN (“%%a\Application Data\Sun\Java\Deployment\cache\*.*”) DO RMDIR /S /Q “%%b”

GOTO FINISH

:FINISH
ECHO Temporary files successfully deleted
GOTO END

:UNKNOWN
ECHO Operating System Unknown

:END

 

Edit: Added Windows 8 paramater 🙂 special thanks to wampbox for that!