Does anyone know a quick way to list all the users with profiles on the
local machine?

Re: User Profiles by Torgeir

Torgeir
Mon Nov 29 13:41:06 CST 2004

Noamer wrote:

> Does anyone know a quick way to list all the users with
> profiles on the local machine?
Hi

Run the WMI script below in a command prompt using cscript.exe, it
will list all local users defined on the computer, and it's user
profile path if one exists, as well as identifying the administrator
account:


'--------------------8<----------------------
' Retrieve local computer name.
Set oWshNet = CreateObject("Wscript.Network")
sComputer = oWshNet.ComputerName

' If you want to run it against a remote computer, use this instead
'sComputer = "some name or IP"

Const HKLM = &H80000002
sProfileRegBase = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"

Set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
& sComputer & "/root/default:StdRegProv")

Set oWMI = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
& sComputer & "/root/cimv2")

Set colItems = oWMI.ExecQuery _
("Select Name,SID from Win32_UserAccount WHERE Domain = '" _
& sComputer & "'",,48)

For Each oItem In colItems
sAddInfo = ""
If Right(oItem.SID, 4) = "-500" Then
sAddInfo = " ****** This is the administrator user ******"
End If
Wscript.Echo "User name: " & oItem.Name & sAddInfo
oReg.GetExpandedStringValue HKLM, sProfileRegBase& "\" & oItem.SID, _
"ProfileImagePath", sProfilePath

If IsNull(sProfilePath) Then
sProfilePath = "(none defined)"
End If
Wscript.Echo "Profile path: " & sProfilePath
Wscript.Echo ' blank line
Next
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: User Profiles by Steve

Steve
Mon Nov 29 21:49:26 CST 2004

Another way would be to run this window shell script:

@ECHO OFF
set profilepath=%ALLUSERSPROFILE:\All Users=%
for /f "tokens=*" %%i in ('dir /b /ad "%profilepath%\*"') do echo
%profilepath%\%%i

--
Steve Seguis - MCSE, Microsoft MVP, SCJP
SCRIPTMATION
Automating the Enterprise
http://www.scriptmation.com


"Noamer" <noam72@hotmail.com> wrote in message
news:OMNr0Kk1EHA.4072@TK2MSFTNGP10.phx.gbl...
> Does anyone know a quick way to list all the users with profiles on the
> local machine?
>
>



Re: User Profiles by Torgeir

Torgeir
Tue Nov 30 04:33:08 CST 2004

Steve Seguis [MVP] wrote:

> Another way would be to run this window shell script:
>
> @ECHO OFF
> set profilepath=%ALLUSERSPROFILE:\All Users=%
> for /f "tokens=*" %%i in ('dir /b /ad "%profilepath%\*"') do echo
> %profilepath%\%%i
Hi

Yes, but note that there is not necessarily a one to one correlation
between the user account name and the user "name" part of the profile
path for that user.


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx