I have scripted GetUserSID.bat to return the current user's domain SID.

The syntax for using GetUserSID.bat is:

\[call GetUserSID SID

Where SID is a call directed environment variable that will contain the user's domain SID.

GetUserSID.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: GetUserSID SID&goto :EOF
if exist "%TEMP%\GetUserSID.VBS" goto getit
@echo.Set WshShell = Wscript.CreateObject("Wscript.Shell") >"%TEMP%\GetUserSID.VBS"
@echo.Set oADinfo = createobject("ADSystemInfo") >>"%TEMP%\GetUserSID.VBS"
@echo.strUserAdPath = oADinfo.userName >>"%TEMP%\GetUserSID.VBS"
@echo.Set objADObject = GetObject("LDAP://" ^& strUserAdPath) >>"%TEMP%\GetUserSID.VBS"
@echo.tempsid = objADobject.objectsid >>"%TEMP%\GetUserSID.VBS"
@echo.hexsid = OctetToHexStr(tempsid) >>"%TEMP%\GetUserSID.VBS"
@echo.decsid = HexStrToDecStr(hexsid) >>"%TEMP%\GetUserSID.VBS"
@echo.Wscript.Echo decsid >>"%TEMP%\GetUserSID.VBS"
@echo.Wscript.Quit >>"%TEMP%\GetUserSID.VBS"
@echo.Function OctetToHexStr(arrbytOctet) >>"%TEMP%\GetUserSID.VBS"
@echo.  Dim k >>"%TEMP%\GetUserSID.VBS"
@echo.  OctetToHexStr = "" >>"%TEMP%\GetUserSID.VBS"
@echo.  For k = 1 To Lenb(arrbytOctet) >>"%TEMP%\GetUserSID.VBS"
@echo.    OctetToHexStr = OctetToHexStr _ >>"%TEMP%\GetUserSID.VBS"
@echo.      ^& Right("0" ^& Hex(Ascb(Midb(arrbytOctet, k, 1))), 2) >>"%TEMP%\GetUserSID.VBS"
@echo.  Next >>"%TEMP%\GetUserSID.VBS"
@echo.End Function >>"%TEMP%\GetUserSID.VBS"
@echo.Function HexStrToDecStr(strSid) >>"%TEMP%\GetUserSID.VBS"
@echo.  Dim arrbytSid, lngTemp, j >>"%TEMP%\GetUserSID.VBS"
@echo.  ReDim arrbytSid(Len(strSid)/2 - 1) >>"%TEMP%\GetUserSID.VBS"
@echo.  For j = 0 To UBound(arrbytSid) >>"%TEMP%\GetUserSID.VBS"
@echo.    arrbytSid(j) = CInt("&H" ^& Mid(strSid, 2*j + 1, 2)) >>"%TEMP%\GetUserSID.VBS"
@echo.  Next >>"%TEMP%\GetUserSID.VBS"
@echo.  HexStrToDecStr = "S-" ^& arrbytSid(0) ^& "-" _ >>"%TEMP%\GetUserSID.VBS"
@echo.    ^& arrbytSid(1) ^& "-" ^& arrbytSid(8) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = arrbytSid(15) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(14) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(13) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(12) >>"%TEMP%\GetUserSID.VBS"
@echo.  HexStrToDecStr = HexStrToDecStr ^& "-" ^& CStr(lngTemp) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = arrbytSid(19) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(18) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(17) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(16) >>"%TEMP%\GetUserSID.VBS"
@echo.  HexStrToDecStr = HexStrToDecStr ^& "-" ^& CStr(lngTemp) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = arrbytSid(23) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(22) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(21) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(20) >>"%TEMP%\GetUserSID.VBS"
@echo.  HexStrToDecStr = HexStrToDecStr ^& "-" ^& CStr(lngTemp) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = arrbytSid(25) >>"%TEMP%\GetUserSID.VBS"
@echo.  lngTemp = lngTemp * 256 + arrbytSid(24) >>"%TEMP%\GetUserSID.VBS"
@echo.  HexStrToDecStr = HexStrToDecStr ^& "-" ^& CStr(lngTemp) >>"%TEMP%\GetUserSID.VBS"
@echo.End Function >>"%TEMP%\GetUserSID.VBS"
:getit
set %1=NONE
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\GetUserSID.VBS"') do (
 set %1=%%a
)