Jump to content
Sign in to follow this  
fruiz367

help with return code for adding domain user to local group

Recommended Posts

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

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 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

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 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

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  

×
×
  • Create New...