Jump to content

Changing a users group


Recommended Posts

I am trying to find a way to simplify my scipt to change a users group...I was wondering if anyone knows a way to either do it by command line or another way to do it in autoit.

my current script used gui automation to change the users group, but i would like to simplify it

here is my current _User function (also my _Profile fuction because _User uses it)

Func _User($action, $user, $pass, $level)
    
    Select
        Case $action = "ADD"
            RunWait("net user " & $user & " " & $pass & " /add")
            _User("SET", $user, $pass, $level)
        Case $action = "REMOVE"
            _Profile ("REMOVE", $user)
            RunWait("net user " & $user & " /delete")
        Case $action = "SET"
            Run("rundll32.exe netplwiz.dll,UsersRunDll")
            While 1
                If WinExists("User Accounts") Then
                    WinActivate("User Accounts")
                    ExitLoop
                EndIf
            WEnd
            $makeadmin = -1
            While $makeadmin = -1
                Sleep(500)
                $makeadmin = ControlListView("User Accounts", "", "SysListView321", "FindItem", $user)
            WEnd
            ControlListView("User Accounts", "", "SysListView321", "Select", $makeadmin)
            ControlClick("User Accounts", "", "Button4")
    ;SET PROPERTIES WINDOW NAME
            $propertieswinname = @ComputerName & "\" & $user & " Properties"
            WinWaitActive($propertieswinname)
    ;SWITCH TAB
            Send("^{TAB}")
    ;Choose Administrators Group
            ControlClick($propertieswinname, "", "Button3")
            ControlCommand($propertieswinname, "", "ComboBox1", "SelectString", $level)
    ;APPLY
            ControlClick($propertieswinname, "", "Button6")
    ;CLOSE WINDOW
            WinClose($propertieswinname)
            WinClose("User Accounts")
    EndSelect
EndFunc ;==>_User

Func _Profile($action, $user)
;LOAD SYSTEM PROPERTIES - Advanced tab
    Run("RunDll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3")
;CLICK USER PROFILE SETTINGS
    While 1
        If WinExists("System Properties") Then
            WinActivate("System Properties")
            ControlClick("System Properties", "Advanced", "Button4")
            ExitLoop
        EndIf
    WEnd
    While 1
        If WinExists("User Profiles") Then
            WinActivate("User Profiles")
            ExitLoop
        EndIf
    WEnd
;PICK User
    $pickprofile = @ComputerName & "\" & $user
    $pickprofile = ControlListView("User Profiles", "", "SysListView321", "FindItem", $pickprofile)
    ControlListView("User Profiles", "", "SysListView321", "Select", $pickprofile)
    
    Select
        Case $action = "COPY"
            ControlClick("User Profiles", "", "Button3")
            While 1
                If WinExists("Copy To") Then
                    WinActivate("Copy To")
            ;SET DESTINATION
                    $copy_to = @HomeDrive & "\Documents and Settings\Default User"
                    ControlSetText("Copy To", "", "Edit1", $copy_to)
                    ControlClick("Copy To", "", "Button5")
                    ExitLoop
                Else
                    Sleep(200)
                EndIf
            WEnd
            While 1
                If WinExists("Confirm Copy") Then
                    WinActivate("Confirm Copy")
                    ControlClick("Confirm Copy", "", "Button1")
                    ExitLoop
                Else
                    Sleep(200)
                EndIf
            WEnd
            While 1
                If WinExists("Copy To") Then
                    Sleep(500)
                Else
                    ExitLoop
                EndIf
            WEnd
        Case $action = "REMOVE"
    ;CLICK DELETE
            ControlClick("User Profiles", "", "Button2")
            WinWaitActive("Confirm Delete")
            ControlClick("Confirm Delete", "", "Button1")
    EndSelect
    
    While WinExists("User Profiles")
        WinClose("User Profiles")
    WEnd
    While WinExists("System Properties")
        WinClose("System Properties")
    WEnd
EndFunc ;==>_Profile
Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

You could use the Net command (NT native) like this:

Run("Net localgroup administrators " & $user & " /add")

For a pure AutoIt solution, look at the COM code posted by MSLx Fanboy here.

However, I would suggest adding error checking to prevent your script from aborting.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

You could use the Net command (NT native) like this:

Run("Net localgroup administrators " & $user & " /add")

For a pure AutoIt solution, look at the COM code posted by MSLx Fanboy here.

However, I would suggest adding error checking to prevent your script from aborting.

Thanks...thats exactly what i was looking for...i hadn't seen that...i tried "user group"...but that can only be run from a domain controller

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Thanks...thats exactly what i was looking for...i hadn't seen that...i tried "user group"...but that can only be run from a domain controller

I got very good with CMD shell batch files and the NET commands, but that gets old and cumbersome. I'm now learning (slowly and with a lot of help) to use COM objects to get things done. I just did some user management functions which were posted at this post in Thread #27707.

Of course, users can be members of more than one group, so when you say "change the user's group" I assume you mean add to one group and remove from another. I didn't do a function for the remove part because it didn't come up in the project at hand. I'll have to go back and add that.

Cheers! :D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...