Programmatically Test Enable / Disable IIS6 Compatibility Role in IIS7

How can I check with C # if the IIS6 compatibility role is enabled / disabled in IIS7?

+3
source share
3 answers

you can check the reading of the value in the registry

HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp\Components\WMICompatibility

or you can output the contents of servermanagercmd to an xml file and parse this file that is looking for the iis6 compatibility component

ServerManagerCmd -query [SaveFile.xml]

If you do this on R2, servermanagercmd is now deprecated, so you can use powershell to achieve the same check. Here are some examples of powershell, in this case remotely http://www.techmumbojumblog.com/?p=217

WMI , , , , IIS, , .

btw, , , , #, , wmi iis6, - (-, ), - api, iis7, Microsoft.Web.Administration.dll System32\inetsrv.

using Microsoft.Web.Administration;
+3

, ! =)

// Ok, this is stupid, but I can't find any other way to do this
// Detect whether we're in integrated mode or not
#warning GIANT HACK FOR IIS7 HERE
try
{
    var x = HttpContext.Current.CurrentNotification;
    _isIntegratedMode = true;
}
catch (PlatformNotSupportedException)
{
    _isIntegratedMode = false;
}
catch (NullReferenceException)
{
    _isIntegratedMode = true;
}

, , (, - , )

+1

You can probably do this by programming a query for the WMI IIS7 provider. http://learn.iis.net/page.aspx/162/managing-sites-with-iis-7039s-wmi-provider/

I do not know if you can do this through powershell.

0
source

Source: https://habr.com/ru/post/1739263/


All Articles