static string TryGetPathFromMicrosoftRegister()
{
try {
var regex = new Regex (@"""([^""]*)\\([^""\\]+(?:\.[^"".\\]+))""");
var pythonKey = Registry.ClassesRoot.OpenSubKey (@"Python.File\shell\open\command");
var python = pythonKey.GetValue (null).ToString ();
var match = regex.Match (python);
if (!match.Success) {
return null;
}
var directory = match.Groups [1].Value;
var fullPath = Path.Combine (directory, "pythonw.exe");
ProcessStartInfo info = new ProcessStartInfo (fullPath, "--version");
Process process = new Process ();
process.StartInfo = info;
if (!process.Start () || !process.StandardOutput.ReadLine ().Contains ("Python ")) {
return null;
}
PythonBinaryLocation = fullPath;
return fullPath;
} catch (Exception) {
return null;
}
}