1

I have a Windows Server 2008 box. I have run, as administrator, in powershell Set-ExecutionPolicy Unrestricted. When I run powershell Get-ExecutionPolicy, it returns Unrestricted.

I have created a .bat file which exhibits the issue I am seeing. The .bat file, test.bat, is only one line, powershell Get-ExecutionPolicy. When I open command prompt and run test.bat, "Unrestricted" is printed to the screen.

If I run the following python script however,

import subprocess
subprocess.Popen("test.bat")

"Restricted" is printed to the screen. How is this setting different when being run from Python's subprocess.Popen? I am not seeing the issue on a Windows 7 machine I have, where I have performed an identical workflow.

smileBot
  • 18,797
  • 7
  • 60
  • 62
ptnapoleon
  • 78
  • 1
  • 4
  • 2
    I found the answer. The Unrestricted ExecutionPolicy was for the 64-bit version of powershell. Python ends up calling the 32-bit version, which I had not set. Windows Server 2008 includes two versions of powershell, but Windows 7 does not. Please see: http://stackoverflow.com/questions/4037939/powershell-execution-of-scripts-is-disabled-on-this-system?rq=1 for more details – ptnapoleon Jun 05 '14 at 18:31
  • You can put that as an answer, and later accept it. – Adil Hindistan Jun 05 '14 at 18:40
  • Yeah, but I had to wait 8 hours because my rep was too low. – ptnapoleon Jun 06 '14 at 19:34

2 Answers2

1

I found the answer. The Unrestricted ExecutionPolicy was for the 64-bit version of powershell. Python ends up calling the 32-bit version, which I had not set. Windows Server 2008 includes two versions of powershell, but Windows 7 does not.

Please see: PowerShell says "execution of scripts is disabled on this system." for more details

Community
  • 1
  • 1
ptnapoleon
  • 78
  • 1
  • 4
0

run following code in powershell as administrator

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned