Not sure about what you mean by "... the application didn't compile..." . As indicated before, the API call you've indicated as having a trouble is correct here.
For instance, this is OK for the compilation (though not working properly - you need to initialize the concerned variables first):
uses windows, jwawindows;
var DLog: TextFile;
procedure test;
var UserToken, newToken: HANDLE;
var tokenAttributes: SECURITY_ATTRIBUTES;
begin
If Not DuplicateTokenEx(UserToken, MAXIMUM_ALLOWED, @tokenAttributes, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, TOKEN_TYPE.TokenImpersonation, newToken) then
begin
Writeln(DLog, 'Failed to duplicate security token');
end;
end;
Anyway, I don't want to be negative, but I'm not sure this method is the right choice.
I don't know it, neither the concerned API calls, but:
-as spotted before, this method won't work in Windows XP (and you've indicated it, in one of your previous post). At least, if might work, but with a different code,
-I'm not even sure it will be working as this in Windows 8 (and further). With their new "Modern UI" interface activated by default, it's quite possible that the logon process has changed; and so that it won't work exactly as for Vista/Windows 7,
-elevating the privileges like this (logon process), and for a non essential application, seems to be quite dangerous to me. Because of the possible security issues, Microsoft could feel the same in the future; and so, forbid it (or change it).
Considering what you are trying to do (i.e. displaying infos in the screen), what about a screen saver ?
It's certainly not perfect, but at least it should be quite easy to make one. Furthermore you can have a different one in the logon than the one for the windows user(s), and with a different delay (as a short one, for instance, let's say 10 seconds). And it seems it's still working the same in Windows 7 (Ref:
http://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/no-screen-saver-at-windows-7-welcomelog-in-screen/a437ee54-6f7f-48fd-8413-7338480948d8 ).
A test should be done before (i.e. as a proof of concept), on various windows versions. Plus it's possible it's not working with Windows 8 (because of the Modern UI), but I guess a simple try could be easy.