Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Find which user has presently logged in a machine.

Posted on 2007-08-12
6
Medium Priority
?
396 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:bsharath
6 Comments
 
LVL 26

Accepted Solution

by:
Farhan Kazi earned 2000 total points
ID: 19678770
:: ===============
:: READ THIS FIRST
:: ===============
:: * To run this script you must have domain administrators rights.
:: * This script require "PSLoggedOn.exe" file (comes with PSTools) on C: drive root
:: * Successful run will generate "LoginReport.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
:: *** SCRIPT START ***
@Echo OFF
SETLOCAL EnableDelayedExpansion

IF EXIST C:\LoginReport.txt DEL /F /Q C:\LoginReport.txt

SET /P SysName=Enter single system name or a file having computers name listed:
Echo %SysName% | FIND "." >NUL
Echo %SysName%
IF NOT ErrorLevel 1 (Call :FindMultiple) ELSE (Call :FindSigle)
Goto :EndScript
:FindSigle

PING -n 1 -w 1000 %SysName%|Find /I "TTL" >NUL
IF NOT ErrorLevel 1 (
      Echo ------------ >>C:\LoginReport.txt
      Echo %SysName% >>C:\LoginReport.txt
      Echo ------------ >>C:\LoginReport.txt
      PSLoggedOn \\%SysName% -l | Find "/" >>C:\LoginReport.txt
)ELSE (            
      Echo ------------ >>C:\LoginReport.txt
      Echo %SysName%: Not able to connect >>C:\LoginReport.txt
      Echo ------------ >>C:\LoginReport.txt)
Goto :EndScript

:FindMultiple
IF NOT EXIST %SysName% Goto ShowErr
FOR %%R IN (%SysName%) Do IF %%~zR EQU 0 Goto ShowErr
FOR /F %%c IN ('Type %SysName%') Do (
    Echo Processing: %%c
      PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
      IF NOT ErrorLevel 1 (
            Echo ------------ >>C:\LoginReport.txt
            Echo %%c: >>C:\LoginReport.txt
            Echo ------------ >>C:\LoginReport.txt
            PSLoggedOn \\%%c -l | Find "/" >>C:\LoginReport.txt
            Echo.>>C:\LoginReport.txt
      )ELSE (
            Echo ------------ >>C:\LoginReport.txt
            Echo %%c: Not able to connect >>C:\LoginReport.txt
            Echo ------------ >>C:\LoginReport.txt
            Echo.>>C:\LoginReport.txt)
)      

Goto EndScript
:ShowErr
Echo "%SysName%" file does not exist or file is empty!
:EndScript
ENDLOCAL
:: Batch Script End
0
 
LVL 14

Expert Comment

by:canali
ID: 19678790
: ================
:: 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
0
 
LVL 31

Expert Comment

by:captain
ID: 19678791
Use AD auditing, see KB for details:
http://support.microsoft.com/?kbid=314955

hth
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Author Comment

by:bsharath
ID: 19678794
Nice one Farhan...
0
 
LVL 11

Author Comment

by:bsharath
ID: 19678795
Oops sorry closed it before i could see others answers....
0
 
LVL 14

Expert Comment

by:canali
ID: 19678802
no problem! I saw after Farhan answer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous article  (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html)detailed one possible method to get SCCM 2007 installed an…
Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question