Start, Stop IIS6 sites programmatically with wmi

Start, Stop IIS6 sites programmatically with wmi

am 27.08.2007 11:38:00 von shane

Hi,

I'm looking for help with starting and stop sites using WMI and C#. So far
I've been able to connect to IIS6 on a remote server, create the site and
directories etc. but the sites are stopped by default.

Any code examples would be appreciated

thanks

Re: Start, Stop IIS6 sites programmatically with wmi

am 27.08.2007 18:54:35 von Kristofer Gafvert

Hi,

I don't have a complete code sample, but i think this may help (it may
have some errors, i don't have any reference in front of me right now):

ManagementObject webSite = new ManagementObject(...);

// Check if the website is stopped or paused
if ((int)webSite["ServerState"] == 4 || (int)webSite["ServerState"] == 6)
{
webSite.InvokeMethod("Start", null);

}


To stop the website, it should be if i remembers correctly:

webSite.InvokeMethod("Stop", null);

--
Regards,
Kristofer Gafvert
http://www.gafvert.info/iis/ - IIS Related Info


Shane wrote:

>
>Hi,
>
>I'm looking for help with starting and stop sites using WMI and C#. So far
>I've been able to connect to IIS6 on a remote server, create the site and
>directories etc. but the sites are stopped by default.
>
>Any code examples would be appreciated
>
>thanks

Re: Start, Stop IIS6 sites programmatically with wmi

am 28.08.2007 19:18:17 von Kristofer Gafvert

Great! I am glad to hear that you got it working.

Good luck with the rest of the code, and you know where we are if you need
help. :-)


--
Regards,
Kristofer Gafvert
http://www.gafvert.info/iis/ - IIS Related Info


Shane wrote:

>Hi,
>that's it, thanks!
>the problem was I was re-using the same ManagementPath.relativePath from
>when I invoked the CreateNewSite method.
>
>the working code is
>
>myPath.RelativePath = "IIsWebServer.Name='W3SVC/" + iisidentifer + "'";
>//iisidentifer is parsed from the return code from createnewsite method
> using (nac = new ManagementObject(scope, myPath, null))
> {
> if ((int)nac["ServerState"] == 4 ||
>(int)nac["ServerState"] == 6)
> {
> nac.InvokeMethod("Start", null);
>
> }
> }
>
>>Hi,
>>
>>I don't have a complete code sample, but i think this may help (it may
>>have some errors, i don't have any reference in front of me right now):
>>
>>ManagementObject webSite = new ManagementObject(...);
>>
>>// Check if the website is stopped or paused
>>if ((int)webSite["ServerState"] == 4 || (int)webSite["ServerState"] == 6)
>>{
>> webSite.InvokeMethod("Start", null);
>>
>>}
>>
>>
>>To stop the website, it should be if i remembers correctly:
>>
>>webSite.InvokeMethod("Stop", null);
>>
>>--
>>Regards,
>>Kristofer Gafvert
>>http://www.gafvert.info/iis/ - IIS Related Info
>>
>>
>>Shane wrote:
>>
>>>
>>>Hi,
>>>
>>>I'm looking for help with starting and stop sites using WMI and C#. So
>>>far
>>>I've been able to connect to IIS6 on a remote server, create the site and
>>>directories etc. but the sites are stopped by default.
>>>
>>>Any code examples would be appreciated
>>>
>>>thanks
>>