Download Source Files - 15 KB
Introduction
Have you EVER BEEN ASKED to Deploy a new version of a web application to production? Typically, You will have to do the following:
Shutdown the web server. Copy the new files and make whatever configuration changes you need. Start the web server. Since the IIS web server is implemented in a windows service, i.e. the IISADMIN service, step 1 and 3 can be done manually by using the
Services icon in the control panel (nt) or the
Services menu Under
Administrative Tools (Windows 2000). You Can Also Use the
Internet Services Manager to do this. If your application is very complicated, you might want to do the whole installation from a program (scripts). At my work place, the developers are not supposed to mess with production machines, they are required to write Scripts to Install Everything and Hand The Installation Scripts to the Production Support Team.
In this article, I will introduce a small utility program that can be used to install, uninstall, start, and stop all windows services. In particular, you can use it to start / stop the IIS web server. I am aware of other good articles about windows services on this site. My intention is provide a tool that busy (and lazy) developers can use without bothering with all the details, please study the source code or other related articles if you really want to learn more about windows services.
The name of the utility program is ServiceInstaller.exe For your convenience, I have included the executable with the source code To install a Windows service, you need to run the following at the command prompt..:
ServiceInstaller -i NameOfservice FullPathofexecutable AccountTouse Password Faccount
For example,
ServiceInstaller -i myService c: /myService/myService.exe myDomain / myID myPasswordIf you omit the last two arguments, the service will be using the local system account By the way, the account you use should be granted the privilege to run services.. The Command To Uninstall The Service Is Much Simpler:
ServiceInstaller -u NameOfService
After Installing The Service, You Can Start (Run) The Service With The Following Command:
ServiceInstaller -r nameofservice [other arguments for the service]
And Here Is The Command To Stop (Kill) The Service:
ServiceInstaller -k nameofService
Now I will show you how to use this tool to shutdown and restart the IIS Web Server. The situation is actually a little more complicated because there may be other services depending on the IISADMIN service. If you simply try to shutdown IISADMIN, it will probably fail The list of services depending on IISADMIN may be different on each machine On my workstation, for example, there are three other services depend on IISADMIN They are:... World Wide Web Publishing Service (W3SVC), FTP Publishing Service (MSFTPSVC) And NetWork News Transport Protocol (NNTPSVC). What We need to do is Shutdown All Services Depending ON Iisadmin First and Ten Shutdown Iisadmin Itself:
ServiceInstaller -k W3SVC
ServiceInstaller -k MSFTPSVC
ServiceInstaller -k nntpsvc
ServiceInstaller -k iisadmin
The Following Commands Will Restart The Four Services We Have Shutdown:
ServiceInstaller -R iisadmin
ServiceInstaller -R nntpsvc
ServiceInstaller -R MSFTPSVC
ServiceInstaller -R W3SVC
Actually, starting any service depending on IISADMIN will also start IISADMIN itself (so the first command in the above is unnecessary). Writing a Windows service is a little trickier, but you do not have to do it (fortunately). My article Start Your Windows Program from an NT Service Introduces A Special Windows Service That Can make Other program behave like a service. Pleases.xiangyang Liu
Click Here to View Xiangyang Liu's Online Profile.
Other Popular Articles:
Driver Development Part 1: Introduction to DriversThis article will go into the basics of creating a simple driver A simple demo for WDM Driver developmentWDM Driver programming introduction with three Pseudo Drivers API hooking revealedThe article demonstrates how to build a user mode Win32 API spying system.. Using mC.exe, message resources and the NT event log in your own projectsA tutorial that shows how to integrate mc.exe in the build environment of Visual Studio and use it for event logging and string resources.