JSI Tip 0351 - Where is UserName? or some interesting uses of the FOR command.

If you have a large multi-location network with traveling roaming users, and need the abilty for users to quickly determine where someone last signed on, without messaging, you can implement the following schema:

. Estabish a share where Everyone has Change permissions on a server that Everyone can reach.

. Set permissions on the shared directory:

    Everyone Add & Read (RWX) (RX)
    CREATOR OWNER      Special Access (RWX) (RWXD)

. Create HereIAm.bat in the shared directory:    Note: For Win 95 clients, you must set environment variables with WINSET.EXE - see tip 120

@echo off
for /f "tokens=1,2 delims=: " %%i in ('time /t') do set hr=%%i%%j NT clients will set hr, W95 will be null
for /f "tokens= 2,3,4 delims=/- " %%i in ('date /t') do set yymmdd=%%k_%%i_%%j NT clients will set yymmdd, W95 will be null
set hereiam=%username%_%computername%_%yymmdd%_%hr%.log Example: SchulmanJ_JSI01_1997_12_08_930a.log
del /q \\ServerName\ShareName\%username%*.log Delete previous log record.
@echo %UserName% last logged on computer %computername% on %yymmdd% at %hr%>\\ServerName\ShareName\%hereiam%       Create the log. Note: @echo through %hereiam% is one line.

. Call HereIAm.bat in a login script.

. When you want to determine where UserName last logged on, run WhereIs UserName from the shared directory or copy it to the users path in the login script:

@echo off
dir \\ServerName\ShareName\%1*.log
type \\ServerName\ShareName\%1*.log
pause
exit

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