As an ASP.NET web developer, there are a few tasks that I must perform often for which I am glad to be able to perform via the command line. GUIs are great, but there are some things that are simply faster to do via the command line. Although we do have Cygwin installed to enhance our tool belt with commands like grep, there are a few ASP.NET related commands that I wanted to share with you today. Some of these are more useful on Windows 2003 server (because you can run multiple worker processes), but I hope you will find them useful.
1) Restarting IIS
The iisreset command can be used to restart IIS easily from the command line. Self-explanatory.
Internet services successfully stopped
Internet services successfully restarted
2) Listing all ASP.NET worker processes
You can use tasklist to get the running worker processes.
tasklist /FI "IMAGENAME eq w3wp.exe"
Image Name PID Session Name Session# Mem Usage
w3wp.exe 129504 Console 0 40,728 K
You can also use the following command if you have Cygwin installed (easier to remember)
tasklist | grep w3wp.exe
w3wp.exe 4456 Console 0 54,004 K
w3wp.exe 5144 Console 0 101,736 K
w3wp.exe 2912 Console 0 108,684 K
w3wp.exe 3212 Console 0 136,060 K
w3wp.exe 852 Console 0 133,616 K
w3wp.exe 352 Console 0 6,228 K
w3wp.exe 1556 Console 0 155,264 K
w3wp.exe 3480 Console 0 6,272 K
3) Associating a process ID with a particular application pool
Should you want to monitor memory usage for a particular worker process, the results shown above are not very useful. Use the iisapp command.
W3WP.exe PID: 4456 AppPoolId: .NET 1.1
W3WP.exe PID: 5144 AppPoolId: CustomerA
W3WP.exe PID: 2912 AppPoolId: CustomerB
W3WP.exe PID: 3212 AppPoolId: Blog
W3WP.exe PID: 852 AppPoolId: LavaBlast
W3WP.exe PID: 352 AppPoolId: CustomerC
W3WP.exe PID: 1556 AppPoolId: CustomerD
W3WP.exe PID: 3480 AppPoolId: DefaultAppPool
By using iisapp in conjunction with tasklist, you can know which task is your target for taskkill.
4) Creating a virtual directory
When new developers checkout your code for the first time (or when you upgrade your machine), you don’t want to spend hours configuring IIS. You could back up the metabase and restore it later on, but we simply use iisvdir. Assuming your root IIS has good default configuration settings for your project, you can create a virtual directory like so:
iisvdir /create “Default Web Site” franchiseblast c:\work\lavablast\franchiseblast\
5) Finding which folder contains the desired log files.
IIS saves its log files in %WINDOWS%\System32\LogFiles, but it creates a different subdirectory for each web application. Use iisweb /query to figure out which folder to go check out.
Connecting to server ...Done.
Site Name (Metabase Path) Status IP Port Host
Default Web Site (W3SVC/1) STARTED ALL 80 N/A
port85 (W3SVC/858114812) STARTED ALL 85 N/A
6) Many more commands…
Take a peek at the following articles for more command-line tools that might be useful in your context:
There are numerous command line tools distributed by Microsoft that help you manage your ASP.NET website. Obviously, the commands listed here are the tip of the iceberg! Although many developers know about these commands because they had to memorize them for some test, many are not even aware of their existence. Personally, I feel that if you write a single script that sets up IIS as you need it to develop, you’ll save time setting up new developers or when you re-install your operating system. Script it once and reap the rewards down the road.