-
Apr 18th, 2018, 07:42 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Check whether application is running for another user
I have an application that establishes connections to several hardware devices. Sometimes users will leave the application open and abandon the PC. Eventually the lockout screen appears and a new user comes along and logs in and launches another instance of the application. However, attempts to establish connections to the hardware devices fail with the new instance as the connection established by the existing instance is blocking ports etc. The devices only allow one instance of the application to connect.
Is there a way of detecting whether another instance of the application is active via another logged-on user?
Perhaps the application could require a machine reboot if another instance were to be detected.
-
Apr 18th, 2018, 08:16 AM
#2
Re: Check whether application is running for another user
I'm not 100% sure but I think that Process.GetProcessesByName can get processes for all users if the current user is an admin. If they're not then they shouldn't be able to get info about other user's anyway. I think that it should be possible to detect the computer locking so could you not have the application clean up when that happens, so it will not monopolise resources if that session isn't active?
-
Apr 18th, 2018, 09:03 AM
#3
Re: Check whether application is running for another user
Will this always run fro the same machine or are there several machines competing for the same set of devices?
Why not just catch the exceptions when trying to connect the second (blocked) session?
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Apr 18th, 2018, 11:18 PM
#4
Thread Starter
Frenzied Member
Re: Check whether application is running for another user
Originally Posted by jmcilhinney
I'm not 100% sure but I think that Process.GetProcessesByName can get processes for all users if the current user is an admin. If they're not then they shouldn't be able to get info about other user's anyway. I think that it should be possible to detect the computer locking so could you not have the application clean up when that happens, so it will not monopolise resources if that session isn't active?
Users will generally be standard users. I don't require information about any other particular user per se but rather whether the PC is running another instance of the application via another user's account.
Are you saying that it might be possible for the application to detect the PC locking and close itself down when this event is detected?
-
Apr 18th, 2018, 11:26 PM
#5
Thread Starter
Frenzied Member
Re: Check whether application is running for another user
Originally Posted by FunkyDexter
Will this always run fro the same machine or are there several machines competing for the same set of devices?
There may be several machines accessing the one database but each machine will have its own set of hardware devices to connect to.
Originally Posted by FunkyDexter
Why not just catch the exceptions when trying to connect the second (blocked) session?
I am trying to avoid this kind of inefficiency. I would prefer a solution which involves avoiding the exception in the first place. Also there could be other reasons for the same exception which may require some kind of support team intervention. Ideally I would like to detect whether another instance is running and suggest a reboot or (even better) close the application when a PC lock event is detected.
-
Apr 18th, 2018, 11:51 PM
#6
Re: Check whether application is running for another user
Originally Posted by robertx
Are you saying that it might be possible for the application to detect the PC locking and close itself down when this event is detected?
I just searched the web for "vb.net detect locking windows" and this was the first result:
https://code.msdn.microsoft.com/wind...State-b6704e7a
I haven't looked closely so I'm not sure but it seems like it might be useful.
-
Apr 19th, 2018, 12:45 AM
#7
Thread Starter
Frenzied Member
Re: Check whether application is running for another user
Originally Posted by jmcilhinney
Whilst the sample application in this link is not coded in a thread-safe manner, it nevertheless demonstrates how to detect that the current Windows session has been locked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|