CreateEvent from Windows-7 Logon Screen

2019-06-27 19:49发布

问题:

I'm asking this question because it turns out that there's some difficulty in writing a screensaver app in Delphi that's capable of running from the Logon screen.

See question: Windows 7 logon screensaver in Delphi

I've narrowed down the problem (or at least one problem) to a particular Win API call CreateEvent.

SyncEvent := CreateEvent(nil, True, False, '');
if SyncEvent = 0 then
  RaiseLastOSError;

This code only fails if called from the Logon screen. And GetLastError returns that access is denied. So clearly the security restrictions on the Logon screen prevent CreateEvent(nil, True, False, ''); from creating the event as desired.

(I don't really see how an Event could be an exploitable security risk.)

So, the question is: Is it possible to create an Event from the Logon screen? Presumably via either:

  • Using an appropriate lpEventAttributes
  • Or calling CreatingEventEx instead.

Although the problem was experienced in Delphi, this is more about the Win API. So feel free to answer in your language of choice.

回答1:

Try setting the last parameter of CreateEvent() to nil instead of '' . There is a difference between a nil pointer and a pointer to a zero-length string. The documentation does not say anything about a zero- length string being treated any differently than any other named string. So maybe there is another zero-length-named event that exists somewhere else on your machine that your app does not have access to, thus the Access Denied error when CreateEvent() tries to access the existing event and fails. If you want to create an unnamed event, use nil instead.