I have scripted DnUsrCpr.bat to return the distinguished name of the logged on user and their computer, using standard commands.

The syntax for using DnUsrCpr.bat is:

DnUsrCpr UserDN CompDN

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 logged on user distinguished name.

<b>CompDN</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 <b>DN</b> of the computer they are logged on from.

Example:

When I use DnUsrCpr UserDN CompDN, UserDN is set to "CN=Jerold Schulman,CN=Users,DC=JSIINC,DC=COM" and CompDN is set to "CN=JSI009,CN=Computers,DC=JSIINC,DC=COM".

DnUsrCpr.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax Call DnUsrCpr UserDN ComputerDN&exit /b 1
if exist "%TEMP%\DnUsrCpr.vbs" goto doit
@echo Set objSysInfo = CreateObject("ADSystemInfo")>"%TEMP%\DnUsrCpr.vbs"
@echo Wscript.Echo objSysInfo.UserName ^& ";" ^& objSysInfo.ComputerName>>"%TEMP%\DnUsrCpr.vbs"
:doit
for /f "Tokens=1* Delims=;" %%c in ('cscript //Nologo "%TEMP%\DnUsrCpr.vbs"') do (
 set %1="%%c"
 set %2="%%d"
)
exit /b 0