I posted this on several vb forums with no avail so i figure i would post here because i have always gotten better help here than anywhere else.
I have an application on a terminal server that runs for each user as upon login and is intended to always be running for them. The problem i found out was that if they didnt logout and just disconnected then reconnected, another instance of this app would run as well as the currently running one, so on and so forth. I then added this simple code:
That does what i want but it doesnt care about multiple users using the app. It looks and if more than one instance is running for all users then it will end so only one user can use it at any time. I need to check if more than one instance is running per user.Code:Dim Proc As System.Diagnostics.Process If proc.Length > 1 And Environment.UserName = Employee.NTUserName Then MsgBox("Another instance of TimeClock is already running. Terminating.") End End If
Another thing i tried is this:
This code looks like it should do what i want but it doesnt. I fairly recently got thrown into vb programming and for terminal services for that matter so there are lots of extra things i didnt expect like this.Code:Dim processList As System.Diagnostics.Process() Dim thisProc As System.Diagnostics.Process = System.Diagnostics.Process.GetCurrentProcess Dim thisSessionID As Long = thisProc.SessionId processList = System.Diagnostics.Process.GetProcesses() Dim Proc As System.Diagnostics.Process Dim count As Integer = 0 For Each Proc In processList If Proc.SessionId = thisSessionID And Proc.ProcessName = "LSTimeClock.exe" Then count += 1 End If If count > 1 Then MsgBox("There is another instance of LSTimeClock Running") End End If
Any help would rock.
Thx
Mung




Reply With Quote