stev379 Posted July 19, 2006 Share Posted July 19, 2006 (edited) I got a function from Torgeir to get the local administrator account name (in case it's already been changed). I'm trying to convert to AutoIT. Obviously, my current attempt below doesn't work. Any suggestions on a proper conversion? Original VB codeFunction GetAdministratorName(sComputerName) Dim sUserSID, oWshNetwork, oUserAccount Set oUserAccounts = GetObject( _ "winmgmts:{impersonationLevel=impersonate}!//" _ & sComputerName & "/root/cimv2").ExecQuery( _ "Select Name, SID from Win32_UserAccount WHERE Domain = '" _ & sComputerName & "'") On Error Resume Next For Each oUserAccount In oUserAccounts If Left(oUserAccount.SID, 9) = "S-1-5-21-" And _ Right(oUserAccount.SID, 4) = "-500" Then GetAdministratorName = oUserAccount.Name Exit For End if Next End Function Attempted AutoIT codeFunc GetAdministratorName(@ComputerName) Dim $UserSID, $oWshNetwork, $oUserAccount $oUserAccounts = objGet( _ "winmgmts:{impersonationLevel=impersonate}!//" _ & @ComputerName & "/root/cimv2").ExecQuery( _ "Select Name, SID from Win32_UserAccount WHERE Domain = '" _ & @ComputerName & "'") ;On Error Resume Next For $oUserAccount In $oUserAccounts If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _ StringRight($oUserAccount.SID, 4) = "-500" Then GetAdministratorName = $oUserAccount.Name Exit For Endif Next EndFunc Edited July 19, 2006 by stev379 Link to comment Share on other sites More sharing options...
Developers Jos Posted July 19, 2006 Developers Share Posted July 19, 2006 (edited) This should do it: $Admin = GetAdministratorName(@ComputerName) ConsoleWrite('@@ Debug(1) : $Admin = ' & $Admin & @lf & '>Error code: ' & @error & @lf) ;### Debug Console Func GetAdministratorName($ComputerName) Dim $UserSID, $oWshNetwork, $oUserAccount $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//" & $ComputerName & "/root/cimv2") $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & $ComputerName & "'") For $oUserAccount In $oUserAccounts If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _ StringRight($oUserAccount.SID, 4) = "-500" Then Return $oUserAccount.Name Endif Next EndFunc Edited July 19, 2006 by JdeB 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 More sharing options...
stev379 Posted July 19, 2006 Author Share Posted July 19, 2006 (edited) This should do it: $Admin = GetAdministratorName(@ComputerName) ConsoleWrite('@@ Debug(1) : $Admin = ' & $Admin & @lf & '>Error code: ' & @error & @lf) ;### Debug Console Func GetAdministratorName($ComputerName) Dim $UserSID, $oWshNetwork, $oUserAccount $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//" & $ComputerName & "/root/cimv2") $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & $ComputerName & "'") For $oUserAccount In $oUserAccounts If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _ StringRight($oUserAccount.SID, 4) = "-500" Then Return $oUserAccount.Name Endif Next EndFunc Thanks! You're awsome!! Edited July 19, 2006 by stev379 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now