winapi - using WIN32 API CreateProcessAsUser in Python -
i have been trying find example of how use createprocessasuser() win32 api in python along side logonuser() api, no avail.
any on appreciated.
first, should know python extensions windows api closely mapped windows api. in use case, following links should prove useful you:
# discusses logonuser() function http://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx # discusses createprocessasuser() function http://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx # discusses startupinfo structure http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
if study these documents pywin documentation, you'll learn quite ton.
that being written, note in order use createprocessasuser(), must hold privilege se_increase_quota_name, , possibly se_assignprimarytoken_name. these can assigned on local workstation (assuming you're admin) via secpol.msc > user rights assignment.
to understand how these privileges map rights shown in secpol.msc, use link:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx
now on code:
# first create token. we're pretending user exists on local computer or active directory domain. user = "ltorvalds" pword = "iamlinuxman" domain = "." # means current domain logontype = win32con.logon32_logon_interactive provider = win32con.logon32_provider_winnt50 token = win32security.logonuser(user, domain, pword , logontype, provider) # let's create startupinfo structure. read link above more info on these can do. startup = win32process.startupinfo() # finally, create cmd.exe process using "ltorvalds" token. appname = "c:\\windows\\system32\\cmd.exe" priority = win32con.normal_priority_class win32process.createprocessasuser(token, appname, none, none, none, true, priority, none, none, startup)
hope helps.
Comments
Post a Comment