你可以使用包含在Pywin32扩展中的ShellExecuteEx Win32 API包装器来实现此操作。如果你正在使用类似ActivePython的东西,你可能已经拥有了这些扩展。要使用ShellExecuteEx:import win32com.shell.shell as shell commands = 'echo hi' shell.ShellExecuteEx(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c '+commands)
runas
命令。例如,参见 此处。如果在 shell 中输入密码不是一个选项,则参见 此处。 - hlt