I want to write a C# method like
public bool PowershellExists() { // Returns true if PowerShell exists on the machine, else false. } I want to write a C# method like
public bool PowershellExists() { // Returns true if PowerShell exists on the machine, else false. } Using the MSDN blog post Detection logic for PowerShell installation, I have written the method like:
public bool PowershellExists() { string regval = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1", "Install", null).ToString(); if (regval.Equals("1")) return true; else return false; }
Registry.GetValue