I am trying to run CPU-Z with Python to save a system report in a text file. This code is calling UAC in Win10, if cmd has no admin rights and then second cmd window opens:
import subprocess
import ctypes
import sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
subprocess.call(['cpuz_x32.exe', '-txt=report'])
else:
# Re-run the program with admin rights
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
When I'm in Python interpreter, 0 is returned. However, there is no report.txt
file created. cpuz_x32.exe
is in the same directory from where I started interpreter.
This was on Windows10. subprocess.call
asked for elevated cmd, so this called UAC.
Then I decided to try this code in one of my WinXP virtual machines. No UAC there. Script runned well. No problems at all. The report.txt file was created. Is this bug in Win10 cmd, subprocess or Python 3.4.3?