1

I want to disable/enable powershell with reg key (if it is possible) to execute in cmd

For example. If I want to disable/enable WSH, simply i run in cmd with privileged:

:: Disable WSH
reg add "HKLM\Software\Microsoft\Windows Script Host\Settings" /v Enabled /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows Script Host\Settings" /v Enabled /t REG_DWORD /d 0 /f
:: Restore WSH
reg add "HKLM\Software\Microsoft\Windows Script Host\Settings" /v Enabled /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows Script Host\Settings" /v Enabled /t REG_DWORD /d 1 /f

How do I do this to disable/enable Powershell? (in Windows XP/7/8/8.1/10 x86 x64)

Thanks

BrianC
  • 149
  • 1
  • 2
  • 9
  • See [PowerShell says "execution of scripts is disabled on this system."](http://stackoverflow.com/a/26955050) – wOxxOm Sep 02 '16 at 16:14
  • excuse me, I saw the link and do not understand and I'm not sure that relates to my question, and my question is off powershell from cmd with a key reg It could be more specific and describe the procedure. Thank you – BrianC Sep 02 '16 at 17:15
  • It shows and explains possible values for PS execution policy. There are easily googlable registry/GPO examples: [1](https://codelucidate.wordpress.com/powershell/change-execution-policy-in-the-registry/), [2](http://www.techrepublic.com/blog/the-enterprise-cloud/set-the-powershell-execution-policy-via-group-policy/). – wOxxOm Sep 02 '16 at 17:19
  • I have changed the registry key to "restricted" (privileges) and does not work. Powershell continuous running – BrianC Sep 02 '16 at 17:38
  • I restarted the PC and nothing. Powershell still running with the key "restricted" (Windows 7x64) (reg add "HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v ExecutionPolicy /t REG_SZ /d Restricted /f) – BrianC Sep 02 '16 at 17:45
  • Thanks anyway for your help. – BrianC Sep 02 '16 at 17:47
  • AppLocker would be another viable option to blacklist/whitelist the applications that are allowed on a system. – Booga Roo Sep 02 '16 at 19:28
  • Please don't edit the answer into your question. [so] is a question and answer site and answers should be separate from questions. You can [answer your own question](http://stackoverflow/help/self-answer) instead. – DavidPostill Sep 02 '16 at 19:33
  • Hi davidPostill. This is a Partially solved. Not a complete solved. only applies for Windows 7. In i need to work with any Windows (XP/7/8/8.1/10) – BrianC Sep 02 '16 at 19:35

2 Answers2

1

Unlike WSH there does not exist a single registry key to prevent running PowerShell. It's significantly more complicated since PowerShell is both a scripting language and a shell. Also Execution Policy is only for scripts.

AppLocker or Software Restriction Policies would be most of what you are looking for (if you are looking to stop the opening of powershell.exe or ISE in interactive mode)

BenH
  • 9,766
  • 1
  • 22
  • 35
0

If you wanted to disable script execution via GPO, this is the registry key that would be created on the workstation.

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell]
"EnableScripts"=dword:00000000
Randy Schuman
  • 357
  • 1
  • 9