How to programmatically determine installed IIS version

后端 未结 6 2000
别那么骄傲
别那么骄傲 2021-01-17 20:27

What would the preferred way of programmatically determining which the currently installed version of Microsoft Internet Information Services (IIS) is?

I know that i

6条回答
  •  没有蜡笔的小新
    2021-01-17 20:44

    To identify the version from outside the IIS process, one possibility is like below...

    string w3wpPath = Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.System), 
        @"inetsrv\w3wp.exe");
    FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(w3wpPath);
    Console.WriteLine(versionInfo.FileMajorPart);
    

    To identify it from within the worker process at runtime...

    using (Process process = Process.GetCurrentProcess())
    {
        using (ProcessModule mainModule = process.MainModule)
        {
            // main module would be w3wp
            int version = mainModule.FileVersionInfo.FileMajorPart
        }
    }
    

提交回复
热议问题