Skip navigation

JSI Tip 10073. How can I retrieve the distinguished names of the logged on user, it's OU or container, the logged on computer, and it's OU or container, using standard commands?


Using standard commands, I have scripted PrntUsrCpr.bat to return the distinguished names of the logged on user, it's OU or container, the logged on computer, and it's OU or container, using standard commands.

The syntax for using PrntUsrCpr.bat is:

\[Call\] PrntUsrCpr UserDN UserPrnt ComputerDN ComputerPrnt

Where:

UserDN       is a call directed environment variable
             that will contain the quoted distinguished name of the logged on user.

UserPrnt     is a call directed environment variable
             that will contain the quoted distinguished name of the user's OU or container.

ComputerDN   is a call directed environment variable
             that will contain the quoted distinguished name of the computer that the user is logged on from.

ComputerPrnt is a call directed environment variable
             that will contain the quoted distinguished name of the computer's OU or container.
PrntUsrCpr.bat contains:
@echo off
if \{%4\}==\{\} @echo Syntax Call PrntUsrCpr UserDN UserPrnt ComputerDN ComputerPrnt&exit /b 1
if exist "%TEMP%\PrntUsrCpr.vbs" goto doit
@echo DIM IUsr, UsrP, Cmp, CmpP>"%TEMP%\PrntUsrCpr.vbs"
@echo Set objSysInfo = CreateObject("ADSystemInfo")>>"%TEMP%\PrntUsrCpr.vbs"
@echo set objUser = GetObject("LDAP://" ^& objSysInfo.UserName)>>"%TEMP%\PrntUsrCpr.vbs"
@echo Set objComputer = GetObject("LDAP://" ^& objSysInfo.ComputerName)>>"%TEMP%\PrntUsrCpr.vbs"
@echo Usr = objSysInfo.UserName>>"%TEMP%\PrntUsrCpr.vbs"
@echo Cmp = objSysInfo.ComputerName>>"%TEMP%\PrntUsrCpr.vbs"
@echo UsrP = Replace(objUser.Parent, "LDAP://", "")>>"%TEMP%\PrntUsrCpr.vbs"
@echo CmpP = Replace(objComputer.Parent, "LDAP://", "")>>"%TEMP%\PrntUsrCpr.vbs"
@echo Wscript.Echo Usr ^& ";" ^& UsrP ^& ";" ^&  Cmp ^& ";" ^& CmpP>>"%TEMP%\PrntUsrCpr.vbs"
:doit
for /f "Tokens=1-3* Delims=;" %%c in ('cscript //Nologo "%TEMP%\PrntUsrCpr.vbs"') do (
 set %1="%%c"
 set %2="%%d"
 set %3="%%e"
 set %4="%%f"
)
exit /b 0



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