How to Create a Batch file for last logged on for a remote use


  1. Posts : 3
    Win 7 Pro
       #1

    How to Create a Batch file for last logged on for a remote use


    So I am looking to create some kind of batch file or script where I can click on it....it asks for the machine name, I enter it and then it displays the last logged on user. The following command
    " wmic /NODE:"computername" computersystem get Username" gives me the desired results but I am trying to automate the process. I appreciate any help
      My Computer


  2. Posts : 1,049
    Windows 7 Pro 32
       #2

    Like this?
    Code:
    @ECHO OFF
    SET MACHINENAME=%1
    IF [%1]==[] GOTO SETNAME
    GOTO END
    :SETNAME
    ECHO Type the machine name, press ENTER, Ctrl+Z, ENTER
    FOR /F "tokens=*" %%A IN ('TYPE CON') DO SET INPUT=%%A
    SET MACHINENAME=%INPUT%
    :END
    rem ECHO "%MACHINENAME%"
    wmic /NODE:"%MACHINENAME%" computersystem get Username | find "\"
    pause
    Put that in a bat file and run it and it will ask for a machine name. The tricky thing is it needs a 3 step ENTER + Ctrl+Z + ENTER to exit the input mode. (that's the best I could do for a quick solution)

    I made it so you can also call it with a parameter, then it won't ask for a machine name. Example:
    C:\>GetLastUser.bat SERVER12
    SERVER12\JOHN
      My Computer


  3. Posts : 3
    Win 7 Pro
    Thread Starter
       #3

    Perfect!!!...thanks for your help Tookeri
      My Computer


  4. Posts : 1,049
    Windows 7 Pro 32
       #4

    You're welcome! It's always fun to write some code
      My Computer


  5. Posts : 25,847
    Windows 10 Pro. 64/ version 1709 Windows 7 Pro/64
       #5

    Just curious.
    Is this secure?
    If anybody new the machines name they could work without a password off the previous users account. Or I'm I crazy.
      My Computer


  6. Posts : 3
    Win 7 Pro
    Thread Starter
       #6

    you arent looking up the password. You are just looking up the username of a person who was last logged onto that machine. So yes its secure.
      My Computer


  7. Posts : 25,847
    Windows 10 Pro. 64/ version 1709 Windows 7 Pro/64
       #7

    I think I understand now.
    All you get is the last person logged in and no password.
    Your also not able to use the computer under the last person log in without the password.
    So after retrieving the last logged in person nothing can be done on this computer until someone logs in with a password.

    My thought were if someone left the computer and forgot to log out once the bat file was run anybody could use the computer under the other person log in.

    What makes me think of such things??
      My Computer


  8. Posts : 1,049
    Windows 7 Pro 32
       #8

    Layback Bear said:
    What makes me think of such things??
    Paranoia?! The script only tells who logged in last. Nothing more nothing less. It's like going that machine and looking at the locked screen information, assuming the screen is locked. That will also tell you who is logged in. It's not much to abuse by that information.
      My Computer


  9. Posts : 25,847
    Windows 10 Pro. 64/ version 1709 Windows 7 Pro/64
       #9

    Thanks for the information. I use paranoia as another layer of security protection.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:15.
Find Us