Jump to content

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...