如何使用C# 获取IIS 运行framework 版本

This is a problem that I encountered in my daily work. I post this question on the CSDN forum, but nobody answers it these day. Because it's an urgent work, I solve it my self.

 

The solution is

  1. Use the "cscript.exe" and "adsutil.vbs" to get the script mapping of the IIS.

  2. Use the Csharp language to integrate the "command window operation" into my CSharp app, which return with  the runtime version .

 

Here's the code block ...

 

 //Process configuration

            Process myProcess = new Process();

            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cscript.exe", @"c:/Inetpub/AdminScripts/adsutil.vbs get w3svc/ScriptMaps");

            myProcessStartInfo.UseShellExecute = false;

            myProcessStartInfo.RedirectStandardOutput = true;

            myProcess.StartInfo = myProcessStartInfo;

           

            //Process work

            myProcess.Start();

            StreamReader myStreamReader = myProcess.StandardOutput;          

            string output = myStreamReader.ReadToEnd();

            myProcess.WaitForExit();

 

            //String work

            //Restruction:

            //  1. This can work on 2.0 and 4.0 whose version is length of 10

            //  2. Only one runtime is registered, done with aspnet_regiis on IIS.

            String runtimePath = String.Empty;

            if (output.Contains(@"Microsoft.NET/Framework64"))

        {

                        runtimePath = @"Microsoft.NET/Framework64/";

        }

            else

        {

                runtimePath = @"Microsoft.NET/Framework/";

        }

 

            int runtimeIndex = output.IndexOf("v", output.IndexOf(runtimePath));

            String version = output.Substring(runtimeIndex, 10);

 

This code is not that perfect. If you have any suggestion. PLS contact with me.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值