Jump to content
Sign in to follow this  
APRES

Add / Delete users

Recommended Posts

APRES

Is there an easy way to automate creating (cloning) / deleting users?

Actually I'd like to let people use a shared machine and after user finished his work to delete all his data.

Share this post


Link to post
Share on other sites
randeep

try the script below, as i am also writing a code which includes the new user creation.

just replace $PublisherUserName with ur username. and $PUblisherPassword with your password for the user.

Is there an easy way to automate creating (cloning) / deleting users?

Actually I'd like to let people use a shared machine and after user finished his work to delete all his data.

Local $User
Local $LocalOutPut

    AutoItSetOption("SendKeyDelay", 200)

    Run ('cmd /c "lusrmgr.msc"' , @SystemDir, @SW_HIDE)                                                     ;runs user and groups window
        IF @error <> 0 Then
            MsgBox(1, "Error", "An Error has occured while opening the window - 'Local Users and Groups")
            Return False
        EndIf

    WinWaitActive("Local Users and Groups", "")

    Send ("{TAB}")                                                                                          ;sends tab to reach 'users' folder
    Send ("{Enter}")

    $User = ControlListView ("Local Users and Groups", "", 12786, "FindItem", $PublisherUserName)           ;finds item 'Tetra' in the user list
        If $User = -1 Then

            Send ("!a")                                                                                         ;to go to 'Action' in the menu
            Send ("{Enter}")                                                                                    ;to add user
            Send ($PublisherUserName)                                                                                           ;writes name tetra
            Send ("!f")                                                                                 ;to go the 'Full Name'
            send ("for sql")                                                                                ;write in the above window
            Send ("!p")                                                                                             ;to go to 'password' section
            Send ($PublisherPassword)                                                                                       ;writes password 'tetra'
            Send ("!c")                                                                                         ;confirms password
            Send ($PublisherPassword)                                                                                       ;writes password 'tetra'
            Send ("!m")                                                                                         ;to go to 'User must change password'
            Send ("!w")                                                                                         ;to reach 'password never expires'
            Send ("!e")                                                                                         ;to press 'Create' user
            sleep(250)
            Send ("!o")                                                                                         ;to press 'Close'

            WinWaitActive("Local Users and Groups")

            local $A

            $A = ControlListView ("Local Users and Groups", "", 12786, "FindItem", $PublisherUserName)

            ControlListView ("Local Users and Groups", "", 12786, "Select", $A)
                ;if $LocalOutput = -1 Then
                    ;MsgBox(16, "Error", "Not able to Select" & $PublisherUserName & "on the window - 'Local Users and Groups'")
                    ;Return $RetValue = False
                ;EndIf

            Send ("{Enter}")
            sleep(1000)

            $LocalOutput = ControlClick ($PublisherUserName & " Properties", "General", 12320, "Left")
                if $LocalOutput = 0 Then
                    MsgBox(16, "Error", "Not able to click on 'General' on the window - " & $PublisherUserName & " Properties'")
                    Return False
                EndIf

            Send("{Right}")
            Send("!d")
            Send("Administrators")
            Send ("{Enter}")
            Send ("{TAB 2}")
            Send ("{Enter}")

            sleep(1000)

            $LocalOutPut = Winclose ("Local Users and Groups", "")                                                              ;to forcefully close window
                If $LocalOutPut = 0 Then
                    MsgBox(16, "Error", "Not able to close the window - 'Local Users and Groups'")
                    Return False
                EndIf

        Else

            $LocalOutPut = Winclose ("Local Users and Groups", "")                                                              ;to forcefully close window
                If $LocalOutPut = 0 Then
                    MsgBox(16, "Error", "Not able to close the window - 'Local Users and Groups'")
                    Return False
                EndIf

        EndIf
Edited by randeep

[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.