Welcome, guest | Sign In | My Account | Store | Cart
@echo off
  if "%1" equ "" goto:help
  setlocal enabledelayedexpansion
    set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    for /f "tokens=2 delims=\" %%i in ('2^>nul reg^
     query HKEY_USERS ^| findstr /v Classes ^| sort') do (
      for %%j in ("-s", "/s") do if "%1" equ "%%~j" echo.%%i
      for %%j in ("-p", "/p") do if "%1" equ "%%~j" (
        if "%%i" equ ".DEFAULT" (
          echo.Default
        ) else (
          for /f "skip=4 tokens=2,* delims=%%" %%k in ('reg^
           query %key%\%%i /v ProfileImagePath') do (
            set "str=%%k%%l"
            if "%%k" equ "systemroot" set "str=!str:systemroot=%systemroot%!"
            if "%%k" equ "SystemDrive" set "str=!str:SystemDrive=%systemdrive%!"
            echo.!str!
          )
        )
      )
    )
  endlocal & goto:eof
  
  :help
  echo.%~n0 v2.01 - shows loaded profiles
  echo.Copyright ^(C^) 2012-2013 - greg zakharov
  echo.ActiveState - code.activestate.com
  echo.
  echo.Usage: %~n0 [/s^|/p]
  echo.   s - print SID of each profile only
  echo.   p - show profile path location
  echo.Note: Default profile is alias of S-1-5-18.
exit /b

Diff to Previous Revision

--- revision 1 2012-11-21 16:58:09
+++ revision 2 2013-08-27 16:27:02
@@ -1,48 +1,33 @@
 @echo off
-  ::if there is no specified argument
   if "%1" equ "" goto:help
-  ::else retrieve loaded profiles
   setlocal enabledelayedexpansion
+    set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
     for /f "tokens=2 delims=\" %%i in ('2^>nul reg^
-    query HKEY_USERS ^| findstr /v "Classes"') do (
-      ::switch 's' means that it will show SIDs
-      for %%j in ("-s", "/s") do if "%1" equ "%%~j" echo %%i
-      ::and 'p' - names only
-      for %%j in ("-p", "/p") do if "%1" equ "%%~j" call:trans %%i
+     query HKEY_USERS ^| findstr /v Classes ^| sort') do (
+      for %%j in ("-s", "/s") do if "%1" equ "%%~j" echo.%%i
+      for %%j in ("-p", "/p") do if "%1" equ "%%~j" (
+        if "%%i" equ ".DEFAULT" (
+          echo.Default
+        ) else (
+          for /f "skip=4 tokens=2,* delims=%%" %%k in ('reg^
+           query %key%\%%i /v ProfileImagePath') do (
+            set "str=%%k%%l"
+            if "%%k" equ "systemroot" set "str=!str:systemroot=%systemroot%!"
+            if "%%k" equ "SystemDrive" set "str=!str:SystemDrive=%systemdrive%!"
+            echo.!str!
+          )
+        )
+      )
     )
-  endlocal
+  endlocal & goto:eof
+  
+  :help
+  echo.%~n0 v2.01 - shows loaded profiles
+  echo.Copyright ^(C^) 2012-2013 - greg zakharov
+  echo.ActiveState - code.activestate.com
+  echo.
+  echo.Usage: %~n0 [/s^|/p]
+  echo.   s - print SID of each profile only
+  echo.   p - show profile path location
+  echo.Note: Default profile is alias of S-1-5-18.
 exit /b
-
-:trans
-  ::set additional variables
-  set "str=%1"
-  set "i=0"
-  ::for checking length of each SID
-  for /l %%i in (0, 1, 255) do (
-    set "chr=!str:~%%i!"
-    if defined chr set /a "i+=1"
-  )
-  ::if length equal eight then it's system profiles
-  if "!i!" equ "8" (
-    set "str=!str:~6,2!"
-    if "!str!" equ "LT" echo Default
-    if "!str!" equ "18" echo System
-    if "!str!" equ "19" echo Local Service
-    if "!str!" equ "20" echo Network Service
-  )
-  ::else these are admins or guest profiles
-  set "str=!str:~41,4!"
-  if "!str:~0,1!" equ "1" echo Administrator
-  if "!str:~0,1!" equ "5" (
-    if "!str!" equ "500" echo Default administrator profile
-    if "!str!" gtr "500" echo Guest
-  )
-exit /b 0
-
-:help
-<nul set /p tip=Usage: %0
-:: [/s | /p]
-::   -s - show SIDs of each loaded profile
-::   -p - display only description of each profile
-for /f "tokens=* delims=:" %%i in ('findstr "^::" "%~dpnx0"') do echo.%%i
-exit /b 0

History