Most Important and Useful Windows Scripts Used By Professionals

Hi All, Welcome to Professional Mondays week #2. After my First post about 10 Important Must Have Security Group Policies For Windows Systems, I have received many concerns about the term Scripts and its uses. I came to know many are unaware of the scripts usage and power. We at corporate companies tend to perform same activities periodically across many computers in a network and its difficult to run the application or task individually on all the PC’s. So we write certain scripts to automate the process or Application installations and force them to run through group Policies as discussed in my earlier post at start-up or login times.A script is nothing but a list of commands that are executed by a respective programs or scripting mechanisms.

Scripts can be used to automate processes on a PC or to generate Web pages on the Web. For example, DOS scripts and VB Scripts are used to run processes on Windows Operating Systems, and Apple Script scripts can automate tasks on Macintosh computers.ASP, JSP, and PHP scripts are used to design and generate Web Pages. In this post I am going to give you some sample scripts prepared using simple DOS commands and VB for advanced users that automate few tasks in windows with less user intervention. Please note that you need to have a very good grip over DOS commands to understand few commands that I used in scripts. You can copy the below commands to a notepad and save the file with the relevant name and save the file name as example.bat (batch Script) Example.cmd (command Script).

SHUTDOWN/RESTART WINDOWS :

For a shortcut to RESTART Windows XP:
SHUTDOWN -r -t 01

For a shortcut to SHUT DOWN Windows XP:
SHUTDOWN -s -t 01

Cleanup Temporary Files and Temporary Internet Files for better performance (With Menu) :

ECHO OFF
CLS
:MENU
ECHO.
ECHO ………………………………………..
ECHO PRESS 1 or 2 or 3 or 4 or 5 or 6 to select your task, or 7 to EXIT.
ECHO ………………………………………..
ECHO.
ECHO 1 – DELETE COOKIES
ECHO 2 – DELETE RECENT DOCUMENTS LIST
ECHO 3 – DELETE MY TEMP
ECHO 4 – DELETE MY TEMP INTERNET FILES
ECHO 5 – DELETE SYSTEM TEMP
ECHO 6 – DELETE RECYCLE BIN
ECHO 7 – EXIT
ECHO.
SET /P M=Type 1, 2, 3, 4, 5, 6 or 7 then press ENTER:
IF %M%==1 GOTO DELETE COOKIES
IF %M%==2 GOTO RECENT DOCUMENTS LIST
IF %M%==3 GOTO MY TEMP
IF %M%==4 GOTO MY TEMP INTERNET FILES
IF %M%==5 GOTO SYSTEM TEMP
IF %M%==6 GOTO RECYCLE BIN
IF %M%==7 GOTO EXIT
: DELETE COOKIES (no space between : and D)
del /F /S /Q C:\docume~1\%USERNAME%\cookies\*.*
GOTO MENU
:RECENT DOCUMENTS LIST
del /F /S /Q C:\docume~1\%USERNAME%\recent\*.*
GOTO MENU
:MY TEMP
del /F /S /Q C:\docume~1\%USERNAME%\locals~1\temp\*.*
GOTO MENU
:MY TEMP INTERNET FILES
del /F /S /Q C:\docume~1\%USERNAME%\locals~1\tempor~1\*.*
GOTO MENU
:SYSTEM TEMP
del /F /S /Q %SystemRoot%\temp\*.*
GOTO MENU
:RECYCLE BIN
REM del /F /S /Q C:\recycler\*.*
GOTO MENU

Please note to change the Path with your own path for your profile if you are using windows 7.
This one is optimized for windows xp. If any doubts, you can always ping me.

Cleanup Temporary Files and Temporary Internet Files for better performance (Without Menu).

rem @ECHO OFF
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=Recent
echo About to delete files from Internet Explorer “Temporary Internet files”
FOR /D %%X IN (“%SRC1%\*”) DO FOR /D %%Y IN (“%%X\%SRC2%\*.*”) DO RMDIR /S /Q “%%Y”
echo About to delete files from Internet Explorer “History”
FOR /D %%X IN (“%SRC1%\*”) DO FOR /D %%Y IN (“%%X\%SRC3%\*.*”) DO RMDIR /S /Q “%%Y”
FOR /D %%X IN (“%SRC1%\*”) DO FOR %%Y IN (“%%X\%SRC3%\*.*”) DO DEL /F /S /Q “%%Y”
echo About to delete files from “Local settings\temp”
FOR /D %%X IN (“%SRC1%\*”) DO FOR /D %%Y IN (“%%X\%SRC4%\*.*”) DO RMDIR /S /Q “%%Y”
FOR /D %%X IN (“%SRC1%\*”) DO FOR %%Y IN (“%%X\%SRC4%\*.*”) DO DEL /F /S /Q “%%Y”
echo About to delete files from “Recent” i.e. what appears in Start/Documents/My Documents
FOR /D %%X IN (“%SRC1%\*”) DO FOR %%Y IN (“%%X\%SRC5%\*.lnk”) DO DEL /F /S /Q “%%Y”
echo About to delete files from “Windows\Temp”
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S “”

This can be placed in the “login” tab according to my previous post  for cleaning the junk in the disk soon after you login to your PC. Please note to change the Path with your own path for your profile if you are using windows 7. This one is optimized for windows xp.

Install MSI Packages without your much involvement :

You all download stuff from internet, I too do it periodically…at office we download Microsoft updates to be installed in the systems. while installing it becomes a pain for us to keep on clicking on next>next>Finish button at each systems which are time consuming.
So to avid them..Just follow the below commands in the same format.

Example:
Internet Explorer setup9.exe –z –m
Or
Internet Explorer setup9.msi –z –m

Above commands are applicable only if you are going to install a update or setup file similar to IE5,6,7,8,9 setups. This wont popup any window but just installs them in the background.

Script to display OS version details (VBScript):

Paste the code in notepad and save the file as Version.vbs

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colOSes = objWMIService.ExecQuery(“Select * from Win32_OperatingSystem”)
For Each objOS in colOSes
Wscript.Echo “Computer Name: ” & objOS.CSName
Wscript.Echo “Caption: ” & objOS.Caption ‘Name
Wscript.Echo “Version: ” & objOS.Version ‘Version & build
Wscript.Echo “Build Number: ” & objOS.BuildNumber ‘Build
Wscript.Echo “Build Type: ” & objOS.BuildType
Wscript.Echo “OS Type: ” & objOS.OSType
Wscript.Echo “Other Type Description: ” & objOS.OtherTypeDescription
WScript.Echo “Service Pack: ” & objOS.ServicePackMajorVersion & “.” & _
objOS.ServicePackMinorVersion
Next

Classic Shutdown Menu (VBSCRIPT) :

‘Shutdown.vbs – Call Windows shutdown choice popup.
set WshShell = wscript.CreateObject(“Shell.Application”)
WshShell.ShutdownWindows

I can go on like this with many useful scripts…Any of the reader interested in any script to automate your task.

email
Comments(14)
  1. Satish June 6, 2011
  2. parbat June 6, 2011
  3. Srikanth Rao June 6, 2011
    • subbuaxel June 7, 2011
      • Srikanth Rao June 7, 2011
        • subbuaxel June 7, 2011
          • subbuaxel June 7, 2011
  4. VJ June 7, 2011
    • Subhash June 7, 2011
    • subbuaxel June 7, 2011
  5. shenoyjoseph June 7, 2011
  6. Y8 June 14, 2011
  7. sushil August 2, 2011
  8. krunal July 17, 2012

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!