5

I want to write a C# method like

public bool PowershellExists() { // Returns true if PowerShell exists on the machine, else false. } 
4
  • blogs.msdn.com/b/powershell/archive/2009/06/25/… + Registry.GetValue Commented Apr 30, 2014 at 4:04
  • 1
    Yeah got that, but I meant for a C# method. Commented Apr 30, 2014 at 4:05
  • 3
    Checking the registry is a C# method. StackOverflow is not a tool for turning documentation into code. If you don't understand registry or how to access it, you should research that. Commented Apr 30, 2014 at 4:06
  • So it's not about it not using? Commented Jan 3, 2016 at 6:25

1 Answer 1

9

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; } 
Sign up to request clarification or add additional context in comments.

2 Comments

can it also tell the Version ? or can we modify it to somehow get the Version Info ?
@N.K if you follow the link there is another key that let you know the version : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine - in more recent version, you can look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.