No announcement yet.

Batch to log Username, Time and Ip-address at login [was: Batch file help]

  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch to log Username, Time and Ip-address at login [was: Batch file help]

    I need to be able to log - Username, time and Ip address at login via a batch file. Can anyone help?

  • #2
    Re: Batch file help

    You don't mention your Operating System...


    %time%, time.exe or now.exe from the Resource Kit

    Extract the required data from the output of ipconfig

    All of which could have been found within 5 seconds by searching this site and/or Google
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.


    • #3
      Re: Batch file help

      In order to keep the forums running well, please follow these simple rules for the forums here.
      Search before you post. And, carefully write your question, provide all the necessary information.

      Are the computers client in a domain?? Are the users domain users??? OSs? IP version?
      You like to run the batch as logonscript? using GPOs?? Is there a networkshare to write the logs to??

      Several batch samples can be found already in this scripting forum!

      @echo off & cls
      Set "logFile=%Computername%.log"  provide full networkpath to logfile!
      ::# Get IP Address
      for /f "skip=1 tokens=2 delims=[]" %%* in (
         'ping.exe -n 1 %Computername%') Do (set "IP=%%*" & goto:exitFor1)
      ::# Get Full Name of User
      If /i "%USERDOMAIN%"=="%Computername%" (
         for /f "skip=1 tokens=2,* delims= " %%a in (
           'net.exe user "%Username%"') do (
             (set "DisplayName=%%b" & goto:exitFor2))
       ) Else (
         for /f "skip=3 tokens=2,* delims= " %%a in (
           'net.exe user "%Username%" /domain') do (
             (set "DisplayName=%%b" & goto:exitFor2))
         If defined DisplayName Set "DisplayName=%DisplayName:)=^)%"
      ::# Append to log
      >>"%logFile%" (
         echo\*** Logon
         echo\User       : %USERDOMAIN%\%Username%  (%DisplayName%^)
         echo\Date/Time  : %date% - %time% 
         echo\To computer: %IP% (%Computername%^)

      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts