user1747513 user1747513 - 1 month ago 12 Question

One instance application over multiple Windows user accounts

I have used solution of Mutex to disallow opening more than one instance of my application at the same time

but, when i use Switch User in windows and open another user, and try to open the application, it opened normally and can't detect that it's running on other account

how could i solve something like this and disallow opening the application among Logged in Windows User Accounts

i am using code like this

Dim onlyInstance As Boolean = False
_mutex = New Mutex(True, "Application Name", onlyInstance)
If Not onlyInstance Then
MessageBox.Show("Application is already running.", "Error.")
End If


If you make your mutex global, then it will be visible to all users:

mutexName = String.Format("Global\\{{{0}}}", "Application Name"); 

From the documentation:

A named system mutex can have two levels of visibility. If its name begins with the prefix "Global\", the mutex is visible in all terminal server sessions. If its name begins with the prefix "Local\", the mutex is visible only in the terminal server session where it was created. In that case, a separate mutex with the same name can exist in each of the other terminal server sessions on the server. If you do not specify a prefix when you create a named mutex, it takes the prefix "Local\". Within a terminal server session, two mutexes whose names differ only by their prefixes are separate mutexes, and both are visible to all processes in the terminal server session. That is, the prefix names "Global\" and "Local\" describe the scope of the mutex name relative to terminal server sessions, not relative to processes.