I can't find the reason to why this should not work:
unit Code;
{$MODE Delphi}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
Windows;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
function IsWow64Process(hProcess: THandle; out Wow64Process: BOOL): BOOL;
external 'kernel32.dll' name 'IsWow64Process';
function IntToHex(dwValue, dwDigits: DWord): String; stdcall;
const
hex: array[0..$F] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
begin
if (dwDigits > 8) then
dwDigits := 8;
Result := Copy(
hex[(dwValue and $F0000000) shr 28]+
hex[(dwValue and $0F000000) shr 24]+
hex[(dwValue and $00F00000) shr 20]+
hex[(dwValue and $000F0000) shr 16]+
hex[(dwValue and $0000F000) shr 12]+
hex[(dwValue and $00000F00) shr 8]+
hex[(dwValue and $000000F0) shr 4]+
hex[(dwValue and $0000000F) shr 0],9-dwDigits,dwDigits);
end;
function EnabledDebugPrivilege(const bEnabled: Boolean):Boolean; //提升权限
var
hToken: THandle;
tp: TOKEN_PRIVILEGES;
a: DWORD;
const
SE_DEBUG_NAME = 'SeDebugPrivilege';
begin
Result:=False;
if (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken)) then
begin
tp.PrivilegeCount :=1;
LookupPrivilegeValue(nil, SE_DEBUG_NAME, tp.Privileges[0].Luid);
if bEnabled then
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
tp.Privileges[0].Attributes := 0;
a:=0;
AdjustTokenPrivileges(hToken, False, @tp, SizeOf(tp), nil, @a);
Result:= GetLastError = ERROR_SUCCESS;
CloseHandle(hToken);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
IsWow64Result: Bool;
ProcessH: THandle;
ProcID: DWORD;
noteh: hwnd;
ThreadId: dword;
begin
EnabledDebugPrivilege(true);
noteh := FindWindow(nil,'Untitled - Notepad');
ThreadId := GetWindowThreadProcessId(noteh,@ProcID);
ProcessH := OpenProcess(PROCESS_ALL_ACCESS, False, ProcID);
IsWow64Process(ProcessH,IsWow64Result);
if(IsWow64Result = true)then
begin
ShowMessage('Yes it is a 64');
end;
end;
initialization
{$I code.lrs}
end.
Yet it does not. Does anyone have a clue?