Monthly Archives: September 2012

This post is a collection of some of the more commonly used command line utilities when doing basic troubleshooting in a Windows domain environment.

To open a command window within a directory from Windows Explorer, hold the Shift key and right-click on the directory, then choose “Open command window here”.

cd

Displays the name of the current directory or changes the current folder.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true

Used within a command window to change the current active directory, allowing navigation through the computer’s mapped drives and their directory structures.

Usage:

cd
Displays the current directory path.

cd
Moves to the root of the current drive.

cd /d e:
Moves to the E: drive from another drive. It’s also possible to move to a different drive by typing only the drive letter followed by a colon, ex: D:

cd..
Moves to the parent directory of the current directory (move up one directory toward the root).

cd “People to sue next”
Moves from the current directory into the subdirectory named “People to sue next”. A handy trick is to just type the first few characters of the directory name, and then hit the tab key to auto-complete the rest of the directory name from the first alphabetical match found, and even wrap it in double quotes if it contains spaces. For example, the same command as above can by typed: cd peop <tab>

If the current directory contains multiple matches for the characters typed, hitting tab again will cycle to the next match.

The tab method can be used more than once, to chain together a series of directories. For example, to move to the C:\Users\Public\Documents directory from a command prompt at the root of C:, one can type: cd u <tab> p <tab> d <tab> <tab> <enter>

dir

Displays a list of a directory’s files and subdirectories.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx?mfr=true

Usage:

dir
Displays the directories and files in the current directory.

dir /s
Displays the directories and files in the current directory and all sub directories.

Dir can also be used to search for a file, and in many cases it works better than the Windows Explorer search.

dir c:\findme.txt /s
Displays a list of all instances of a file named “findme.txt” on the C: drive. It’s also possible to navigate to a location, such as the root of C:, and type: dir /s findme.txt to search that location and all subdirectories for a file named “findme.txt”.

Wildcards are allowed in the form of an asterisk. For example, type: dir c:\*.doc /s to search the C: drive for all files with a .doc or .docx extension (I’m not sure why it also locates .docx files, when there is no wildcard specified at the end of the extension, but it does).

Another command line utility for searching for files is where, but the syntax is slightly more complicated.

gpupdate

Refreshes local and Active Directory-based Group Policy settings, including security settings.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/refrgp.mspx?mfr=true

If you absolutely must reapply all settings, you can use the /force switch. After reading about the difference between gupdate and gpupdate /force, I now feel that gupdate is sufficient to reapply group policy nearly all of the time, and the /force switch shouldn’t automatically be used.

Usage:

gpupdate
Reapplies group policy.

gpresult

Displays Group Policy settings and Resultant Set of Policy (RSOP) for a user or a computer.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true

Usage:

gpresult /r
Displays RSoP summary data, which includes the last time group policy was applied, from which server group policy was applied, and the groups for which the current user is a member.

gpresult /h gpreport.html
Generates a report of the applied group policy settings and saves it in HTML format as a file named gpreport.html. When generating a report as a user that is not a local administrator, either supply a full path to a valid location for gpreport.html, or navigate to a location (like the Public Documents directory) before running the command, or else the utility may be unable to create the report due to insufficient rights to the current directory.

ipconfig

Displays all current TCP/IP network configuration values and refreshes Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) settings. Used without parameters, ipconfig displays the IP address, subnet mask, and default gateway for all adapters.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ipconfig.mspx?mfr=true

Usage:

ipconfig
Display the computer’s IP address and default gateway, for each network adapter.

ipconfig /all
Displays full TCP/IP information, including the MAC address, DHCP server, and DNS servers, for each network adapter.

net use

Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. The command also controls persistent net connections. Used without parameters, net use retrieves a list of network connections.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_use.mspx?mfr=true

Usage:

net use
Lists all of the computer’s connections (mapped network drives).

net use e: \\ComputerName\ShareName
Maps the E: drive to the ShareName shared resource on the ComputerName computer. To map the local E: drive to the C: drive (which is a hidden share) of a remote machine named Loomer, type: net use e: \\loomer\c$

net use e: /delete
Removes the connection currently mapped to the local E: drive.

If you are connecting to a network share that your regular account does not have rights to access, you will be prompted for a username. You will need to also supply the domain, ex: domainusername

nslookup

Displays information that you can use to diagnose Domain Name System (DNS) infrastructure.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/nslookup.mspx?mfr=true

Usage:

nslookup <ipaddress or computername>
Queries the local computer’s default DNS name server for information on the specified IP address or computer name. Supply either piece of information and nslookup will return both pieces. It’s also possible to specify a particular DNS name server to be queried, which is useful when troubleshooting whether DNS is propagating/replicating correctly.

ping

Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message Protocol (ICMP) Echo Request messages. The receipt of corresponding Echo Reply messages are displayed, along with round-trip times. Ping is the primary TCP/IP command used to troubleshoot connectivity, reachability, and name resolution.

You can use ping to test both the computer name and the IP address of the computer. If pinging the IP address is successful, but pinging the computer name is not, you might have a name resolution problem.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ping.mspx?mfr=true

Usage:

ping <ipaddress or computername>
Makes four attempts to contact the computer at the specified IP Address or with the specified computer name, and reports back whether the machine could be contacted and the time taken for the request to travel to the remote computer, be acknowledged, and the acknowledgement received by the local computer.

ping <ipaddress or computername> -t
Repeatedly attempts to contact the remote computer until interrupted by pressing Ctrl+Break or Ctrl+C. This is sometimes called a persistent ping.

systeminfo

Displays detailed configuration information about a computer and its operating system, including operating system configuration, security information, product ID, and hardware properties, such as RAM, disk space, and network cards.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/systeminfo.mspx?mfr=true

The systeminfo command also reveals installed hotfixes and some information about the computer that isn’t readily available in Device Manager or other MMC Snap-ins, such as the BIOS version.

Usage:

systeminfo
Displays information about the local computer.

systeminfo /s computername /u domainuser
Displays information about a remote computer named computername.

systeminfo /s computername | find “System Model:”
Retrieves information about a remote computer named computername, but pipes the output of systeminfo to the find command, which returns only the line containing the string “System Model:”. This output in the command window shows only “System Model:” followed by the model of the remote computer.

The systeminfo report can be sent to a text file, ex: systeminfo > systeminforeport.txt

Bonus commands

getmac

Returns the media access control (MAC) address and list of network protocols associated with each address for all network cards in each computer, either locally or across a network.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/getmac.mspx?mfr=true

Usage:

getmac /v
Shows MAC addresses for the local computer.

getmac /s computername /u domainusername /v
Shows MAC addresses for a remote computer named computername while authenticating as a different user.

(Need to test this.)

msg

Sends a message to a user (this may be turned off in many environments). Run msg /? for usage information.

Ardamis.com is on the map – the internet map, that is! /knee-slap

The internet map is a graphical representation of a site’s relative traffic, with over 350 thousand sites are represented. It’s unclear where the data comes from, but it’s flattering to be included.

The Internet Map

The Internet Map

Ardamis.com’s location puts it in a cluster of tech-related sites, right next to apachefriends.org and not too distant from php.net.

While not quite as wickedly awesome as The Scale of the Universe 2, it’s worth spending a few minutes exploring.

I needed to insert a short delay between two processes, so I whipped up a little VBScript that accepts an argument in seconds and then sleeps for that amount of time. If no argument is passed, it sleeps for 3 seconds. It writes to the Application event log before it sleeps and after it wakes.

Usage: sleep.vbs 5

It could be better, sure, but I’m humble about it. It doesn’t validate that the argument is an integer, for example. But it does the trick when used correctly.

sleep.vbs

Option Explicit

'Accepts input in seconds and converts the input to microtime, then sleeps for that long

Dim WshShell
Dim strEventInfo
Dim intSeconds, intMicrotime

Set WshShell = CreateObject("WScript.Shell")

If WScript.Arguments.Count > 0 Then
	intSeconds = WScript.Arguments.Item(0)
Else
	intSeconds = 3
End If

intMicrotime = intSeconds * 1000

LogEvent "The sleep.vbs script is sleeping for " & intSeconds & " seconds."

'Sleep briefly to allow processes to finish
WScript.Sleep intMicrotime 

LogEvent "The sleep.vbs script is done sleeping."

'******************************************************
'* Subroutine: LogEvent(strEventInfo)
'*   Creates a Windows Event Log information entry with the specified text
'******************************************************
Sub LogEvent(strEventInfo)
	WshShell.LogEvent 4, strEventInfo
End Sub

I’m not an electrician, and my understanding of the Code is admittedly flimsy, but I believe that it’s illegal to use 3-prong grounding receptacles on 2-wire circuts (which is the arrangement that exists in most of the rooms in our house). I’m also fuzzy about whether doing any work at all, even to just replace outlets and ground them, requires that I replace the wiring with proper 3-wire, such as Romex. That uncertainty not withstanding, I’ve decided to take it upon myself to begin improving the situation by replacing all of the open ground receptacles with new receptacles and ground them to the box. Thankfully, Chicago has long required solid metal conduit, which ought to provide the ground, though I’m finding that there just isn’t a ground wire at all in many of the boxes. I suspect that someone came along 20-years ago and replaced the 2-prong outlets with 3-prong grounded outlets, and just didn’t ground them. In the worst-case scenario, where a ground wire to the box still doesn’t effectively ground the receptacle, my plan is to install a 3-prong GFCI outlet (which I understand will need to be labeled No Equipment Ground on the cover plate).

To make sure I don’t mess up too badly, I’ve been reading up on residential wiring, and have watched quite a few videos on how to replace outlets. One of the best videos I’ve found was by Joseph Matson, a 35-year union electrician. He mostly does woodworking videos, but his video on how to install an electrical outlet is absolutely top notch.

I found the use of tails out from the receptacle to be genius. Sure, it adds some bulk, but the advantage of giving current a means of bypassing the receptacle obviously outweighs the nuisance of stuffing a few extra inches of wire and some wire nuts into the box.

The only thing I wished he addressed in the video is the final touch of wrapping of the outlet in elecrical tape to cover the terminal screws. I still do this because this is how I was taught decades ago by my electrician uncle. I understand that it was used more when metal boxes were standard, to prevent the terminal screws from coming into contact with the side of the box, but I feel it’s still a neat way to tidy up at the end.

Mr. Matson also has a tutorial on how to install a single pole electrical switch, and replacing a few of the light switches may become my next project. (I’m partial to those switches that firmly snap into one position or another with a near-silent thwap.)

I happen to have two rolls of electrical tape and a handful of receptacles and solidly thwapping switches laying around, so all I really need is some 6-inch lengths of 12 AWG wire for the ground wire and some 1032 ground screws. But as long as I’m shopping, I may as well stock the larder and also get some tough-looking lineman’s pliers like Joe uses.

My Home Depot shopping list:

Irwin 9.5 in. North American Lineman’s Pliers $16.57
Ideal Green 12 AWG Solid Pigtails with Screws (5-Pack) $2.97
Southwire Romex SIMpull 25 ft. 12-2 NM-B Wire $16.44
Ideal 76B Red Wire Nuts (100-Pack) $7.98

The VBScript code below creates a text file in your %TEMP% directory using datestamp and timestamp data as part of the file name. The file name uses the following format: YYYYMMDD-HHMMSS.txt.

It seems like I am forever writing log files for my VBScript projects, and this is a pretty good way of giving them meaningful and generally unique file names. Extend it to suit your purposes.

Option Explicit

'#########################################################
'##  Initialize global variables and objects
'#########################################################

Dim WshShell
Dim strSafeDate, strSafeTime, strDateTime, strLogFilePath, strLogFileName

Set WshShell = CreateObject("WScript.Shell")

strLogFilePath = WshShell.ExpandEnvironmentStrings("%TEMP%")

strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)

strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

'Set strDateTime equal to a string representation of the current date and time, for use as part of a valid Windows filename
strDateTime = strSafeDate & "-" & strSafeTime

'Assemble the path and filename
strLogFileName = strLogFilePath & "\" & strDateTime & ".txt"

'Create the file and write a line of text to it
CreateLog strLogFileName, strDateTime

'******************************************************
'* Subroutine: CreateLog(strLogFileName,strEventInfo)
'*   Creates text file containing a line of text
'******************************************************
Sub CreateLog(strLogFileName,strEventInfo)
	'http://msdn.microsoft.com/en-us/library/5t9b5c0c(v=vs.84).aspx
   Dim objFSO, objTextFile
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objTextFile = objFSO.CreateTextFile(strLogFileName, True)
   objTextFile.WriteLine(strEventInfo)
   objTextFile.Close
End Sub

Easy peasy.

Microsoft has a nifty tool called Orca.exe that lets you directly edit options within msi installer files and msp patch files.

Orca.exe is a database table editor for creating and editing Windows Installer packages and merge modules. The tool provides a graphical interface for validation, highlighting the particular entries where validation errors or warnings occur.

This tool is only available in the Windows SDK Components for Windows Installer Developers. It is provided as an Orca.msi file. After installing the Windows SDK Components for Windows Installer Developers, double click Orca.msi to install the Orca.exe file.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa370557(v=vs.85).aspx

Orca.msi was originally included in the Windows Installer 4.5 SDK, which is no longer available as a stand-alone download. Orca.exe version 5.0.7693.0 and other tools for working with msi files are part of the Microsoft Windows SDK for Windows 7 and .NET Framework 4 (or for previous versions, try the older Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1). The package that includes Orca.msi is available as an a la carte selection from the Microsoft Windows SDK web installer. Proceed through the web installer wizard and then select only the “Debugging Tools for Windows” under “Common Utilities” for the minimum install. Orca.Msi will be saved to “C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\”.

If you prefer a massive download just to get a 2 MB executable, the entire Microsoft Windows SDK is available as a 1.4 GB ISO from Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 (ISO).

Should Windows 7 be old news to you, you can try the Windows Software Development Kit (SDK) for Windows 8. (I have no idea what’s in there.)