Sign in to follow this  
Followers 0
Luigi

This WMI way to get all windows's users is good?

27 posts in this topic

#1 ·  Posted (edited)

Hi Forum,

I know... there are many ways to get a list (array) with all windows's users...

This query in WMI is good?

Always work?

What I want? Get an array with all windows's users. The windows's default users is not wanted (like 'All Users', 'Default', 'Default User', etc).

Best regards,

Detefon

SELECT LocalPath FROM Win32_UserProfile WHERE SID LIKE 'S-1-5-21%'
#include <Array.au3>

Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

Local $arrName = StringSplit("LocalPath", ",", 2)

Local $colItems = $objWMIService.ExecQuery("SELECT LocalPath FROM Win32_UserProfile WHERE SID LIKE 'S-1-5-21%'", "WQL", 0x10 + 0x20)
Local $Result = ''
Local $sLocalPath
Local $aUsers[1]
Local $sUsersFolder = _GetUsersFolder()
If IsObj($colItems) Then
    For $objItem In $colItems
        For $jj = 0 To UBound($arrName) - 1
            $sLocalPath = StringReplace(Execute("$objItem." & $arrName[$jj]), $sUsersFolder & "\", "")
            _ArrayAdd($aUsers, $sLocalPath)
        Next
    Next
    _ArrayDelete($aUsers, 0)
    _ArrayDisplay($aUsers, "Users")
EndIf

Func _GetUsersFolder()
    Local $arr = StringSplit(@DesktopCommonDir, "\", 2)
    Return $arr[0] & "\" & $arr[1]
EndFunc ;==>_GetUsersFolder
Edited by Detefon

m(o.O)m

Share this post


Link to post
Share on other sites



Did you mean user Profiles or user Accounts?


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

yes, only user's name.


m(o.O)m

Share this post


Link to post
Share on other sites

So your code work?

WMI is good.


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Work, for me, the doubt is: it always work?

I'm not sure here:

SELECT LocalPath FROM Win32_UserProfile WHERE SID LIKE 'S-1-5-21%'

If all users's guid starting with 's-1-5-21%' always return the users, that is que question! 8D

Edited by Detefon

m(o.O)m

Share this post


Link to post
Share on other sites

Work, for me, the doubt is: it always work?

I'm not sure here:

SELECT LocalPath FROM Win32_UserProfile WHERE SID LIKE 'S-1-5-21%'

If all users's guid starting with 's-1-5-21%' always return the users, that is que question! 8D

Yes, I'm pretty sure.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Yes should work. or use this registry key

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList

saludos


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

Yes should work. or use this registry key

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList

hum... others alternatives! I like this! ^^

Thank you Danyfirex ^^

 

Yes, I'm pretty sure.

Thank you MikahS. ^^


m(o.O)m

Share this post


Link to post
Share on other sites

The WMI class Win32_UserProfile doesn't exist on XP

Share this post


Link to post
Share on other sites

j0kky, you talk about the point!

I want know how to verify the status, start and stop the wmi!

Yes, you are write, I presume the WMI is enable...

But, I unknow how check this...


m(o.O)m

Share this post


Link to post
Share on other sites

The WMI class Win32_UserProfile doesn't exist on XP

mikell, it's important for my work, thanks ^^


m(o.O)m

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thank you MikahS. ^^

No problem :)

Also, way to check if WMI is enabled (I'm pretty sure)

$oWMIService = ObjGet("winmgmts:\\.\root\cimv2")
If IsObj($oWMIService) Then
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#Include <Array.au3>
$a = _LocalAccounts_GetUserList()
_ArrayDisplay($a)


Func _LocalAccounts_GetUserList()
    Local $sComputerName = @ComputerName, $aFilter[1] = ["user"], $aResult[1], $oUser

    Local $oComputer = ObjGet("WinNT://" & $sComputerName)
    If NOT IsObj($oComputer) Then Return SetError(2, 0, 0)

    $oComputer.Filter = $aFilter
    For $oUser In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oUser.Name
    Next
    $aResult[0] = UBound($aresult) - 1

    Return $aResult
EndFunc ; ===> _LocalAccounts_GetUserList

Share this post


Link to post
Share on other sites

Datefon,

A non-WMI way...

#include <File.au3>
;#include <array.au3>

local $aUsers = _FileListToArrayRec('C:\users','*',$FLTAR_FOLDERS)

for $1 = 1 to $aUsers[0]
    if not stringregexp($aUsers[$1],'All Users(\|)?|Default( User)?(\|)?|Public(/|)?') then ConsoleWrite($aUsers[$1] & @CRLF)
next

 This is good on Win7.  The directory structure is different on XP and may be different on Vista and Win8.

kylomas 


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

@jguinch - If that is directed at me then I don't know what Win32_Account is.  Possibly because I'm using the Home version of Win7


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

one more way (without wmi)

#include <array.au3>
Local $DOS_out

; Returns members of Users group (remove first 6 unwanted lines)
$iPID = Run(@ComSpec & ' /c NET LOCALGROUP Users | MORE /E +6', "", @SW_HIDE, 2)

Do ; wait that dos has finished
    $DOS_out &= StdoutRead($iPID)
Until @error

; Parse members of Users group from DOS output
$admins = StringSplit(StringStripWS($DOS_out, 7), @CR, 2)
_ArrayPop($admins); remove last unwanted line
_ArrayDisplay($admins) ; show Users group members

edit:

change the group name in this line to select members of other groups:

$iPID = Run(@ComSpec & ' /c NET LOCALGROUP Users | MORE /E +6', "", @SW_HIDE, 2)
Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

@Chimp - I get this as output (Win7 - Home)...

Nancy
NT AUTHORITYAuthenticated Users
NT AUTHORITYINTERACTIVE


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
I hope that Google translator help me to say what I want. 
 
I am very happy to see that so many people reply this topic, and especially with different ways of doing the same thing! 
 
Particularly I read each code carefully and let the imagination fly, thinking of other alternatives, other scripts, this is really cool. 
 
I think unfair to choose one of the answers, to give the topic is closed, I can not do that. Choosing one is not an alternative for me, all are great.
 
All options solved my problem. 
 
Thank you: @Danyfirex, @MikahS, @j0kky, @mikell, @jguinch, @kylomas, @Chimp
:thumbsup:

m(o.O)m

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0