I work in a testing environment where we can have local and remote users logging into Windows based test machines. I have developed a hardware monitor for some of our test benches but have run into a problem when a user gets disconnected by another user trying to log onto the system. My companies policy is not to log off users when another user attempts to log in, but instead leave them logged in but "disconnected", which leaves all applications and such running in the background. My hardware monitor is launched for each user session when they log in, and if multiple users have logged in (one active, 1+ "disconnected") then there can be potential conflicts with the hardware monitor that is able to send commands automatically to the test hardware because each user has a copy running. What I would like to do is monitor Windows user login status and if the user has a status of "disconnected" then I would park the hardware monitor into an idle state until it detects the user account is active again, and only have the instance for the active user actually monitoring and controlling hardware. This would prevent conflicts from multiple users with the hardware monitor running.
I looked into making group policies to force the disconnected users to log off after a set time, but we have instances where people may legitimately need to stay in a disconnected status and not get logged out by force, so unfortunately that won't work for me.
I need the status of people logging in locally in person, and for remote users. I think this could possibly be done with Windows command line using "query user" and parsing out user name and status, but have not been able to get this to work using System Exec.vi. This info is also available in task manager from the users tab, but do not know how to access this info from within LabVIEW.
Any help getting pointed in the right direction would be greatly appreciated.
Solved! Go to Solution.
Ooh ooh ooh I know this one.
Connectivity -> Libraries and executables -> System Exec
This is like sitting in a cmd window.
Put in the command "query user" without the quotes. It will return something like this:
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
>username console 1 Active none 9/28/2023 8:14 AM
With lots of extra spaces between the words and a \r\n at the end of each line.
You can also use that subVI to do anything that your normally do in a command line. It will pop up a cmd window when it works. There might be a way to suppress that feature.
Thanks for the reply!
When I open cmd prompt from Windows and type the command it works as intended. When I run the command within LabVIEW using the System Exec vi nothing happens.
The string that I put into my answer came from a vi where I tested it.
You can not put a carriage return (\n or \r) after "Query user" That came up with an error when I tried it. Turn on slash codes and check. It should show
With what ever case you used.
Here is a snippet of the block diagram and output, with \ codes visible. All I get returned is the "More?" when executing this.
If I let System Exec vi launch a cmd window with no commands, and then I manually type "query user" into the console that was opened by System Exec, I get an error on the console stating "query" is not recognized as an internal or external command.
So there is something different about the cmd window launched by System Exec versus the one Windows launches. The Windows launched console recognizes it as a valid command and works as intended. The System Exec launched console does not.
No idea whats happening here.
Change the string with "cmd" in it to "query user"
Delete the string constant that currently has query\suser in it.
The reply on the standard output indicator should be what you are looking for. At least that is the way that it worked for me. I have used this vi for a number of applications that way.
Here is the error when I try that.
I am guessing the memory full error is somewhat generic because this machine has 64GB of RAM and is nowhere near full. Not sure what the No Listeners on GPIB is. Searching the error has not been very helpful.
I followed the steps in this article:
When making the command "cmd /c query user" it seems to be working now, but only that it returns the error stating query is not a recognized command, same as typing it manually into the console opened by System Exec vi.
Anyone know how to make the query command work with System Exec vi?
leave cmd\sc\s stuff off just type in what you would type in on the command line window
"query user" in slash code "query\suser"
I tried it with all of the logical inputs and did not get any errors but I did not get an output when I made wait until completion false.
If I typed in the slash codes into a regular text box it did not give me an output but did not error.