我想运行一个特定的cmd代码,只有在以管理员权限运行cmd时才能执行该代码。
这是我的代码:
SELECT c.CompanyName, c.CompanyCity
FROM UserCompany AS uc
JOIN Company AS c ON c.CompanyId = uc.CompanyId
WHERE uc.UserId = 1
runas命令将弹出UAC。我希望此import ctypes, sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
print "Admin success"
else:
# Re-run the program with admin rights
ctypes.windll.shell32.ShellExecuteW(None, u'runas',unicode('cmd.exe'),"REG ADD 'HKLM\SOFTWARE\Microsoft\Microsoft Antimalware\Exclusions\Paths' /v 'C:\MyFolderwithNoSpaces' /t REG_DWORD /d 0 /f/c ", None, 1)
在Windows中以管理员权限运行。请帮我纠正代码或建议更好的语法。