在Python中使用WIN32 API CreateProcessAsUser [英] using WIN32 API CreateProcessAsUser in Python

查看:512
本文介绍了在Python中使用WIN32 API CreateProcessAsUser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找一个很好的示例,说明如何在Python中与LogonUser()API一起使用CreateProcessAsUser()WIN32 API,但无济于事。

I have been trying to find a good example of how to use the CreateProcessAsUser() WIN32 API in Python along side the LogonUser() API, but to no avail.

在此方面的任何帮助将不胜感激。

Any help on this would be greatly appreciated.

推荐答案

首先,您应该知道Windows API的Python扩展非常紧密映射到Windows API。在这种用例中,以下链接应该对您非常有用:

First, you should know that the Python extensions for Windows API is closely mapped to the Windows API. In this use case, the following links should prove very useful to you:


  • 讨论LogonUser()函数

    • Discusses LogonUser() function
      • http://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx
      • http://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx
      • http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx

      如果您研究这些cupy和pywin文档一起,您将学到很多东西。

      If you study these documents together with the pywin documentation, you'll learn quite a ton.

      在编写时,请注意,要使用CreateProcessAsUser(),必须拥有特权 SE_INCREASE_QUOTA_NAME ,可能还 SE_ASSIGNPRIMARYTOKEN_NAME 。可以通过secpol.msc>用户权限分配在本地工作站上分配这些权限(假设您是管理员)。

      That being written, note that in order to use CreateProcessAsUser(), you must hold the privilege SE_INCREASE_QUOTA_NAME, and possibly SE_ASSIGNPRIMARYTOKEN_NAME. These can be assigned on your local workstation (assuming you're admin) via secpol.msc > User Rights Assignment.

      了解这些特权如何映射到secpol中显示的权限.msc,请使用以下链接:

      To understand how these privileges map to rights shown in secpol.msc, use this link:

      • http://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx

      现在转到代码:

      # First create a token. We're pretending this user actually exists on your 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)
      
      # Now let's create the STARTUPINFO structure. Read the link above for more info on what these can do.
      startup = win32process.STARTUPINFO()
      
      # Finally, create a cmd.exe process using the "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)
      

      希望这会有所帮助。

      这篇关于在Python中使用WIN32 API CreateProcessAsUser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆