function SetPrivilege:bool;
var
hToken:dword;
tkp:TTOKENPRIVILEGES;
rl:dword;
begin
result:=false;
if OpenProcessToken(GetCurrentProcess,TOKEN_ALL_ACCESS,hToken) then
if LookupPrivilegeValue(nil,'SeDebugPrivilege',tkp.privileges[0].luid) then
begin
tkp.PrivilegeCount:=1;
tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
result:=AdjustTokenPrivileges(hToken,false,tkp,sizeof(tkp),tkp,rl);
end;
end;
function EnumWindowsProc(hWnd:HWND;lParam:lParam):bool;stdcall;
var
lpbuffer:array [0..254] of char;
wText:string;
begin
GetWindowText(hWnd,lpbuffer,255);
wText:=strpas(lpbuffer);
// form1.listbox1.items.add(wText); //listbox里面没发现有啊??
if CompareText(wText,'SAS window')=0 then
begin
hSASWnd:=hWnd;
result:=false;
showmessage('SAS window');
end;
result:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hDesk:dword;
begin
hDesk:=OpenDesktop('Winlogon',0,false,MAXIMUM_ALLOWED);
EnumDesktopWindows(hDesk,@EnumWindowsProc,0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if not setprivilege then
messagebox(handle,'setprivilege error','error',0);
end;