#include <windows.h>
#include <iostream.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
char ClassBuf[128];
GetWindowText(hwnd,ClassBuf,sizeof(ClassBuf));
HWND h=FindWindow(NULL,"SAS window");
if(h==hwnd)
{
cout<<"win"<<endl;
return false;
}
return true;
}
void main()
{
//获得SeDeDebug权限-----------------
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;
//
if (! OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_READ, &hToken ) )
return;
if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){
CloseHandle( hToken );
return;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
CloseHandle( hToken );
//------------------------------------
//
HDESK hDesk=NULL;
hDesk = OpenDesktop("Winlogon",0,false,MAXIMUM_ALLOWED); //这一句显示拒绝访问 ,操作没有成功.
EnumDesktopWindows(hDesk,(WNDENUMPROC)EnumWindowsProc,0);
HWND h=FindWindow(NULL,"SAS window");
if(h==NULL)
cout<<"failed"<<endl;
}
我想使该程序能够访问桌面,得到"SAS window"的句柄,但是debug时显示"拒绝访问",不知问题出在那
,大家帮帮忙!!