Scripting Question

New to scripting trying to get a basic one to work - Pull Logged in Users with a Custom Inventory Rule

08/30/2019 521 views

Good morning all,

This all comes from needing a way to find out if anyone is currently logged.  I can do this from the command line with:

query user /server:computername

I would like to just make this a custom inventory rule but apparently this will not run as localuser so I was advised to run it as a script, output it to a log then have a custom inventory rule just read the log.

i can run this process manually on my own PC.  First in the CLI I run :

query user > c:\dell\query_user.txt

then from the CLI I run:

notepad.exe c:\dell\query_user.txt

So my question is, how do I setup the first part of this to run (query user /server:computername) to run as a script so I can then run a custom inventory rule to read the log?

Many thanks

0 Comments   [ + ] Show comments


Community Chosen Answer


Hi, Welcome.

Let's do this....

1- Create a BAT file that will run the command output the results into a TXT file, I'm going to named it Query-User.bat

2- Create a new Script (Don't forget to target the computer or use device labels as target, and select your O.S.) and Launch your BAT File Like this:


3- Use a Custom Inventory Rule to read the TXT file and return what's inside:

ShellCommandTextReturn(cmd /c type C:\ProgramData\Quest\Users.txt)

4- Wait for OR Force Inventory on that Computer, and then you should be able to see THIS!


**We have admin, batman and robin currently logged in, robin is the last active user, he logged in one minute after batman**

This is how it looks like from the computer:


Let us know how that goes.

Answered 08/30/2019 by: Channeler
Red Belt

All Answers


You need to remember that the information returned by a custom inventory rule is only updated when the computer runs an inventory update. So your "Current logged in user" will be the user that was logged into the computer when the inventory ran, which is not necessarily who is logged in when you are looking at the data. Also, if you are using a script to output the information and then upload it to the SMA, the data is dependent on when the script ran, so unless you are scheduling the script to run in conjunction with your inventory interval your "Current logged in user" will be even more inaccurate.

In reality, if you really need to know the user that is currently logged into a computer you will have to use a tool that queries that data in real time. I prefer using PSTools' psloggedon, personally.

Answered 09/02/2019 by: chucksteel
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ