I would like to write a script to start IIS server automatically if it is stopped.
- you can look for w3wp.exe in the process list (if it's IIS6)
- you can always try "iisreset /start" - I believe, it works even if IIS is already started
- take a look at the scripts provided by Microsoft in
C:\Inetpub\AdminScripts
(assuming default install location), there is startsrv.vbs, startweb.vbs - both do a good job
You can use the IIS Admin Scripts to query the server, and then start it if you need.
The script is located in systemroot\system32.
To query you server, just run IIsWeb.vbs /query w3svc/1
from a command line.
If it's not running, then you can run IIsWeb.vbs /start w3svc/1
to start it.
Here is an article with more information on these scripts.
One simple thing you can do if you are worried about iis not restarting after it fails is to set the services responses. If you go into services and then look at the properties for iis, you will see a recovery tab. Change each of the failure options to restart the service. one thing you could also do is create a batch file that includes iisreset and set the option to run program and have that be the program you select.
You can also use a third-party tool like Service Hawk to monitor and restart the IIS services for you if they should stop.