Discussion:
Make list of computernames and logged in users
(too old to reply)
markcoutinho
2008-04-18 15:12:53 UTC
Permalink
Hi all,

Sometimes I wonder which user uses which computer when I have failed
to update my helpdesk-database. So it would be nice if I could use a
batch which does the following:
make a list of all computernames (=variable %computername%) and on
every line the names of the users (variable %username%) and put that
in a text-file (i.e. c:\temp\computerusers.txt).

Of course that would only make a list of all the people who are logged
in, but that would be a great help anyway.

Thanks for your help!
Ted Davis
2008-04-18 20:20:25 UTC
Permalink
Post by markcoutinho
Hi all,
Sometimes I wonder which user uses which computer when I have failed to
update my helpdesk-database. So it would be nice if I could use a batch
make a list of all computernames (=variable %computername%) and on every
line the names of the users (variable %username%) and put that in a
text-file (i.e. c:\temp\computerusers.txt).
Of course that would only make a list of all the people who are logged in,
but that would be a great help anyway.
Thanks for your help!
This might be part of the way there:

for /f %A in ('net view ^| find "\\"') do (echo %A >> dump.txt &
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))

It would still need to be munged into some sort of database to be really
useful (\\machine_name is on one line and logged in user, along with login
date/time, is on the next line).
--
T.E.D. (***@mst.edu)
markcoutinho
2008-04-21 10:26:32 UTC
Permalink
Post by markcoutinho
Hi all,
Sometimes I wonder which user uses which computer when I have failed to
update my helpdesk-database. So it would be nice if I could use a batch
make a list of all computernames (=variable %computername%) and on every
line the names of the users (variable %username%) and put that in a
text-file (i.e. c:\temp\computerusers.txt).
Of course that would only make a list of all the people who are logged in,
but that would be a great help anyway.
Thanks for your help!
  for /f %A in ('net view ^| find "\\"') do (echo %A >> dump.txt &
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))
It would still need to be munged into some sort of database to be really
useful (\\machine_name is on one line and logged in user, along with login
date/time, is on the next line).
--
Thanks for your reply, T.E.D.
This is what I put in a batch file:

for /f in 'net view' find "\\"' do echo >> c:\temp\dump.txt &

psloggedon | find "/"| find /v "your user name">> c:\temp\dump.txt

But it doesn't do a thing.
Has something gone wrong with characters that were converted in this
subject?

Thanks in advance!
Ted Davis
2008-04-21 13:03:16 UTC
Permalink
Post by markcoutinho
Post by markcoutinho
Hi all,
Sometimes I wonder which user uses which computer when I have failed
to update my helpdesk-database. So it would be nice if I could use a
make a list of all computernames (=variable %computername%) and on
every line the names of the users (variable %username%) and put that
in a text-file (i.e. c:\temp\computerusers.txt).
Of course that would only make a list of all the people who are logged
in, but that would be a great help anyway.
Thanks for your help!
  for /f %A in ('net view ^| find "\\"') do (echo %A >> dump.txt &
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))
It would still need to be munged into some sort of database to be really
useful (\\machine_name is on one line and logged in user, along with
login date/time, is on the next line).
--
Thanks for your reply, T.E.D.
for /f in 'net view' find "\\"' do echo >> c:\temp\dump.txt &
psloggedon | find "/"| find /v "your user name">> c:\temp\dump.txt
But it doesn't do a thing.
Has something gone wrong with characters that were converted in this
subject?
Thanks in advance!
Put the () back in - some are required by the FOR command syntax, some
are there to prevent ambiquity and ensure that the redirections apply to
the proper commands instead of the entire FOR command.
--
T.E.D. (***@mst.edu)
foxidrive
2008-04-21 13:42:04 UTC
Permalink
Post by markcoutinho
  for /f %A in ('net view ^| find "\\"') do (echo %A >> dump.txt &
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))
It would still need to be munged into some sort of database to be really
useful (\\machine_name is on one line and logged in user, along with login
date/time, is on the next line).
--
Thanks for your reply, T.E.D.
for /f in 'net view' find "\\"' do echo >> c:\temp\dump.txt &
psloggedon | find "/"| find /v "your user name">> c:\temp\dump.txt
But it doesn't do a thing.
Has something gone wrong with characters that were converted in this
subject?
Google groups translates characters incorrectly. Try using a news client.
Mark Coutinho
2008-04-22 08:04:20 UTC
Permalink
I installed a newsreader client, so this translation-thing is solved.
However, T.E.D.: it still doesn't do a thing here. Any suggestions on
what to change?
Thanks in advance!

Mark
Post by foxidrive
Post by markcoutinho
  for /f %A in ('net view ^| find "\\"') do (echo %A >> dump.txt &
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))
It would still need to be munged into some sort of database to be really
useful (\\machine_name is on one line and logged in user, along with login
date/time, is on the next line).
--
Thanks for your reply, T.E.D.
for /f in 'net view' find "\\"' do echo >> c:\temp\dump.txt &
psloggedon | find "/"| find /v "your user name">> c:\temp\dump.txt
But it doesn't do a thing.
Has something gone wrong with characters that were converted in this
subject?
Google groups translates characters incorrectly. Try using a news client.
foxidrive
2008-04-22 08:28:57 UTC
Permalink
Post by Mark Coutinho
I installed a newsreader client, so this translation-thing is solved.
However, T.E.D.: it still doesn't do a thing here. Any suggestions on
what to change?
Thanks in advance!
It works here - here is a batch file version:

@echo off
for /f %%A in ('net view ^|find "\\"') do (echo %%A >> dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))


Make sure you download psloggedon from Microsoft - you might find it under
'pstools'.
Ted Davis
2008-04-22 12:54:28 UTC
Permalink
Post by foxidrive
Post by Mark Coutinho
I installed a newsreader client, so this translation-thing is solved.
However, T.E.D.: it still doesn't do a thing here. Any suggestions on
what to change?
Thanks in advance!
@echo off
for /f %%A in ('net view ^|find "\\"') do (echo %%A >> dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
Make sure you download psloggedon from Microsoft - you might find it under
'pstools'.
It occurred to me that since net view shows only one group/domain at a
time, it might be necessary to specify the domain if it is different from
the user's. It is also necessary to have logon rights to the machines.
--
T.E.D. (***@mst.edu)
Mark Coutinho
2008-04-24 06:41:49 UTC
Permalink
We're getting closer, I guess. 'Cause this time the batch resulted in
a 'dump.txt'-file. However, all it said was: \\APPLICATION - being the
name of one of our servers.
We just have one domain here (SOAAIDSNL).
Any other suggestion would be highly appreciated!
Post by Ted Davis
Post by foxidrive
Post by Mark Coutinho
I installed a newsreader client, so this translation-thing is solved.
However, T.E.D.: it still doesn't do a thing here. Any suggestions on
what to change?
Thanks in advance!
@echo off
for /f %%A in ('net view ^|find "\\"') do (echo %%A >> dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
Make sure you download psloggedon from Microsoft - you might find it under
'pstools'.
It occurred to me that since net view shows only one group/domain at a
time, it might be necessary to specify the domain if it is different from
the user's. It is also necessary to have logon rights to the machines.
Ted Davis
2008-04-24 13:22:05 UTC
Permalink
We're getting closer, I guess. 'Cause this time the batch resulted in a
'dump.txt'-file. However, all it said was: \\APPLICATION - being the name
of one of our servers.
We just have one domain here (SOAAIDSNL). Any other suggestion would be
highly appreciated!
Actually, that is diagnostic of two specific problems: the target machines
are not in your machine's group (add /domain:group_name to the end of
the net view command) or lack of access permission for the machines (it
must be run as an administrator).

If that diagnosis is correct, then
net view
at a CMD prompt should list only the machine you saw.
Post by Ted Davis
It occurred to me that since net view shows only one group/domain at a
time, it might be necessary to specify the domain if it is different from
the user's. It is also necessary to have logon rights to the machines.
--
T.E.D. (***@mst.edu)
Mark Coutinho
2008-04-25 07:31:47 UTC
Permalink
I tried the net view command at the prompt and that gives me the
output I'd expect: all the machinenames in the domain.
The other suggestion: I wasn't quite sure where to put your command so
I tried two different versions:

@echo off
for /f %%A in ('net view domain:soaaidsnl ^|find "\\"') do (echo %%A
Post by Ted Davis
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))

and

@echo off
for /f %%A in ('net view ^|find "\\" domain:soaaidsnl') do (echo %%A
Post by Ted Davis
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))

but neither of them came up with what I want to. Again: just
\\APPLICATION in the dump.txt-file.

Did I put it in the wrong spot?
Post by Ted Davis
Post by foxidrive
We're getting closer, I guess. 'Cause this time the batch resulted in a
'dump.txt'-file. However, all it said was: \\APPLICATION - being the name
of one of our servers.
We just have one domain here (SOAAIDSNL). Any other suggestion would be
highly appreciated!
Actually, that is diagnostic of two specific problems: the target machines
are not in your machine's group (add /domain:group_name to the end of
the net view command) or lack of access permission for the machines (it
must be run as an administrator).
If that diagnosis is correct, then
net view
at a CMD prompt should list only the machine you saw.
Post by foxidrive
Post by Ted Davis
It occurred to me that since net view shows only one group/domain at a
time, it might be necessary to specify the domain if it is different from
the user's. It is also necessary to have logon rights to the machines.
foxidrive
2008-04-25 07:53:33 UTC
Permalink
Post by Mark Coutinho
I tried the net view command at the prompt and that gives me the
output I'd expect: all the machinenames in the domain.
The other suggestion: I wasn't quite sure where to put your command so
@echo off
for /f %%A in ('net view domain:soaaidsnl ^|find "\\"') do (echo %%A
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
Did you get psloggedon?
Ted Davis
2008-04-25 12:57:57 UTC
Permalink
I tried the net view command at the prompt and that gives me the output
I'd expect: all the machinenames in the domain. The other suggestion: I
wasn't quite sure where to put your command so I tried two different
@echo off
for /f %%A in ('net view domain:soaaidsnl ^|find "\\"') do (echo %%A
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
and
@echo off
for /f %%A in ('net view ^|find "\\" domain:soaaidsnl') do (echo %%A
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
but neither of them came up with what I want to. Again: just \\APPLICATION
in the dump.txt-file.
Did I put it in the wrong spot?
Well, since it's an argument to NET VIEW, it certainly belongs between
that and the pipe.

Let's try building the command from scratch.

First, at a CMD prompt, say

net view > list.txt

Verify that list.txt contains the correct list of computers. If it doesn't
you have a NET VIEW issue. Then verify that psloggedon is working by
saying

psloggedon

That should result in something like this

--------
PsLoggedOn v1.21 - Logon Session Displayer
Copyright (C) 1999-2000 Mark Russinovich
SysInternals - www.sysinternals.com

Users logged on locally:
<Unknown> NT AUTHORITY\LOCAL SERVICE
<Unknown> NT AUTHORITY\NETWORK SERVICE
4/22/2008 8:39:07 PM TERA\user_name
<Unknown> NT AUTHORITY\SYSTEM

No one is logged on via resource shares.
--------

(Aside: I named this machine "TERA" because it is my first machine with a
(nominal) terabyte of disk space.)

If you get this response

'psloggedon' is not recognized as an internal or external command,
operable program or batch file.

You either don''t have the program or it isn't in the PATH - if it exists
but isn't in the PATH, either put it in the path, invoke it with its fully
qualified filespec (the extension isn't needed) -

c:/bin/psloggedon.exe

in my case.

Once both NET VIEW and PSLOGGEDON are seen to be working, verify that the
first FIND filter works

psloggedon | find "/"

should respond with something like
4/22/2008 8:39:07 PM TERA\user_name

Since "user_name" will be your username, the second filter should return
nothing

psloggedon | find "/" | find /v "user_name"

Now go back to be simple psloggedon command and paste a machine name from
list.txt in as its argument

psloggedon \\grendel

Upu should get a responce like the one with no argument, except it should
give a different username - if you get something like this

PsLoggedOn v1.21 - Logon Session Displayer
Copyright (C) 1999-2000 Mark Russinovich
SysInternals - www.sysinternals.com

Error opening HKEY_USERS for \\grendel
Unable to query resource logons

then, either you don't have the necessary permissions or the machine
has been shut down since you made the list (or, as in this case, the
machine is not a Windows machine (grendel is running Fedora Linux)).

When all those pieces work, test the FOR /f command with the list (still
at the CMD prompt, not in a batch file)

for /f %A in (list.txt) do echo %A

should display the list of machines - that pretty much has to work if you
are running an NT series OS.

Next build the first level of the compound DO clause

for /f %A in (list.txt) do ((echo %A)& (psloggedon %A))

which should give the machine name followed by the psloggedon response.

If that works, add the filters, one at a time

for /f %A in (list.txt) do ((echo %A)& (psloggedon %A | find "/"))

Then

for /f %A in (list.txt) do ((echo %A)& (psloggedon %A | find "/" | find
/v "your user name"))

(one line)

If that works, then replace the list file with the NET VIEW command and
filter

for /f %A in ('net view ^| find "\\"') do ((echo %A)& (psloggedon %A |
find "/" | find /v "your user name"))

The single and double quotes around and in the net view command are
critical.

If this displays the list of machines with the filtered user data for
those that have someone logged in (like this)

\\TERA
4/22/2008 8:39:07 PM TERA\user_name

then everything except the redirection has been tested - do that next

for /f %A in ('net view ^| find "\\"') do ((echo %A>> dump.txt)&
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))

(be sure to delete dump.txt before each test using it)

With that working, move it into a batch file

@echo off
del dump.txt
for /f %%A in ('net view ^| find "\\"') do ((echo %%A>> dump.txt)&
(psloggedon %%A | find "/" | find /v "your user name" >> dump.txt))
type dump.txt

For the two machines here, dump.txt is

\\GRENDEL
\\TERA
4/22/2008 8:39:07 PM TERA\username

where the real username has been disguised.
--
T.E.D. (***@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
Mark Coutinho
2008-04-28 09:18:59 UTC
Permalink
Ted, you're great for helping me troubleshooting this batch.
What I checked:
- net view > list.txt comes up with a list
- psloggedon: I didn't have that, so I downloaded it and tried it.
- psloggedon came up with Users logged on locally:
Error: could not retrieve logon time
NT AUTHORITY\Lokale service
Error: could not retrieve logon time
NT AUTHORITY\Netwerkservice
28-04-2008 7:43:09 SOAAIDSNL\mark
Error: could not retrieve logon time
NT AUTHORITY\SYSTEM

No one is logged on via resource shares.
So that's good, I'd say.
- however, when I do psloggedon | find "/" it comes up with just
loggedon v1.33 - See who's logged on
Copyright ® 2000-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

so that's where I have my hiccup.

I stopped debuggin' there, as I don't think that would be of any use
since this command doesn't come up with anything. I copied/pasted this
command from your answer from within my newsreader, by the way.

Why doesn't it come up with anything?

Thanks again!
Post by Ted Davis
I tried the net view command at the prompt and that gives me the output
I'd expect: all the machinenames in the domain. The other suggestion: I
wasn't quite sure where to put your command so I tried two different
@echo off
for /f %%A in ('net view domain:soaaidsnl ^|find "\\"') do (echo %%A
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
and
@echo off
for /f %%A in ('net view ^|find "\\" domain:soaaidsnl') do (echo %%A
Post by foxidrive
dump.txt &(
psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
but neither of them came up with what I want to. Again: just \\APPLICATION
in the dump.txt-file.
Did I put it in the wrong spot?
Well, since it's an argument to NET VIEW, it certainly belongs between
that and the pipe.
Let's try building the command from scratch.
First, at a CMD prompt, say
net view > list.txt
Verify that list.txt contains the correct list of computers. If it doesn't
you have a NET VIEW issue. Then verify that psloggedon is working by
saying
psloggedon
That should result in something like this
--------
PsLoggedOn v1.21 - Logon Session Displayer
Copyright (C) 1999-2000 Mark Russinovich
SysInternals - www.sysinternals.com
<Unknown> NT AUTHORITY\LOCAL SERVICE
<Unknown> NT AUTHORITY\NETWORK SERVICE
4/22/2008 8:39:07 PM TERA\user_name
<Unknown> NT AUTHORITY\SYSTEM
No one is logged on via resource shares.
--------
(Aside: I named this machine "TERA" because it is my first machine with a
(nominal) terabyte of disk space.)
If you get this response
'psloggedon' is not recognized as an internal or external command,
operable program or batch file.
You either don''t have the program or it isn't in the PATH - if it exists
but isn't in the PATH, either put it in the path, invoke it with its fully
qualified filespec (the extension isn't needed) -
c:/bin/psloggedon.exe
in my case.
Once both NET VIEW and PSLOGGEDON are seen to be working, verify that the
first FIND filter works
psloggedon | find "/"
should respond with something like
4/22/2008 8:39:07 PM TERA\user_name
Since "user_name" will be your username, the second filter should return
nothing
psloggedon | find "/" | find /v "user_name"
Now go back to be simple psloggedon command and paste a machine name from
list.txt in as its argument
psloggedon \\grendel
Upu should get a responce like the one with no argument, except it should
give a different username - if you get something like this
PsLoggedOn v1.21 - Logon Session Displayer
Copyright (C) 1999-2000 Mark Russinovich
SysInternals - www.sysinternals.com
Error opening HKEY_USERS for \\grendel
Unable to query resource logons
then, either you don't have the necessary permissions or the machine
has been shut down since you made the list (or, as in this case, the
machine is not a Windows machine (grendel is running Fedora Linux)).
When all those pieces work, test the FOR /f command with the list (still
at the CMD prompt, not in a batch file)
for /f %A in (list.txt) do echo %A
should display the list of machines - that pretty much has to work if you
are running an NT series OS.
Next build the first level of the compound DO clause
for /f %A in (list.txt) do ((echo %A)& (psloggedon %A))
which should give the machine name followed by the psloggedon response.
If that works, add the filters, one at a time
for /f %A in (list.txt) do ((echo %A)& (psloggedon %A | find "/"))
Then
for /f %A in (list.txt) do ((echo %A)& (psloggedon %A | find "/" | find
/v "your user name"))
(one line)
If that works, then replace the list file with the NET VIEW command and
filter
for /f %A in ('net view ^| find "\\"') do ((echo %A)& (psloggedon %A |
find "/" | find /v "your user name"))
The single and double quotes around and in the net view command are
critical.
If this displays the list of machines with the filtered user data for
those that have someone logged in (like this)
\\TERA
4/22/2008 8:39:07 PM TERA\user_name
then everything except the redirection has been tested - do that next
for /f %A in ('net view ^| find "\\"') do ((echo %A>> dump.txt)&
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))
(be sure to delete dump.txt before each test using it)
With that working, move it into a batch file
@echo off
del dump.txt
for /f %%A in ('net view ^| find "\\"') do ((echo %%A>> dump.txt)&
(psloggedon %%A | find "/" | find /v "your user name" >> dump.txt))
type dump.txt
For the two machines here, dump.txt is
\\GRENDEL
\\TERA
4/22/2008 8:39:07 PM TERA\username
where the real username has been disguised.
Ted Davis
2008-04-28 13:29:17 UTC
Permalink
Ted, you're great for helping me troubleshooting this batch. What I
- net view > list.txt comes up with a list - psloggedon: I didn't have
that, so I downloaded it and tried it. - psloggedon came up with Users
Error: could not retrieve logon time
NT AUTHORITY\Lokale service
Error: could not retrieve logon time
NT AUTHORITY\Netwerkservice
28-04-2008 7:43:09 SOAAIDSNL\mark
Error: could not retrieve logon time
NT AUTHORITY\SYSTEM
No one is logged on via resource shares. So that's good, I'd say.
- however, when I do psloggedon | find "/" it comes up with just loggedon
v1.33 - See who's logged on
Copyright ® 2000-2006 Mark Russinovich Sysinternals -
www.sysinternals.com
so that's where I have my hiccup.
I stopped debuggin' there, as I don't think that would be of any use since
this command doesn't come up with anything. I copied/pasted this command
from your answer from within my newsreader, by the way.
Why doesn't it come up with anything?
There is a difference between the time format on your system and on mine.

The obvious fix is to replace

find "/"
with
find "-"

If that lets other lines through (it shouldn't since the other lines with
"-" are written to STDERR in V1.33.

Please do not bottom quote: it makes no sense in the usenet context (if
it makes sense anywhere or to anybody except Microsoft) and is quite a
bother.
--
T.E.D. (***@mst.edu)
Mark Coutinho
2008-04-29 09:50:51 UTC
Permalink
Hi Ted,

Thanks again - we're getting close!
When I put this in a CMD-screen it comes out with what I'd expect:
for /f %A in ('net view ^| find "\\"') do ((echo %A>> dump.txt)&
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))

However, when I integrate this line in a batch it comes up with:
\\APPLICATION

This is the name of the first server that psloggedon or net view
finds. Presumably it cuts off the batch at that stage.

What to do next?
Ted Davis
2008-04-29 13:53:33 UTC
Permalink
Post by Mark Coutinho
Hi Ted,
Thanks again - we're getting close!
When I put this in a CMD-screen it comes out with what I'd expect: for /f
%A in ('net view ^| find "\\"') do ((echo %A>> dump.txt)&
(psloggedon %A | find "/" | find /v "your user name" >> dump.txt))
\\APPLICATION
This is the name of the first server that psloggedon or net view finds.
Presumably it cuts off the batch at that stage.
What to do next?
Are you doubling the % signs in the batch file? Are you sure you aren't
just seeing a long wait for a timeout and thinking the task is done?

I can't think of anything that would cause that problem except a failure
of NET VIEW or FIND "\\".

BTW, be sure to replace find "/" with find "-", and it's a good idea to
add /i to the find /v command.
--
T.E.D. (***@mst.edu)
markcoutinho
2008-05-01 13:03:49 UTC
Permalink
Thanks Ted. Due to public holidays I won't be at the office until May
6th, but then I'll try your suggestions.
Have a nice weekend!

Continue reading on narkive:
Loading...