Sign in to follow this  
Followers 0
fruiz367

help with return code for adding domain user to local group

5 posts in this topic

Hello, i need help. i am able to add domain user to account, but i do not know what is the return code for when the user is spelled wrong or for some reason it wasn't able to add the user to the group. I want a box to show up saying "Not able to add user to group. check name and try again". Any clues?

;  Prompt to add domain user to Local Administrators Group
#RequireAdmin
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Local $msg
$GUIID2 = GUICreate("Add User to Admin Group", 303, 125, 327, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Enter the username to add to local Admin Group", 16, 16, 230, 17)
$nameinput = GUICtrlCreateInput("", 16, 40, 193, 21)
$okbtn = GUICtrlCreateButton("OK", 24, 72, 105, 33)
GUICtrlSetState($okbtn, $GUI_DEFBUTTON)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($okbtn, "okbtn")

; GUI MESSAGE LOOP
GUISetState()

While 1
    Sleep(1000)
WEnd

Func CLOSEClicked()
    Exit
EndFunc   ;==>CLOSEClicked

Func okbtn()
    $oObj = ObjCreate("WScript.Shell")
    $username = GUICtrlRead($nameinput)
    $Group = ObjGet("WinNT://" & @ComputerName & "/Administrators,group")
    $Group.Add("WinNT://(domain)/" & $username & ",group")
    ;If $username = 0 Then
    ;   MsgBox(0, "Status", "User added, click OK")
    ;EndIf

    

    GUIDelete($GUIID2)
EndFunc   ;==>okbtn

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to AutoIt and the forum!

What's the value of the return code?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

that's what i want to find out. when i run the script, if i put a valid username, it will add it to the group. but if i put a nonvalid username, it will just exit, without giving me a return code or error.

Share this post


Link to post
Share on other sites

In this case you need a COM error handler. This handler will give you the needed information.

Check the help file, function ObjEvent.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

ok, thanks. i will check on that.

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  
Followers 0