Question

I am implementing licensing in our application.

How do I stop user from using the same logon multiple times on a Windows Terminal Server.

Is there a way in Windows Terminal Server to pass a specific parameter to Win32_Process?

If there is any, then I can read from it and do not allow second logon.

Or there has to be something like a central Windows Service, from whom my exe needs to take authentication before starting.

Any suggestions?

Was it helpful?

Solution

The best way to do this is use a global Mutex:

bool owned;
using (var mutex = new Mutex(true, @"Global\SingleUserNameLogon-" + CurrentUserName, out owned))
{
    if (!owned)
    {
        MessageBox.Show("This program can only be run by one person at a time!");
        closeTheForm();
    }

    //Put the rest of your program here
}

This creates a mutex named Global\SingleUserNameLogon-Bhoomi, if the program detects another program already created a mutex with that exact name it will call the closeTheForm() function.

By prefixing the mutex's name with Global\ it will check all sessions on the computer for a mutex with the same name, not just the session the app is running from.

One thing to note is once the mutex is disposed another program can run so you may need to not put the mutex in a using statement and instead keep it as a local variable of your form that you create in the constructor and dispose on close.

OTHER TIPS

After a lot of searching I came up with a Custom Solution.

Solution is like this :

When User opens up the exe, username is appended to the text (Window Title) of the exe, like this :

this.text = CurrentUserName;

When the exe loads it will check all the running processes like this :

    Process[] processlist = Process.GetProcesses();

        foreach (Process theprocess in processlist)
        {
            if (theprocess.ProcessName == "SingleUserNameLogon" || theprocess.ProcessName == "SingleUserNameLogon.exe")
                if(CurrentUserName == theprocess.MainWindowTitle)
                 {
                     closeTheForm();
                 }
        }

This is a custom solution.

Any other elegant solution is welcome.

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