bsharath
asked on
Find which user has presently logged in a machine.
Hi,
I want a script that will ask me for a machine names and when i give the machine name it tells me who has logged in at present.In the same script need to have a way to scan the whole file which has the machine names and tell me who is using which machine.
Regards
Sharath
I want a script that will ask me for a machine names and when i give the machine name it tells me who has logged in at present.In the same script need to have a way to scan the whole file which has the machine names and tell me who is using which machine.
Regards
Sharath
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice one Farhan...
ASKER
Oops sorry closed it before i could see others answers....
no problem! I saw after Farhan answer
:: READ THIS FIRST
:: ================
:: * To run this script you must have domain administrators rights.
:: *** Need psloggedon,exe in c:\ (get it from http://www.microsoft.com/technet/sysinternals/utilities/psloggedon.mspx)
:: * Successful run will display logged on sigle machine or on all computers.
:: * This script require "Computers.txt" file on C: drive root from where it will pick computer names.
:: * Copy and Paste following script into notepad and save it with any name having .bat extension.
:: Batch Script Start
@Echo Off
SETLOCAL EnableDelayedExpansion
Echo.
Echo.
Echo Search logged user on pcSingle or pcList ^?
Set /p pc="[MachineName or L]? "
if +%pc%+==++ Goto ShowErr
if /i +%pc%+==+L+ Goto List
if /i not +%pc%+==+L+ c:\pro\psloggedon.exe \\%pc%|findstr /r /v "^NT" |find /i /v "error"
Goto EndScript
:List
IF NOT EXIST C:\Computers.txt Goto ShowErr
FOR %%R IN (C:\Computers.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\userlogged.txt DEL /F /Q C:\userlogged.txt
FOR /F %%c IN ('Type Computers.txt') Do (
Echo Processing: %%c
PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
IF NOT ErrorLevel 1 (
c:\pro\psloggedon.exe \\%%c |findstr /r /v "^NT" |find /i /v "error"
)ELSE (Echo %%c: Not able to connect )
)
Goto EndScript
:ShowErr
Echo.
Echo --- ERROR ---
if +%pc%+==++ (Echo Nothing entered^!^! I Need a machineName or L
)else Echo C:\Computers.txt file does not exist or file is empty!
:EndScript
ENDLOCAL
:: Batch Script End