Introduction: Handy Batch File

Picture of Handy Batch File

In this Instructable I'm going to show you a Batch File that I created for you people.

so let me explain what this Batch File does. The script let's you generate backups of your files, check your network connectivity, close your not needed Windows services, delete temp files, history and cookies and at last it can show you your computer information.

The reason I made this is because I wanted to give you something awsome and that you can easly modify by your self.

Step 1: Basic Information

* If you don't want the information skip to the next step

Batch files allow MS-DOS and Microsoft Windows users to write a series of commands to run in order upon their execution for automating frequently performed tasks. For example, a batch file could be used to run frequently utilized commands, delete or move a series of files, and other jobs.

Step 2: Setting Up the Menu

Picture of Setting Up the Menu

If you are copying the code below make sure not to copy my explanation with it. I will put the explanation in the code only when it is new.

::The @ disables echo for that one command.
@ECHO OFF
::Clear the screen/window
CLS
::Executes the code from here. This is also called a "label"
:MENU
::Empty rule
echo.
::Display text on screen
echo  -----------------------------------
echo             Windows Tool              
echo  -----------------------------------
echo  1. Generate Backup of Files (enter 7 to see information)             
echo  2. Check Network Connectivity               
echo  3. Close Not Needed Windows Services (enter 6 to see services)      
echo  4. Deletes Temporary Internet Files, History and Cookies               
echo  5. Show Computer Information       
echo  -----------------------------------
echo  Help
echo  Exit 
echo.
::Sets M to the given input from the user
SET /P M=Choose and then press ENTER:
:: Note - list ERRORLEVELS in Decreasing order
::Checks if M is equal to the variables given below
IF %M%==exit GOTO End IF %M%==help GOTO Help if %M%==about GOTO About IF %M%==7 GOTO BackupInfo IF %M%==6 GOTO ShowServices IF %M%==5 GOTO GetComputerInfo IF %M%==4 GOTO DeleteCache IF %M%==3 GOTO CloseSomeServices IF %M%==2 GOTO CheckNetworkConn IF %M%==1 GOTO CreateBackup

Step 3: Setting Up the Functions

Picture of Setting Up the Functions

FIrst we're going to create all of the function that we need for this batch. In the next step we will fill them in with the correct code.

:About
echo.
echo ----------------------------------------------------------------- echo About echo ----------------------------------------------------------------- echo.
GOTO MENU
:Help
echo.
echo ----------------------------------------------------------------- echo Help echo -----------------------------------------------------------------
echo.
GOTO MENU
:BackupInfo
echo.
echo ----------------------------------------------------------------- echo Backup Information echo -----------------------------------------------------------------
echo.
GOTO MENU
:CreateBackup
echo.
echo ----------------------------------------------------------------- echo Creating Backup, please wait... echo -----------------------------------------------------------------
echo.
GOTO MENU
:CheckNetworkConn
echo.
echo ----------------------------------------------------------------- echo Checking connection, please wait... echo -----------------------------------------------------------------
echo.
GOTO MENU
:TRYAGAIN
echo.
echo Failure! echo.
echo.
:TRYIP
echo.
:TRYROUTER
echo.
echo Failure! echo.
echo.
goto :FAILURE
:ROUTERSUCCESS
echo.
echo Failure! echo.
echo.
goto :FAILURE
:NETDOWN
echo.echo  Failure!
echo.
echo.
goto :FAILURE
:SUCCESSDNS
echo.
echo Failure! echo.
echo.
goto :FAILURE
:SUCCESS
echo.
echo Success! echo.
echo.
goto MENU
:SUCCESS2
echo.
echo Success? echo.
echo.
goto MENU
:FAILURE
echo.
echo Failure! echo.
echo.
goto :MENU
:ShowServices
echo.
echo ----------------------------------------------------------------- echo Services That Will Be Stopped echo -----------------------------------------------------------------
echo.
GOTO MENU
:CloseSomeServices
echo.
GOTO MENU
:DeleteCache
echo.
echo ----------------------------------------------------------------- echo Deleting Internet Cache... echo ----------------------------------------------------------------- echo.
GOTO MENU
:GetComputerInfo
echo.
echo ----------------------------------------------------------------- echo Show Computer Information (%computername%) echo ----------------------------------------------------------------- echo.
GOTO MENU
:End

Step 4: Filling Up the Functions

Now let's fill them in! insert the code below under the the last echo with --------

:about

echo This batch file was created by Kevin Tipker in June 2016
echo and is free to use and modify on your own risk. Please be very echo carefull if you don't understand what you are doing echo. echo You can find more of my work in the link below. echo - https://www.instructables.com/member/Kevin+Tipker

:Help

echo * To run this bat file without any problems you need to be a Administrator
echo and execute it as Administrator echo. echo 1. Generate Backup of Files (enter 7 to see information) echo - Check if there is a map called Backup in C:/ If not create it echo. echo 2. Check Network Connectivity echo - Make sure to use LAN echo. echo 4. Deletes Temporary Internet Files, History and Cookies echo - The history, cookies etc files are located in echo C:\Documents and Settings\username\Local Settings\Temporary Internet Files

:BackupInfo

echo This process will make a backup of the following files:
echo - My Documents echo - Favorites echo - Email and contacts (MS Outlook) echo - Backing up email and address book (Outlook Express) echo - Registry echo. echo * NOTE: There is a change that not everything will be backed up echo and that is because you maybe not have MS Oulook or Outlook Express

:CreateBackup

:: variables

::this has to be above the title rule (see image 5)
set drive=C:\Backup set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo - Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo - Backing up Favorites... %backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

echo - Backing up email and address book (Outlook Express)... %backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book" %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

echo - Backing up email and contacts (MS Outlook)... %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

echo - Backing up the Registry... if not exist "%drive%\Registry" mkdir "%drive%\Registry" if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg" regedit /e "%drive%\Registry\regbackup.reg"

echo. echo Backup Complete!

:CheckNetworkConn

ping -n 1 www.google.com >nul
@echo off IF NOT ERRORLEVEL 1 goto :SUCCESS IF ERRORLEVEL 1 goto :TRYAGAIN

:TRYAGAIN

echo - Let me try a bit more, please wait...
@echo off ping -n 1 www.google.com >nul IF NOT ERRORLEVEL 1 goto :SUCCESS2 IF ERRORLEVEL 1 goto :TRYIP

:TRYIP

echo - Checking DNS...
echo - Lets try by IP address... @echo off ping -n 1 216.239.37.99|find "Reply from " >NUL IF NOT ERRORLEVEL 1 goto :SUCCESSDNS IF ERRORLEVEL 1 goto :TRYROUTER

:TRYROUTER

echo - Lets try pinging the router....
ping -n 2 192.168.1.1|find "Reply from " >NUL IF NOT ERRORLEVEL 1 goto :ROUTERSUCCESS IF ERRORLEVEL 1 goto :NETDOWN

:ROUTERSUCCESS

echo - It appears that you can reach the router, but internet is unreachable.

:NETDOWN

echo - It appears that you having network issues, the router cannot be reached.

:SUCCESSDNS

echo - It appears that you are having DNS issues.

:SUCCESS

echo - You have an active Internet connection

:SUCCESS2

echo - You have an active internet connection but some packet loss was detected.

:FAILURE

echo - You do not have an active Internet connection

:ShowServices

echo - ActiveX Installer (AxInstSV)
echo - BitLocker Drive Encryption Service echo - Printer Extensions and Notifications echo - Print Spooler echo - Optimize Drives echo - http service (for problems with localhost servers like XAMP)

:CloseSomeServices
::You can add diffrent services here just search them up on google

net stop AxInstSV
net stop BDESVC net stop PrintNotify net stop Spooler net stop defragsvc net stop http

:DeleteCache
::This is not everything you can use there are some more that you can use to delete internet files from your pc

echo - Starting process...
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2 RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1 echo - Done!

:GetComputerInfo

REM set variables
set system= set manufacturer= set model= set serialnumber= set osname= set sp= setlocal ENABLEDELAYEDEXPANSION set "volume=C:" set totalMem= set availableMem= set usedMem=

echo Getting data [Computer: %computername%]... echo Please Wait....

REM Get Computer Name FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A

REM Get Computer Manufacturer FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A

REM Get Computer Model FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

REM Get Computer Serial Number FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A

REM Get Computer OS FOR /F "tokens=2 delims='='" %%A in ('wmic os get Name /value') do SET osname=%%A FOR /F "tokens=1 delims='|'" %%A in ("%osname%") do SET osname=%%A

REM Get Computer OS SP FOR /F "tokens=2 delims='='" %%A in ('wmic os get ServicePackMajorVersion /value') do SET sp=%%A

REM Get Memory FOR /F "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a) set totalMem=%totalMem:,=% set availableMem=%availableMem:,=% set /a usedMem=totalMem-availableMem

FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree %volume%') DO ( SET "diskfree=!disktotal!" SET "disktotal=!diskavail!" SET "diskavail=%%j" ) FOR /f "tokens=1,2" %%i IN ("%disktotal% %diskavail%") DO SET "disktotal=%%i"& SET "diskavail=%%j"

echo. echo ----------------------------------------------------------------- echo Computer Information echo ----------------------------------------------------------------- echo - System Name: %system% echo - Manufacturer: %manufacturer% echo - Model: %model% echo - Serial Number: %serialnumber% echo - Operating System: %osname% echo - C:\ Total: %disktotal:~0,-9% GB echo - C:\ Avail: %diskavail:~0,-9% GB echo - Total Memory: %totalMem% echo - Used Memory: %usedMem% echo - Computer Processor: %processor_architecture% echo - Service Pack: %sp% echo -----------------------------------------------------------------

Step 5: Finished!

Picture of Finished!

You have finished your batch file! I hope I was clear enough with my explanations and otherwise dont be scared to ask me anything. In the future I will update the script some more and maybe even add some more functions.

Comments

joshed (author)2016-06-26

::The @ disables echo for that one command.

@ECHO OFF

::Clear the screen/window

CLS

::Executes the code from here. This is also called a "label"

:MENU

::Empty rule

echo.

::Display text on screen

echo -----------------------------------

echo Windows Tool

echo -----------------------------------

echo 1. Generate Backup of Files (enter 7 to see information)

echo 2. Check Network Connectivity

echo 3. Close Not Needed Windows Services (enter 6 to see services)

echo 4. Deletes Temporary Internet Files, History and Cookies

echo 5. Show Computer Information

echo -----------------------------------

echo Help

echo Exit

echo.

::Sets M to the given input from the user

SET /P M=Choose and then press ENTER:

:: Note - list ERRORLEVELS in Decreasing order

::Checks if M is equal to the variables given below

IF %M%==exit GOTO End

IF %M%==help GOTO Help

if %M%==about GOTO About

IF %M%==7 GOTO BackupInfo

IF %M%==6 GOTO ShowServices

IF %M%==5 GOTO GetComputerInfo

IF %M%==4 GOTO DeleteCache

IF %M%==3 GOTO CloseSomeServices

IF %M%==2 GOTO CheckNetworkConn

IF %M%==1 GOTO CreateBackup

:About

echo.

echo -----------------------------------------------------------------

echo About

echo -----------------------------------------------------------------

echo This batch file was created by Kevin Tipker in June 2016

echo and is free to use and modify on your own risk. Please be very

echo carefull if you don't understand what you are doing

echo.

echo You can find more of my work in the link below.

echo - https://www.instructables.com/member/Kevin+Tipker

echo.

GOTO MENU

:Help

echo.

echo -----------------------------------------------------------------

echo Help

echo -----------------------------------------------------------------

echo * To run this bat file without any problems you need to be a Administrator

echo and execute it as Administrator

echo.

echo 1. Generate Backup of Files (enter 7 to see information)

echo - Check if there is a map called Backup in C:/ If not create it

echo.

echo 2. Check Network Connectivity

echo - Make sure to use LAN

echo.

echo 4. Deletes Temporary Internet Files, History and Cookies

echo - The history, cookies etc files are located in

echo C:\Documents and Settings\username\Local Settings\Temporary Internet Files

echo.

GOTO MENU

:BackupInfo

echo.

echo -----------------------------------------------------------------

echo Backup Information

echo -----------------------------------------------------------------

echo This process will make a backup of the following files:

echo - My Documents

echo - Favorites

echo - Email and contacts (MS Outlook)

echo - Backing up email and address book (Outlook Express)

echo - Registry

echo.

echo * NOTE: There is a change that not everything will be backed up

echo and that is because you maybe not have MS Oulook or Outlook Express

echo.

GOTO MENU

:CreateBackup

echo.

echo -----------------------------------------------------------------

echo Creating Backup, please wait...

echo -----------------------------------------------------------------

:: variables

::this has to be above the title rule (see image 5)

set drive=C:\Backup

set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo - Backing up My Documents...

%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo - Backing up Favorites...

%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

echo - Backing up email and address book (Outlook Express)...

%backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"

%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

echo - Backing up email and contacts (MS Outlook)...

%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

echo - Backing up the Registry...

if not exist "%drive%\Registry" mkdir "%drive%\Registry"

if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"

regedit /e "%drive%\Registry\regbackup.reg"

echo.

echo Backup Complete!

echo.

GOTO MENU

:CheckNetworkConn

echo.

echo -----------------------------------------------------------------

echo Checking connection, please wait...

echo -----------------------------------------------------------------

ping -n 1 www.google.com >nul

@echo off

IF NOT ERRORLEVEL 1 goto :SUCCESS

IF ERRORLEVEL 1 goto :TRYAGAIN

:FAILURE

echo - You do not have an active Internet connection

echo.

GOTO MENU

:TRYAGAIN

echo.

echo Failure!

echo - Let me try a bit more, please wait...

@echo off

ping -n 1 www.google.com >nul

IF NOT ERRORLEVEL 1 goto :SUCCESS2

IF ERRORLEVEL 1 goto :TRYIP

echo.

echo.

:TRYIP

echo.

echo - Checking DNS...

echo - Lets try by IP address...

@echo off

ping -n 1 216.239.37.99|find "Reply from " >NUL

IF NOT ERRORLEVEL 1 goto :SUCCESSDNS

IF ERRORLEVEL 1 goto :TRYROUTER

:TRYROUTER

echo.

echo Failure!

echo - Lets try pinging the router....

ping -n 2 192.168.1.1|find "Reply from " >NUL

IF NOT ERRORLEVEL 1 goto :ROUTERSUCCESS

IF ERRORLEVEL 1 goto :NETDOWN

echo.

echo.

goto :FAILURE

:ROUTERSUCCESS

echo.

echo Failure!

echo - It appears that you can reach the router, but internet is unreachable.

echo.

echo.

goto :FAILURE

:NETDOWN

echo.

echo Failure!

echo - It appears that you having network issues, the router cannot be reached.

echo.

echo.

goto :FAILURE

:SUCCESSDNS

echo.

echo Failure!

echo - It appears that you are having DNS issues.

echo.

echo.

goto :FAILURE

:SUCCESS

echo.

echo Success!

echo - You have an active Internet connection

echo.

echo.

goto MENU

:SUCCESS2

echo.

echo Success?

echo - You have an active internet connection but some packet loss was detected.

echo.

echo.

goto MENU

:FAILURE

echo.

echo Failure!

echo.

echo.

goto :MENU

:ShowServices

echo.

echo -----------------------------------------------------------------

echo Services That Will Be Stopped

echo -----------------------------------------------------------------

echo - ActiveX Installer (AxInstSV)

echo - BitLocker Drive Encryption Service

echo - Printer Extensions and Notifications

echo - Print Spooler

echo - Optimize Drives

echo - http service (for problems with localhost servers like XAMP)

echo.

GOTO MENU

:CloseSomeServices

::You can add diffrent services here just search them up on google

net stop AxInstSV

net stop BDESVC

net stop PrintNotify

net stop Spooler

net stop defragsvc

net stop http

echo.

GOTO MENU

:DeleteCache

echo.

echo -----------------------------------------------------------------

echo Deleting Internet Cache...

echo -----------------------------------------------------------------

::This is not everything you can use there are some more that you can use to delete internet files from your pc

echo - Starting process...

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

echo - Done!

echo.

GOTO MENU

:GetComputerInfo

echo.

echo -----------------------------------------------------------------

echo Show Computer Information (%computername%)

echo -----------------------------------------------------------------

REM set variables

set system=

set manufacturer=

set model=

set serialnumber=

set osname=

set sp=

setlocal ENABLEDELAYEDEXPANSION

set "volume=C:"

set totalMem=

set availableMem=

set usedMem=

echo Getting data [Computer: %computername%]...

echo Please Wait....

REM Get Computer Name

FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A

REM Get Computer Manufacturer

FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A

REM Get Computer Model

FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

REM Get Computer Serial Number

FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A

REM Get Computer OS

FOR /F "tokens=2 delims='='" %%A in ('wmic os get Name /value') do SET osname=%%A

FOR /F "tokens=1 delims='|'" %%A in ("%osname%") do SET osname=%%A

REM Get Computer OS SP

FOR /F "tokens=2 delims='='" %%A in ('wmic os get ServicePackMajorVersion /value') do SET sp=%%A

REM Get Memory

FOR /F "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a)

set totalMem=%totalMem:,=%

set availableMem=%availableMem:,=%

set /a usedMem=totalMem-availableMem

FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree %volume%') DO (

SET "diskfree=!disktotal!"

SET "disktotal=!diskavail!"

SET "diskavail=%%j"

)

FOR /f "tokens=1,2" %%i IN ("%disktotal% %diskavail%") DO SET "disktotal=%%i"& SET "diskavail=%%j"

echo.

echo -----------------------------------------------------------------

echo Computer Information

echo -----------------------------------------------------------------

echo - System Name: %system%

echo - Manufacturer: %manufacturer%

echo - Model: %model%

echo - Serial Number: %serialnumber%

echo - Operating System: %osname%

echo - C:\ Total: %disktotal:~0,-9% GB

echo - C:\ Avail: %diskavail:~0,-9% GB

echo - Total Memory: %totalMem%

echo - Used Memory: %usedMem%

echo - Computer Processor: %processor_architecture%

echo - Service Pack: %sp%

echo -----------------------------------------------------------------

echo.

GOTO MENU

:End

joshed (author)2016-06-26

I got it working. You really should post the text all in one block, not taking the code out of the functions. I had to do so much copying and pasting and removing extra headers because of the messed up way you shared this. Thanks, though.

joshed (author)2016-06-26

None of this works.

joshed (author)2016-06-26

192.168.0.1 is quite a bit more common for routers than 192.168.1.1.

Shouldn't your script just simply look up what the gateway is and ping that?

About This Instructable

1,803views

33favorites

License:

Bio: I'm a freelance web developer. I love to make websites, whether this is a normal site, a blog or a WordPress-driven website. As a ... More »
More by Kevin Tipker:How to Clean an Infected ComputerHandy Batch FileHoe Maak Je Een Bootable USB-stick
Add instructable to: