How to get IIS information via c#?

Asked

Viewed 151 times

4

How to get c# some IIS information like Version and some settings like Roles and Services.

*Note: My application is not Web.

  • http://stackoverflow.com/questions/446390/how-to-detect-iis-version-using-c

2 answers

3

One of the probably possible ways to do this is through consultations by WMI. Some information can be seen on the page IIS WMI Provider.

To work with the IIS and WMI, it is necessary to use the classes of namespace MicrosoftIISv2. There are some examples here.

Note: If you are using IIS 7, you need to enable compatibility with IIS 6 WMI, to power the MicrosoftIISv2 be present.

In that another page shows some examples of how to get information using WMI (tested on IIS 6 and Windows Server 2003).

I believe it is also possible to get some information with the class Environment. According to this page, this can also be done using the Request.ServerVariables, example:

lblServerIP.Text = Request.ServerVariables["LOCAL_ADDR"];
lblMachineName.Text = Environment.MachineName;
lblUserDomainName.Text = Environment.UserDomainName.ToString();
lblUserName.Text = Environment.UserName;
lblOSVersion.Text = Environment.OSVersion.ToString();
lblStartTime.Text = (Environment.TickCount / (1000 * 60 * 60)) + "Hours";
lblNowTime.Text = DateTime.Now.ToLongDateString();
lblIISVersion.Text = Request.ServerVariables["SERVER_SOFTWARE"];
lblIsHTTPS.Text = Request.ServerVariables["HTTPS"];
lblPATHS.Text = Request.ServerVariables["PATH_INFO"];
lblPATHS2.Text = Request.ServerVariables["PATH_TRANSLATED"];
lblPORT.Text = Request.ServerVariables["SERVER_PORT"];
lblSessionID.Text = Session.SessionID;

All variables can be viewed on the page IIS Server Variables.

  • i n can use the "Request" pq my application n is web.

  • @psNytrancez I posted the answer aiming at something generic, usually this type of question is for WEB. In any case there is another way with WMI. Another thing I forgot to put in the answer, is this page of the MSDN. It’s about the API reference section for working with IIS 7.

  • This API with II7 also falls into the same scenario of the application not being web.

  • 1

    @psNytrancez I think it does work with this on Desktop.

2


  • 1

    Upovte. If the articles answer the question, I will mark it as an answer! Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.