Q. How can a batch or logon script return the current user's CN?

Jerold Schulman

November 16, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Using standard commands, I have scripted CN.bat to return the current user's CN.

The syntax for using CN.bat is:

[call] CN FullName

Where FullName is a call directed environment variable that will contain the current user's CN.

CN.bat contains:

@echo offif {%1}=={} @echo Syntax: CN.bat FullName&goto :EOFif exist "%TEMP%CN.VBS" goto [email protected] array>"%TEMP%CN.VBS"@echo.On Error Resume Next>>"%TEMP%CN.VBS"@echo.Set objSysInfo = CreateObject("ADSystemInfo")>>"%TEMP%CN.VBS" @echo.Set objUser = GetObject("LDAP://" ^& objSysInfo.UserName)>>"%TEMP%CN.VBS"@echo.array = split(objSysInfo.UserName, ",")>>"%TEMP%CN.VBS"@echo.ln = Len(array(0)) - 3 >>"%TEMP%CN.VBS"@echo.ps = 4 >>"%TEMP%CN.VBS"@echo.Wscript.Echo Mid(array(0), ps, ln)>>"%TEMP%CN.VBS":setCNfor /f "Tokens=*" %%n in ('cscript //nologo "%TEMP%CN.VBS"') do ( set %1=%%n)


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like