如何以编程方式重置IIS?

时间:2022-08-26 00:06:45

Is there any alternative to the IIS Administrative UI that can be used to reset IIS from a program?..

是否有可用于从程序重置IIS的IIS管理UI的替代方法?

now we have created a batch file if iis reset and scheduled it every hour......

现在我们已经创建了一个批处理文件,如果iis重置并每小时安排一次......

i just wanted something so that we should not be able to reset iis....

我只想要一些东西,以便我们不能重置iis ....

4 个解决方案

#1


Using the WMI interface, you can programatically recycle the AppPool

使用WMI界面,您可以以编程方式回收AppPool

Use MgmtClassGen from the SDK to generate your WMI class:

使用SDK中的MgmtClassGen生成WMI类:

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\mgmtclassgen" IIsApplicationPool        /n root\MicrosoftIISv2 /l VB /p IIsApplicationPool.vb

-or-

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\mgmtclassgen" IIsApplicationPool        /n root\MicrosoftIISv2 /l CS /p IIsApplicationPool.cs

Then use this in your code:

然后在你的代码中使用它:

Dim msScope As New ManagementScope("root\MicrosoftIISv2")
Dim wmiIISAppPool As IIsApplicationPool
Try
    wmiIISAppPool = New IIsApplicationPool(msScope, String.Format("W3SVC/AppPools/{0}", _AppPoolID))
    'Recycle it
    wmiIISAppPool.Recycle()

Catch ex As Exception
    LogEvent("    *** ERROR - AppPoolRecycle failed: AppPoolID: {0} {1}", _AppPoolID, ex.Message)
Finally
    If Not wmiIISAppPool Is Nothing Then wmiIISAppPool.Dispose()
End Try

#2


Look at the IIS Admin API, in particular the IIisServiceControl interface.

查看IIS Admin API,特别是IIisServiceControl接口。

#3


You can also use iisreset from command prompt to restart all of IIS.

您还可以从命令提示符使用iisreset重新启动所有IIS。

I believe tvanfossan answer is ok but the interface he recommends I think can only reset all of IIS once. You may want to programmatically identify which process running in your application pool you want to kill if you have a hung process.

我相信tvanfossan的答案还可以,但他推荐的界面我认为只能重置一次IIS。如果您有挂起的进程,您可能希望以编程方式识别要在应用程序池中运行的进程。

I suggest looking at the scripting interfaces as well: http://msdn.microsoft.com/en-us/library/ms526050.aspx

我建议也查看脚本界面:http://msdn.microsoft.com/en-us/library/ms526050.aspx

#4


there is file called iisreset.exe in system32 folder. You can create a batch to execute it.

system32文件夹中有一个名为iisreset.exe的文件。您可以创建批处理来执行它。

#1


Using the WMI interface, you can programatically recycle the AppPool

使用WMI界面,您可以以编程方式回收AppPool

Use MgmtClassGen from the SDK to generate your WMI class:

使用SDK中的MgmtClassGen生成WMI类:

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\mgmtclassgen" IIsApplicationPool        /n root\MicrosoftIISv2 /l VB /p IIsApplicationPool.vb

-or-

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\mgmtclassgen" IIsApplicationPool        /n root\MicrosoftIISv2 /l CS /p IIsApplicationPool.cs

Then use this in your code:

然后在你的代码中使用它:

Dim msScope As New ManagementScope("root\MicrosoftIISv2")
Dim wmiIISAppPool As IIsApplicationPool
Try
    wmiIISAppPool = New IIsApplicationPool(msScope, String.Format("W3SVC/AppPools/{0}", _AppPoolID))
    'Recycle it
    wmiIISAppPool.Recycle()

Catch ex As Exception
    LogEvent("    *** ERROR - AppPoolRecycle failed: AppPoolID: {0} {1}", _AppPoolID, ex.Message)
Finally
    If Not wmiIISAppPool Is Nothing Then wmiIISAppPool.Dispose()
End Try

#2


Look at the IIS Admin API, in particular the IIisServiceControl interface.

查看IIS Admin API,特别是IIisServiceControl接口。

#3


You can also use iisreset from command prompt to restart all of IIS.

您还可以从命令提示符使用iisreset重新启动所有IIS。

I believe tvanfossan answer is ok but the interface he recommends I think can only reset all of IIS once. You may want to programmatically identify which process running in your application pool you want to kill if you have a hung process.

我相信tvanfossan的答案还可以,但他推荐的界面我认为只能重置一次IIS。如果您有挂起的进程,您可能希望以编程方式识别要在应用程序池中运行的进程。

I suggest looking at the scripting interfaces as well: http://msdn.microsoft.com/en-us/library/ms526050.aspx

我建议也查看脚本界面:http://msdn.microsoft.com/en-us/library/ms526050.aspx

#4


there is file called iisreset.exe in system32 folder. You can create a batch to execute it.

system32文件夹中有一个名为iisreset.exe的文件。您可以创建批处理来执行它。