Return SID via WMIC

This returns the SID of the specified username. Note, this couldĀ be either the currently logged on user, or a specific user. ThisĀ used in tandem with a script that cycles through a list of usernames, could be used to dynamically access the HKEY_USERS registry hive. For me specifically, I was using it for the ProfileList key in the registry.

@echo off

for /f “delims= ” %%a in (‘”wmic path win32_useraccount where name=’%UserName%’ get sid”‘) do (
if not “%%a”==”SID” (
set mySID=%%a
goto :SID_END
)
)

:SID_END
echo %mySID%

pause

email me