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.