Jump to content

Getting SID from EnvGet()


 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...