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!
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. (tda...@mst.edu)
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!
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. (tda...@mst.edu)
>> 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. (tda...@mst.edu)
>
>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?
Google groups translates characters incorrectly. Try using a news client.
Mark
On Mon, 21 Apr 2008 23:42:04 +1000, foxidrive <got...@woohoo.invalid>
wrote:
>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'.
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. (tda...@mst.edu)
> 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.
>>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. (tda...@mst.edu)
@echo off
for /f %%A in ('net view domain:soaaidsnl ^|find "\\"') do (echo %%A
>> 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
>> 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?
>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
>>> dump.txt &(
>psloggedon %%A|find "/"|find /v "your user name" >> dump.txt))
Did you get psloggedon?
> 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
>>> 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
>>> 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. (tda...@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
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!
> 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?
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. (tda...@mst.edu)
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?
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. (tda...@mst.edu)