LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Windows User Connection Status for Local AND Remote Users

Solved!
Go to solution

Hello,

 

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.

0 Kudos
Message 1 of 12
(1,161 Views)

Ooh ooh ooh I know this one.

 

Go to

 

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.

0 Kudos
Message 2 of 12
(1,152 Views)

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.

0 Kudos
Message 3 of 12
(1,140 Views)

 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

 

QUERY\sUSER

 

With what ever case you used.

0 Kudos
Message 4 of 12
(1,122 Views)

Here is a snippet of the block diagram and output, with \ codes visible. All I get returned is the "More?" when executing this.

 

StevoP80_0-1695920054022.png

 

0 Kudos
Message 5 of 12
(1,110 Views)

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.

0 Kudos
Message 6 of 12
(1,099 Views)

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.

0 Kudos
Message 7 of 12
(1,087 Views)

Here is the error when I try that.

StevoP80_0-1695923630182.png

 

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.

0 Kudos
Message 8 of 12
(1,081 Views)

I followed the steps in this article:

LabVIEW: (Hex 0x2) Memory is Full When Using the System Exec VI - NI

 

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.

 

StevoP80_0-1695924860014.png

 

 

Anyone know how to make the query command work with System Exec vi?

0 Kudos
Message 9 of 12
(1,068 Views)

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.

 

0 Kudos
Message 10 of 12
(1,049 Views)