无论多少用户登录到系统,程序只能运行一个!不要告诉我用Mutex,Mutex对多用户登录是无效的。

解决方案 »

  1.   

    程序只允许运行一个实例,windows系统支持多用户登录同时登录,但我的程序无论多少用户登录,也只允许让它运行一个实例。以前用Mutex来达到运行一个实例的效果,但如果有另一个用户登录系统,其实它仍是可以运行这个程序的。。
      

  2.   

    Mutex怎么会无效?哈哈,没读懂参数使用方法吧,lpName 
    The name of the mutex object. The name is limited to MAX_PATH characters. Name comparison is case sensitive. If lpName matches the name of an existing named mutex object, this function requests the MUTEX_ALL_ACCESS access right. In this case, the bInitialOwner parameter is ignored because it has already been set by the creating process. If the lpMutexAttributes parameter is not NULL, it determines whether the handle can be inherited, but its security-descriptor member is ignored.If lpName is NULL, the mutex object is created without a name.If lpName matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same name space.The name can have a "Global\" or "Local\" prefix to explicitly create the 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. 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.
    The object can be created in a private namespace. For more information, see Object Namespaces.