Windows command prompt tips

Following tips are useful while scripting in Windows


Everybody likes comments to there scripts. In win32 shell any line starting with :: is a comment

:: This is a comment


Installing Printer from Command Line

As a linux administrator I always prefer CLI mode than GUI. But at work I also have to manage windows machines. Most boring task in windows is Printer Installation. If you don’t have active directory at your place you can’t automate the task & you have to go to user’s desk for installation. But windows have some in built script which can help you in installing printer from command line mode.

Configure TCP/IP from the Command Prompt using Netsh

Most of the time user use same laptop at home as well as at office. At home most probebly they have different network and in office if the system administrator is smart, he will be using DHCP server to allocate IP address. While working from home they have to set IP address manually as per their ISP. To make this task easier we can use netsh.

Generating report via CPUZ and sending it to your email id

Most of the time we need our client’s hardware information. CPU-Z is a freeware that gathers information on some of the main devices of your system.

CPU-Z is capable of generating html report. Client can send the report as an attachment to us. To make this task simpler, we are using script to automate the same. Script will generate cpu-z report in html format at it will ask user for their email server credential to send the report via email.

Download CPU-Z

Download sendEmail for windows

Running the program
Create an “inv” folder in c:
Extract CPU-Z and sendEmail & copy cpuz.exe, cpuz.ini, sendEmail.exe to c:\inv
Your folder structure should be


We need to modify cpuz.ini as per our need,


Now we have to create bat file for sending CPU-Z’s report

@echo off
cd c:\inv\
del report.htm
echo "Genrating cpuz info"
cpuz.exe --html=report
cd \
cd c:\inv
SET /P from=[Enter your email id]
SET /P to=[Enter the person email id to whom you want to send email]
SET /P sub=[Enter subject]
SET /P smtp=[Enter your smtp server ip]
SET /P port=[Enter your smtp server port]
SET /P username=[Enter username for smtp server]
SET /P password=[Enter smtp server password]
sendemail.exe -f %from% -t %to% -u %sub% -s %smtp%:%port% -m "inv report" -a report.htm -xu %username% -xp %password% -l smtp.log -o message-content-type=auto

Bat file will generate a report of CPU-Z & send the same on user mention email id. It will ask user for his email id, sender, subject, smtp server address, credentials for smtp server. It will also generate a log file as c:\inv\smtp.log
You can hard code your email id, smtp server credentials.

Enabling Thunderbird’s logging

Most of the time we have to troubleshoot mail clients for numerous reason. For the same Thunderbird provides session logging. Below mention methods are only useful for investigating problems that occur after Thunderbird establishes a connection to a server. If Thunderbird cannot connect to the server, then it is pointless trying to log the connection.

On Windows
Create a batch file to start Thunderbird & place it on desktop

set mydate=%date:~-4,4%%date:~-7,2%%date:~-10,2%
set mytime=%time:~0,2%%time:~+3,2%
set NSPR_LOG_FILE=%USERPROFILE%\thunderbird_%mydate%_%mytime%.log
start /d "c:\program files\mozilla thunderbird" thunderbird.exe

Adjust log file location (NSPR_LOG_FILE) as per your need

On linux
Create a bash script to start the Thunderbird

MYDATE=`date "+%Y%m%d_%H%M%S"`
exit $?

Adjust thunderbird path (TB_PATH) as per your installation.
If you want to log all modules instead of just IMAP (SMTP, e.g.) then replace “IMAP” above with “all”

rss twitter facbook