Forum Discussion

digimon's avatar
digimon
New Contributor
12 years ago

How can I get the list of all local user accounts & user groups in my system

I want to get the list of all local user accounts and user groups in my system. After that, will add/ delete user( or group) automatically by TC.



Have tried WMI, WIN32API, SYS... couldn't find function can be used for my request.



Anyone can hlep me on it?



Thanks in advance.

2 Replies

  • Hi Bobby,

     


    Here is the sample script adapted to TestComplete:


     




    Sub GetAllUsers


      Dim wmiService, computerName, objectsList, user


      


      computerName = "."


     


      Set wmiService = GetObject("winmgmts:"&"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 


      Set objectsList = wmiService.ExecQuery ("Select * from Win32_UserAccount Where LocalAccount = True")


      


      For Each object in objectsList


        user = "Account Type: " & object.AccountType & vbCrLf &_


                  "Caption: " & object.Caption & vbCrLf &_ 


                  "Full Name: " & object.FullName


        Call Log.Message("UserInfo", user)  


      Next


    End Sub




     


    Please make sure that all the needed WMI settings are set on your computer according to the "Working With WMI Objects in Scripts" article.