IIS Insider - May 2005
By Chris Adams, Supportability Beta Lead, Microsoft Corporation
Recycling the Application Pool Remotely
Q. I need to recycle the application pool remotely in a Windows Server 2003 and IIS 6.0 environment. I haven't found an easy way without entering it at the server or using a remote console session. Can this be done remotely, and if so, do you have a technical document about the feature?
This is a very good question and one that Microsoft gets asked frequently by customers. The short answer is, yes, this can be done remotely. The long answer though requires a little knowledge of scripting if you are running IIS 6.0 on a Windows Server 2003 RTM version.
The script you need to do this locally is in Windows Server 2003 Service Pack 1, available from the Microsoft Download Center.
The command-line syntax used locally is:
iisapp /p <PID> /r
For example, if the w3wp process was Process ID (PID) 1234, then the command issued is:
iisapp.vbs /p 1234 /r
Figure 1 shows another example.
Figure 1: Using iisapp to Recycle an Application Pool
See full-sized image
You can also use the Application Pool's friendly name instead of the PID by using the /a switch instead of the /p.
You can view all the switches and options using the command-line help for iisapp.vbs by typing the command:
However, the iisapp.vbs command-line utility does not support remotely connecting to a computer.
If you are familiar with developing scripts this problem is solved using Windows Management Instrumentation (WMI) scripting or Active Directory Services Instrumentation (ADSI). These technologies are well documented in MSDN and you can use the IIS provider to connect to and recycle the application pools.
For example, here is a simple sample script with no error checking or dialog boxes. It also accepts no switches. However, it enables you to remotely recycle an application pool when you supply the following pieces of information in the script:
Target server Name (strServer)
Target server Username (strUsername)
Target server User Password (strPassword)
Application Pool name
I hope this sample script gets you started on your way to recycling a worker process running on a remote IIS 6.0 server:
strServer = "MyServer" //Replace this with the target server name strUser = "Administrator" //Provide Administrator privilege credentials strPassword = "password" //Input Administrator privileged account password Set LocatorObj = CreateObject("WBemScripting.SWbemLocator") LocatorObj.Security_.ImpersonationLevel = 3 Impersonate LocatorObj.Security_.AuthenticationLevel = 6 Pkt Privacy (required for remote administration over WMI as of Win2k3 SP1) Set ProviderObj = LocatorObj.ConnectServer(strServer, "root/MicrosoftIISv2", strUser, strPassword) Set MyAppPool = ProviderObj.Get( "IIsApplicationPool=w3svc/apppools/DefaultAppPool" MyAppPool.Recycle
There is detailed information in the IIS SDK to help you write a script that can remotely connect to an IIS server at:
By the way, the iisapp.vbs file that is delivered with Windows Server 2003 Service Pack 1 (SP1) can easily be copied to a Windows Server 2003 RTM version. There was no change in functionality to the core server between RTM and Service Pack 1 that would cause this script to not work. However, the script does not work on IIS versions below 6.0.
To review the changes added to Service Pack 1 for IIS 6.0, please review the following document on Microsoft's Web site:
How to Create Customized Snap-ins to Remotely Connect to IIS 6 Servers
Q. I would like to be able to remotely connect using the IIS Manager using a run command similar to how I connect to the event viewer. The IIS Manager snap-in, iis6.msc, doesn't seem to take a switch to specify a remote computer. I use the following command to connect to a remote computer's event viewer logs:
Is the same possible using the IIS 6 snap-in?
A. I wish it were that simple and it is certainly something that would make the administrative tasks a bit simpler for IIS administrators and developers. The IIS Manager that ships with IIS 6.0 does not accept any switches when executed at the command prompt. The iis6.msc snap-in is completely stand-alone and does not accept input from the administrator (unlike the event viewer snap-in).
However, there's a workaround. The Microsoft Management Console (MMC) allows customized snap-ins. The Active Directory snap-in can include local or remote servers and supports complete management of the resources.
A customized MMC allows you to execute a simple command that will connect to local or remote resources. The file can be stored locally on your workstation or remotely on a server
To create a customized snap-in, complete the following steps:
Start MMC by clicking Start, clicking Run, and typing mmc.
In the MMC console, select Add/Remove Snap-in on the Console menu.
In the Add/Remove Snap-in dialog box, click Add, and double-click Active Directory Users and Computers from the list of Available Stand-alone Snap-ins. If a wizard appears, follow the instructions on the screen.
Repeat step 3 to add each of these snap-ins: Security Templates, Distributed File System, and Certificates.
Click Close, and click OK.
Click Save on the Console menu.
These steps are outlined on the Microsoft TechNet Web site at:
Once you have installed the snap-ins you can then customize this single *.msc file to include remote servers. Note that the user of the snap-in must have administrative privileges on all servers listed in the snap-in.
To connect to a remote server using the MMC, do the following:
Locate the snap-in created in the previous step, and open it. For example, run MyIISServers.msc and press Enter.
In the MMC Console, right-click on Internet Information Services (IIS) Manager and choose Connect (see Figure 2).
Figure 2: Customized MMC Console
See full-sized image
In the Connect to Computer dialog box, enter the remote IIS 6 server name you want to connect to. If you would like to connect to the server using different credentials (such as administrator credentials for that server) then check "Connect as" and input those credentials in the text boxes provided (see Figure 3)
Figure 3: Connect to Computer Dialog Box
See full-sized image
Note: If you will be connecting with the same domain credentials (domain administrator or equivalent rights) to all IIS 6 servers, it is not necessary to use the Connect as credentials.
Repeat step 3 to add each IIS 6 servers you are interested in connecting to.
Click Save on the Console menu.
This approach would allow you to easily type the command similar to the one you are mentioning. The only step is to ensure that you include the full path to the file. For example, the following would work if issued at the Run command:
This saved *.msc file will store all servers, local and remote, that were configured and allow you quick and easy access to data across your Web environment. The only requirement is that you use an account with administrator privileges to connect to all computers. Although this isn't as easy as using the switch mechanism like the event viewer, it does allow you a single command to access remote servers.
Error When Using CDOSYS to Send E-mail Through an ASP Page
Q. We have an ASP application that needs to send email. We are currently developing this application locally and are using CDOSYS to send the email via an ASP page. We are getting the following error each time we attempt to use the mail application:
CDO.Message.1 (ox80040220)SendUsing configuration failed
Can you advise us how to resolve this problem?
A. The above error message can typically occur when the application logic that is provided to the API is invalid. The CDOSYS API is one that is very robust allowing developers to be very specific in building messages.
The first troubleshooting step is to ensure that your SMTP server is working in general. To begin, I typically have a generic page that has simple source code that is hard-coded and does not accept input from Web forms that users are providing. For example, you can save the following code and name it testmail.asp and put it in your Web content root directory:
<%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <% send by connecting to port 25 of the SMTP server Dim iMsg Dim iConf Dim Flds Dim strHTML Dim strSmartHost Const cdoSendUsingPort = 2 StrSmartHost = "mail.example.com" set iMsg = CreateObject("CDO.Message") set iConf = CreateObject("CDO.Configuration") Set Flds = iConf.Fields set the CDOSYS configuration fields to use port 25 on the SMTP server With Flds .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10 .Update End With build HTML for message body strHTML = "<HTML>" strHTML = strHTML & "<HEAD>" strHTML = strHTML & "<BODY>" strHTML = strHTML & "<b> This is the test HTML message body</b></br>" strHTML = strHTML & "</BODY>" strHTML = strHTML & "</HTML>" apply the settings to the message With iMsg Set .Configuration = iConf .To = "firstname.lastname@example.org" .From = "email@example.com" .Subject = "This is a test CDOSYS message (Sent via Port 25)" .HTMLBody = strHTML .Send End With cleanup of variables Set iMsg = Nothing Set iConf = Nothing Set Flds = Nothing %> </BODY> </HTML>
To use the above sample script code, replace the following lines with a valid To and From e-mail addresses. You should also replace the smarthost value to a valid mail server in your environment.
.To = "firstname.lastname@example.org" .From = email@example.com StrSmartHost = "mail.example.com"
If this script runs successfully, you can assume that there is a problem with the code itself within your page. If the above script fails, check the IIS Insider article at: http://www.microsoft.com/technet/community/columns/insider/iisi0102.mspx#EDAA, for further assistance in troubleshooting your SMTP server.
This problem, though, could be related to a bug in the Microsoft Exchange CDOSYS component as outlined in the Microsoft Knowledge Base (KB) article at http://support.microsoft.com/default.aspx?scid=kb;en-us;322338
You can find good step-by-step help for debugging problems with your SMTP service and\or application at http://www.microsoft.com/technet/archive/itsolutions/ecommerce/deploy/d5smtp.mspx. The guidance applies to Windows Server 2003, though it was written in support of Windows 2000.
Beyond that, there isn't much more that can go wrong. The problem is either related to either an invalid setting in the configuration (in the code) or it's a bug in the CDOSYS component. The fun part is chasing down the problem and determining where it resides. If you take the above "divide and conquer" approach, you should be able to eliminate outside variables and get your code working or the bug fixed. Good luck!
For More Information
Submit your questions to the IIS Insider. A response is not guaranteed; however, selected questions along with the answers will be posted in a future IIS Insider column.