tags:

views:

1385

answers:

4

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

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

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

+2  A: 

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

tvanfosson
actually my prob is i dont have much knowledge about the .net but of java..some project is deployed at our client site of .net..which is getting down in a day lot of time..so i need some code or alternative to make that beeter....and i should not need to reset thee iis...
vivek
A: 

You can also use iisreset from command prompt to restart all of 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.

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

Klathzazt
+1  A: 

Using the WMI interface, you can programatically recycle the AppPool

Use MgmtClassGen from the SDK to generate your WMI class:

"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
Christopher_G_Lewis
WMI is a rich toolset for all admin tasks and is the most secure remote access into a Win server. I've used WMI for several other tasks including installing apps across servers via SMS.
John Baughman
please can u explain liitle about this code...
vivek
Basically, MgmtClassGen gives you a strongly typed object given your WMI class. So the code creates a WMI IIsApplicationPool object tied to the Application Pool name (String.Format("W3SVC/AppPools/{0}", _AppPoolID). It exposes a method called Recycle() that uses WMI to recycle the app pool.
Christopher_G_Lewis
i m not very new in .net and deployed at clientside....how will i use it ....my subject is java..from where should i call it...
vivek
it will be recyling the application pool......and not exactly resetting the iis i think soo.......plz update
vivek
A: 

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

anupad