简体   繁体   中英

How to recycle an IIS Application pool from a classic ASP page?

I need to programatically recycle an IIS Application pool from a classic ASP page. How could I achieve that ?

I am able to do it from a VBS, but not from an ASP page.

So far, I have tried this code, which returns no error, but does nothing :

<%
Set objWShell = Server.CreateObject("WScript.Shell")
    Set objCmd = objWShell.Exec("%systemroot%\SysWow64\cmd.exe /c %systemroot%\system32\inetsrv\appcmd.exe recycle apppool /apppool.name:MyAppPoolNameHere")
    Set objCmd = nothing
Set objWShell = nothing
%>

I also have tried the following code (which works in VBS, but not inside an ASP page) :

<%
Set locator = Server.CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.connectserver("MyServerName", "root/MicrosoftIISv2")
Set APCollection = Service.InstancesOf("IISApplicationPool")

Response.write APCollection.count

For Each APInstance In APCollection
    Response.Write "<br>" & APInstance.Name
    APInstance.Recycle
Next
%>

Many thanks for your help ;-)

Faced same issue long ago, ended up writing code that edits the web.config file, and thus causing automatic recycle of the application pool.

To make it work you need to grant full permissions for the IUSR account over the web.config file, I don't think those are given by default.

Code is as follows: (lots of debug, you can remove all the Response.Write lines)

<% Option Explicit %>
<% Response.Buffer = True %>
<%
Const FILE_PATH="C:\Inetpub\wwwroot\Web.config"
Dim objFSo, objFile, strData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Response.Write("File: " & FILE_PATH & ", Exist? " & objFSO.FileExists(FILE_PATH) & "<br />")
Response.Flush()
Set objFile = objFSO.OpenTextFile(FILE_PATH)
strData = objFile.ReadAll
objFile.Close
Response.Write("Got " & Len(strData) & " bytes of data<br />")
Response.Flush()
Set objFile = objFSO.CreateTextFile(FILE_PATH)
objFile.Write(strData)
objFile.Close
Response.Write("Success")
Response.Flush()
Set objFile = Nothing
Set objFSO = Nothing
%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM