昨天在两个Application之间使用Event之间使用Event,在Windows 7和 Vista下面会出现接收不到Event的现象。在网络上面查找了一下发现,必须在创建的Event名字前面加关键字“Global” 。在winXP以后的系统中,服务都运行在section之中,但到了vista之后,对服务之间的权限管理更加严格。所以出现了上面的问题。下面是NSDN中的解释:
Kernel Object Name Spaces
A Terminal Services server has multiple namespaces for the following named kernel objects: events, semaphores, mutexes, waitable timers, file-mapping objects, and job objects. There is a global namespace used primarily by services such as client/server applications. In addition, each client session has a separate namespace for these objects. Note that this differs from the standard Windows environment in which all processes and services share a single namespace for these objects.
The separate client session namespaces enable multiple clients to run the same applications without interfering with each other. For processes started under a client session, the system uses the session namespace by default. However, these processes can use the global namespace by prepending the "Global/" prefix to the object name. For example, the following code calls CreateEvent and creates an event object named CSAPP in the global namespace:
[C++]
CreateEvent( NULL, FALSE, FALSE, "Global//CSAPP" );
Service applications in a Terminal Services environment use the global namespace by default. Processes started under session zero (typically the console session) also use the global namespace by default. The global namespace enables processes on multiple client sessions to communicate with a service application or with the console session. For example, a client/server application might use a mutex object for synchronization. The server component running as a service can create the mutex object in the global namespace. Then the client component running as a process running under a client session can use the "Global/" prefix to open the mutex object.
Another use of the global namespace is for applications that use named objects to detect that there is already an instance of the application running in the system across all sessions. This named object must be created or opened in the global namespace instead of the per-session namespace. Note that the more common case of running the application once per session is supported by default since the named object is created in a per session namespace.
Client processes can also use the "Local/" prefix to explicitly create an object in their session namespace.
The "Local", "Global" and "Session" prefixes are reserved for system use and should not be used as names for kernel objects. These keywords are case sensitive. On Windows 2000 without Terminal Services, these keywords are ignored. On Windows NT 4.0 without Terminal Services, and earlier versions of Windows NT, the functions for creating or opening these objects fail if you specify a name containing the backslash character (/).