Nothing returned when using 32 bit Python os.popen on a 64 Bit Windows 7 System
I am trying to use the following commands to run a check for bitlocker encryption on a 64 Bit Windows 7 system:
import os
os.popen('C:\Windows\System32\manage-bde.exe -status c:').read()
and it returns '' (nothing).
I have also tried to use subprocess.Popen with the same results.
This is a 32 bit version of Python 2.6.6 running on a 64 bit Windows 7 machine. When I use a 64 bit version of Python, both os.popen and subprocess.Popen work, but I am unable to use 64 bit Python as I have many 32 bit systems to support and py2exe will not support 开发者_如何转开发bundling on a 64 bit platform.
Does anyone know if I can get either subprocess.Popen or os.popen to work on a 64 bit Windows system using a 32 bit version of Python? I am not sure where I am going wrong.
Alternately, if anyone knows how I can check for full bitlocker encryption on a Windows 7 system without the benefit of using manage-bde.exe, I would appreciate it.
manage-bde.exe is in the "real" System32 directory. 32 Bit applications are automatically redirected to %windir%\SysWOW64, when they try to access it. You can access it via the SysNative alias:
import os
os.popen(r'C:\Windows\SysNative\manage-bde.exe -status c:').read()
Parsing the output of manage-bde is kind of hacky. The output format could easily change in future Windows releases and your script would break.
The cleaner, more maintainable alternative would be to use the BitLocker WMI Provider, Win32_EncryptableVolume. Specifically, the GetProtectionStatus method.
As it was already pointed you can access 64-bit applications from "real" System32 directory via the Sysnative alias (i.e. %windir%\Sysnative). But please note that %windir%\Sysnative is defined only for 32 bit applications and is not valid for 64 bit ones: "64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one" (link).
精彩评论