Sign in to follow this  
Followers 0
bobbintb

Getting SID from EnvGet()

4 posts in this topic

i need to get the SID to help me gleam info from the registry properly and i read you can get it with EnvGet() but i don't see a list of variable to use so i cant find it. is there any function to get the SID or will i have to make something up, which will more than likely be ineffective?

Share this post


Link to post
Share on other sites



Its easy to know what variables are available for envget(): Just open an CMD session and type the set command.

Try this func to retrive the current users SID:

ConsoleWrite(GetUserSID(@ComputerName,@UserName) & @CRLF)

Func GetUserSID($ComputerName,$Username)
    Dim $UserSID, $oWshNetwork, $oUserAccount
    $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//"  & $ComputerName & "/root/cimv2")
    $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount")
    For $oUserAccount In $oUserAccounts
        If $Username =  $oUserAccount.Name Then Return $oUserAccount.SID
    Next
    Return ""
EndFunc

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Since Winmgmt service can be stopped or paused for some reason thus causing the failure of the code posted by Jos, you can use _Security__LookupAccountName() function to get wanted information. Array is returned and you want the first element of it ($array[0]).


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

ah ok. i knew there had to be something. thanks.

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