fruiz367 Posted May 30, 2013 Share Posted May 30, 2013 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? expandcollapse popup; 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 Link to comment Share on other sites More sharing options...
water Posted May 30, 2013 Share Posted May 30, 2013 (edited) Welcome to AutoIt and the forum! What's the value of the return code? Edited May 30, 2013 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
fruiz367 Posted May 30, 2013 Author Share Posted May 30, 2013 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. Link to comment Share on other sites More sharing options...
water Posted May 30, 2013 Share Posted May 30, 2013 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
fruiz367 Posted May 30, 2013 Author Share Posted May 30, 2013 ok, thanks. i will check on that. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now