Page 1 of 1 1
Topic Options
#10759 - 2001-07-23 05:11 PM Finding who is logged on to a remote machine
Anonymous
Unregistered


Hello,
I have a little script which is set up to kill tasks on a remote machine (for use by our helpdesk folk) and (for safety reasons) it gets the currently logged on user from our logon audit files and displays it (to prevent mishaps).
However we have taken over another site, which does not run our logon script, and I want to have similar function.
I thought I could use WINMSD remotely and gen a report, then parse the output file (this sort of thing used to work) - but the machines are a mix of NT and 2000 and WINMSD does not seem to be compatible between them.

I am rambling, anyhow - what I need is a way of getting the userid who is currently logged on to a machine, ideally in a file so I can parse it.

Thanks in advance
Mark

[ 23 July 2001: Message edited by: Mark Antrobus ]

Top
#10760 - 2001-07-23 05:34 PM Re: Finding who is logged on to a remote machine
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Hi Mark,

This code should give you a file with one line in it wich is the current logged on user. It is the complete 'user'-line that NBTSTAT returns, so you have to strip the first part if you only want the username.

code:

$station="WORKSTATION"
$tmpfile="%temp%\tmpfile.$$$"
DEL $tmpfile
Shell '%comspec% /c nbtstat -a $station | find "<03>" | find /v "$station" > $tmpfile'

Let us know if you need anymore help with it.

_________________________
The Code is out there

Top
#10761 - 2001-07-23 05:40 PM Re: Finding who is logged on to a remote machine
Anonymous
Unregistered


Roger,
Excellent - you hit the nail on the head.

Many thanks for such a lightening fast response

Mark

Top
#10762 - 2001-07-23 09:55 PM Re: Finding who is logged on to a remote machine
Anonymous
Unregistered


Does "nbtstat |find" always return the results in the same order? Will the machine name always be before the user name? That would be so excellent if so...

I tried doing this very type of thing a long while ago using SysInternals "loggedon". Which never kept everything in order. At present I've got control of the logon script and am recording the userid and a bunch of other stuff to an INI. I just read out when and who last logged on, if anyone is loggedon.

Top
#10763 - 2001-07-25 12:12 AM Re: Finding who is logged on to a remote machine
Anonymous
Unregistered


Jason,
Roger's shell removes everything but the username, thats the purpose of the two finds..

code:
  
nbtstat -a WORKSTA1 | find "<03>" | find /v "WORKSTA1"

would give you a single line of

code:
  
USER1 <03> UNIQUE Registered

very neat!
Mark

Top
#10764 - 2001-07-25 09:31 PM Re: Finding who is logged on to a remote machine
Anonymous
Unregistered


There is one little downfall to this approach...

It cannot see if someone happens to be loggedon more than once. If someone logged on to machine A and then logs on to machine B(While still loggedon to A) this way will show no one logged on machine B.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 384 anonymous users online.
Newest Members
SERoyalty, mytar, Gabriel, Alex_Evos, Dansen
17869 Registered Users

Generated in 0.126 seconds in which 0.099 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org