# Possibility to have Batch file created to show logged on user on a remote Computer



## PoddyMcQ (Dec 14, 2010)

Hi

So here is my problem.

In work we get a number of calls from users getting various errors from password faults to corrupt Hard Drives.

What im looking to do in particular is have a BAT file created that will show who is currently logged on to a remote Computer.

The problem is that most of the Admin/Techy's have Limited accounts (no right click, no access to local Drive etc) i am one of 4 advanced users (out of 23 in an office) who have extra privilages compared to the rest of the office.

The OS used in work is Vista Enterprise SP2

I have tried creating BAT files that use nbtstat, but this doesn't retrive the info i need.

any help would be apreciated.

Thanks


----------



## TheOutcaste (Aug 8, 2007)

```
wmic /NODE:"ComputerName" computersystem get Username
```
If needed, you can specify a username and Password:

```
wmic /NODE:"ComputerName" /User:Administrator /Password:password computersystem get Username
```
If the Windows Firewall is on, you have to enable remote Admoinistration. You can do that by running this command on each system:

```
netsh firewall set service RemoteAdmin enable
```
you can also use WMI in a VBScript, here's one example:
How to get the logged on user with WMI (VBScript)


----------



## PoddyMcQ (Dec 14, 2010)

so the code you've given there will allow me to enter the name of a computer and it will tell me whos logged on? even with a restricted account?


----------



## TheOutcaste (Aug 8, 2007)

The account running the code would have to be granted rights for WMI monitoring. Best to run it from an Admin Account, or you can specify an admin account in the command itself. Downside to that is the password is in plain text.

Her's some info on setting permissions:
Enable WMI for Remote Monitoring


----------



## TheOutcaste (Aug 8, 2007)

I'll have to double check against a Vista System, see if UAC causes any issues.
Seems to work on my Win 7 system with UAC turned on. Accessing it from an XP system.
Win 7's UAC is a bit more lenient than Vista though.


----------



## Ent (Apr 11, 2009)

> Win 7's UAC is a bit more lenient than Vista though.


What setting is it on? I understand that the highest Win 7 slider position is equivalent to having Vista UAC on.


----------



## TheOutcaste (Aug 8, 2007)

Is you network setup as a Domain, or as just a Workgroup?

For this to work with Vista in a Workgroup, you may have to turn off UAC, or modify permissions to allow access.
See this article:
User Account Control and WMI

If on a domain, it shouldn't be a problem according to that same artivle:


> If your computer is part of a domain, connect to the target computer using a domain account that is in the local Administrators group of the remote computer.


I tried it on a Vista Ultimate PC not in a Domain, and had to turn off UAC for both the VBScript or the WMIC command to work.


----------



## PoddyMcQ (Dec 14, 2010)

Don't mean to sound cheeky or ungratefull at the help provided, but

what i'm looking for is a script that will run in CMD and check who the localy logged on user on a remote Computer on a domain.

I'd like it if this could work using a standard account, as getting another 20 or so accounts to be granted Admin privilages wont happen (i work on a customer site)

i know of a script called psloggedon, which does exactly as i ask but because it isn't a local program on the computer the client will not approve the installation of it.


----------



## valis (Sep 24, 2004)

have you tried the qwinsta command? Are you trying to hit a bunch of machines at once, or are you just trying to find out who is logged onto a particular rig in the domain?

If the latter, qwinsta should do the trick.


----------



## PoddyMcQ (Dec 14, 2010)

its just one machin at a time.

is qwinsta preloaded onto windows?


----------



## valis (Sep 24, 2004)

actually, I may be wrong...it may only work on TS's.......


----------



## TheOutcaste (Aug 8, 2007)

MS figures if you are going to be doing Admin tasks you have to use an Admin account. What should and shouldn't be considered an Admin task can certainly be argued.

You only need one Domain Admin account to run this from, you don't have to change any accounts. Just give the users you want to be able to do Admin tasks that username/password. Then they just need to open an Elevated Command Prompt using that Username and Password and they'll be able to use the WMIC command. Or run it using the RunAs command.

If you add the User Names (or the Users group if you want everyone to have permission) to the WMI Control and DCOM permissions as described in the Enable WMI for Remote Monitoring article it can then be run from a Standard User account. This has to be done on each PC. I don't know if this could be set via a GPO, I've not done much with permissions and Group Policy. I suspect it can though.

To get *psloggedon* to read from Vista when a Standard user is logged on, you have to start the Remote Registry service on each PC and set it to Automatic, so that takes some configuration as well. I don't know how it manages to read the registry from a non-admin account though. Obviously it's possible, but the usual batch/VBScript methods all have to be run with Admin credentials.


----------

