Skip navigation

Q. Another way to set a variable to the current user's logon date and time?

I previously scripted LogonTime.bat to set a variable to the current user's logon date and time.

Using PsLoggedOn.exe, I have scripted LogonDtTm.bat to perform the same task.

The syntax for using LogonDtTm.bat is:

\[call\] LogonDtTm LT

Where LT is a call directed environment variable that will contain the date and time of the current user's logon, like MM/DD/YYYY HH:MM:SS.

LogonDtTm.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: LogonDtTm LT&goto :EOF
setlocal
set lt=0
for /f "Tokens=1-3" %%a in ('psloggedon -l^|find /i "%USERDOMAIN%\%UserName%"') do (
 set lt=%%a %%b
)
endlocal&set %1=%lt%


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish