/build/static/layout/Breadcrumb_cap_w.png

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

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

Answers (2)

Posted by: Channeler 4 years ago
Red Belt
4

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
IuwUAAACA+EgMDw+Lu1JhYeHp06f37NnT29u7du1a8ex4VVxcLO5FKpFIiHsAAAC5IJVKiXsA+Q15twAAAAAQH8i7tUe+AQMAAOQQcQIDyHvIuwUAAACA+MB8twAAAAAQH8i7BQAAAID4QN4tAAAAAMQH8m4BAAAAID6QdwsAAAAA8YG8WwAAAACID+TdAgAAAEB8IO8WAAAAAOIDebcAAAAAEBea9v8BGw6CpKMIB9sAAAAASUVORK5CYII=



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:

+f8DHd1LclfHuZMAAAAASUVORK5CYII=


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

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!

v+2O0vXlnoZkAAAAABJRU5ErkJggg==

**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:

fwUmDuInqOxFAAAAAElFTkSuQmCC


Let us know how that goes.

Posted by: chucksteel 4 years ago
Red Belt
2

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.

 
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