CreateEvent( NULL, FALSE, FALSE, "Global\\CSAPP" );
OpenEvent( EVENT_ALL_ACCESS, FALSE, "Global\\CSAPP" );
同理:Mutex,Semaphore,Waitable timer,Job等也会有同样问题。详细参考msdn.
参考文献:
1. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=980340&SiteID=1
->
Hi Everyone:
i have a application and a service(which run on LocalSystem),the service will a Create a gloable Event, and App will Open this Event. It seems ok on NT/XP, but on vista, when App Open this Event, it will return handle NULL. this is why? Thanks
answer:The corresponding error code (from GetLastError() right after the failing OpenEvent) would be most useful in confirming this but:
If it's 5, it's likely that the event is not ACLed properly so that it can be opened with the access required by the application (which probaly ran as admin on XP, and not anymore in Vista).
If it's 2, it's likely that the application doesn't specify Global\ when calling OpenEvent (on XP, applications often run in session 0, and on Vista, they never do).
2. msdn
HANDLE WINAPI OpenEvent(
DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCTSTR lpName
);
Terminal Services: The name can have a "Global\" or "Local\" prefix to explicitly open an object in the global or session name space. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces .
Windows XP Home Edition: Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
Windows 2000: If Terminal Services is not running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.
Windows NT: The name can contain any character except the backslash character.
Windows Me/98/95: The name can contain any character except the backslash character. The empty string ("") is a valid object name.
Client | Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95. |
---|---|
Server | Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server. |
Header |
Declared in Winbase.h; include Windows.h.
|
Library |
Use Kernel32.lib.
|
DLL | Requires Kernel32.dll. |
Unicode |
Implemented as
OpenEventW (Unicode) and
OpenEventA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
|