from ctypes import *
kernel = windll.kernel32
advapi = windll.advapi32
HANDLE = c_void_p
TOKEN_ADJUST_PRIVILEGES = 0x0020
h_token = HANDLE()
if advapi.OpenProcessToken(kernel.GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES , byref(h_token)):
print("OK")
else:
print("Error:%d" % kernel.GetLastError())
在xp下运行没问题,一放在win7 or win8 下,就会提示错误代码6,无效的句柄
多谢提醒,本来搜到那些直接用VC写的人都是把build的目标改一下就好,然后就以为是静态链接库的问题,搜到这个帖子才恍然大悟,从python到pywin一串工具链都要改成64位的
如果你的系统是WIN7 64位系统,而python装的是32位的,会遇到下面的问题:
调用:DebugActiveProcess(),函数返回0,使用 GetLastError() 返回错误码50, 使用 FormatMessage 处理后显示 “不支持该请求”。
我个人解决方法:
重新安装python,找64位的:
1、下载安装:
http://www.python.or
2、下载安装pywin32-64位
http://jaist.dl.sour
3、安装setuptools
下载:http://peak.telecomm
D:\Python27_64\3rd>..\python.exe ez_setup.py
Downloading http://pypi.python.o
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to d:\python27_64\lib\site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install-script.py script to D:\Python27_64\Scripts
Installing easy_install.exe script to D:\Python27_64\Scripts
Installing easy_install.exe.manifest script to D:\Python27_64\Scripts
Installing easy_install-2.7-script.py script to D:\Python27_64\Scripts
Installing easy_install-2.7.exe script to D:\Python27_64\Scripts
Installing easy_install-2.7.exe.manifest script to D:\Python27_64\Scripts
Installed d:\python27_64\lib\site-packages\setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
3、如果你用到chardet,并安装到python27_64中
D:\Python27_64\3rd\chardet-2.1.1>..\..\python.exe setup.py install
4、配置python26_64到pydev中。
安装完毕,再次以64位lib,建立新项目,运行Ok!
Enter the pid of the process to attach to :4968
pid= 4968
self.h_process: 116
res: 1
debug....
press a key to continue...
[*] Finished debugging ,Exitting ...