Skip navigation

JSI Tip 9882. How can I retrieve the distinguishedName of the logged on user, using standard commands?


I have scripted uDN.bat to retrieve the distinguishedName of the logged on user.

The syntax for using uDN.bat is:

call uDN DN

Where DN is a call directed environment variable that will contain the logged on user's distinguishedName, like "CN=Jerold Schulman,CN=Users,DC=JSIINC,DC=COM".

uDN.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: uDN DN&goto :EOF
if exist "%TEMP%\uDN.VBS" goto getDN
@echo.Set objSysInfo = CreateObject("ADSystemInfo")>"%TEMP%\uDN.VBS"
@echo.sUser = 
" ^& objSysInfo.UserName ^&
">>"%TEMP%\uDN.VBS" @echo.WScript.Echo sUser>>"%TEMP%\uDN.VBS" :getDN for /f "Tokens=*" %%u in ('cscript //nologo "%TEMP%\uDN.VBS"') do ( set %1=%%u )



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