import ctypes
import ctypes.wintypes
# create variable that will be filled with a token that represents the user
token = ctypes.wintypes.HANDLE()
# 3 is LOGON32_LOGON_NETWORK, 0 is LOGON32_PROVIDER_DEFAULT
if ctypes.windll.advapi32.LogonUserW(u"username", u"domain", u"password", 3, 0, ctypes.byref(token)) == 0:
# failed to login if we get 0
failed_to_login()
# close the handle to avoid leaking it
ctypes.windll.kernel32.CloseHandle(token)
如果您在Linux上工作,那么与Windows ^{} function 大致等价的是^{} ,如
SO_PEERCRED
。(感谢Grawity对超级用户peercred)的介绍。在您可以使用
ctypes
直接调用Windows API:您也可以在失败后调用
^{pr2}$ctypes.windll.kernel32.GetLastError()
,查看错误代码是什么,您可以通过命令提示符中的net helpmsg nnnn
来查找。在相关问题 更多 >
编程相关推荐