def RunAs(filePath, asAdministrator, *args): sei = SHELLEXECUTEINFO() sei.cbSize = sizeof(SHELLEXECUTEINFO) sei.fMask = (SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS) if asAdministrator: sei.lpVerb = u"runas" else: sei.lpVerb = u"" sei.lpFile = GetUncPathOf(filePath) sei.lpParameters = " ".join( ['"%s"' % arg.replace('"', '""') for arg in args]) sei.nShow = SW_SHOWNORMAL if not ctypes.windll.shell32.ShellExecuteExW(byref(sei)): err = GetLastError() raise WindowsError(err, "ShellExecuteEx: %s" % FormatError(err)) return sei.hProcess
def RunAs(filePath, asAdministrator, *args): sei = SHELLEXECUTEINFO() sei.cbSize = sizeof(SHELLEXECUTEINFO) sei.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS if asAdministrator: sei.lpVerb = u"runas" else: sei.lpVerb = u"" sei.lpFile = GetUncPathOf(filePath) sei.lpParameters = " ".join(['"%s"' % arg.replace('"', '""') for arg in args]) sei.nShow = SW_SHOWNORMAL if not ctypes.windll.shell32.ShellExecuteExW(byref(sei)): err = GetLastError() raise WindowsError(err, "ShellExecuteEx: %s" % FormatError(err)) return sei.hProcess