This is a problem that I encountered in my daily work. I post this question on the 优快云 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.
本文介绍了一种使用C#语言结合cscript.exe和adsutil.vbs脚本获取IIS中脚本映射配置及.NET运行时版本的方法。通过执行特定命令并解析输出结果来确定IIS上的.NET运行时版本。
2360

被折叠的 条评论
为什么被折叠?



