const
DISABLE_MAX_PRIVILEGE = $1;
function CreateRestrictedToken(ExistingTokenHandle: THandle; Flags: Longword;
DisableSidCount: Longword; var SidToDisable: SID_AND_ATTRIBUTES;
DeletePrivilegeCount: Longword; var PrivilegesToDelete: LUID_AND_ATTRIBUTES;
RestrictedSidCount: Longword; var SidToRestrict: SID_AND_ATTRIBUTES; var NewTokenHandle: THandle): Longword; stdcall; external 'Advapi32.dll' name 'CreateRestrictedToken';
procedure TForm1.Button1Click(Sender: TObject);
var
hToken, hNewToken: THandle;
SidToDisable, SidToRestrict: SID_AND_ATTRIBUTES;
PrivilegesToDelete: LUID_AND_ATTRIBUTES;
SI: STARTUPINFO;
PI: PROCESS_INFORMATION;
begin
OpenProcessToken(GetCurrentProcess, MAXIMUM_ALLOWED, hToken);
CreateRestrictedToken(hToken, DISABLE_MAX_PRIVILEGE, 0, SidToDisable, 0, PrivilegesToDelete, 0, SidToRestrict, hNewToken);
if ImpersonateLoggedOnUser(hNewToken) then
begin
ZeroMemory(@SI, SizeOf(SI));
SI.cb:= SizeOf(SI);
CreateProcessAsUser(hNewToken, PChar(Application.ExeName), '', nil, nil, False,
CREATE_DEFAULT_ERROR_MODE, nil, nil, SI, PI);
RevertToSelf;
end;
end;