Created
September 22, 2018 03:21
-
-
Save GhostofGoes/87ad972e36256f06fd8e5b8acaa4bfdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
PY2 = sys.version_info[0] == 2 | |
if PY2: | |
import _winreg as winreg | |
else: | |
import winreg | |
try: | |
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) | |
ps_key = winreg.OpenKey(reg, r'SOFTWARE\Microsoft\PowerShell') | |
except OSError: | |
return None | |
ps_location = None | |
for version in [3, 1]: | |
ver_path = str(version) + r'\PowerShellEngine' | |
try: | |
ver_key = winreg.OpenKey(ps_key, ver_path) | |
ps_location = winreg.QueryValueEx(ver_key, 'ApplicationBase')[0] | |
except OSError: | |
continue | |
if not ps_location: | |
return None | |
ps_path = os.path.join(ps_location, 'powershell.exe') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment