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:

<b>UserDN</b>       is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a>
             that will contain the quoted distinguished name of the logged on user.

<b>UserPrnt</b>     is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a>
             that will contain the quoted distinguished name of the user's <b>OU</b> or container.

<b>ComputerDN</b>   is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a>
             that will contain the quoted distinguished name of the computer that the user is logged on from.

<b>ComputerPrnt</b> is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a>
             that will contain the quoted distinguished name of the computer's <b>OU</b> 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