Question

I have a program on a remote server that I access via remote desktop and I was wondering if there is any way to restrict the program to be used by one user at a given moment?

For instance while user A is using the program, I want to prevent users B,C,etc.. from running it.

Was it helpful?

Solution

Check out this answer

.NET Check if another application is running

Here is an example of one approach (VB.NET):

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) Then Close()
End Sub

Though in researching this, it seems that using a Mutex is a better approach, albeit a much more complicated one, because it's possible that, using the simple approach exemplified above, you could run into trouble if more than one of your processes has the same name. This seems to be one of the definitive q&a's on the topic:

What is a good pattern for using a Global Mutex in C#?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top