Jump to content

Issues with radio buttons and normal button


Iceman682
 Share

Recommended Posts

#include <GuiTreeView.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Region ### START Koda GUI section ### Form=Z:GUI'slocalAdminsGUI.kxf
Global $GlobalAdminsGUI = GUICreate("Add local Admins", 394, 484)
GUICtrlCreateGroup("Select Computer Type", 10, 10, 372, 60)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $Radiobox1 = GUICtrlCreateRadio("Desktop", 40, 32, 65, 25)
GUICtrlSetTip(-1, "User Will Be Added To The local Power Users Group")
Global $Radiobox2 = GUICtrlCreateRadio("Desktop With AutoCAD or Laptop", 156, 32, 209, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateGroup("User Account To Be Added To local Administrators Group", 10, 179, 372, 98)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $GlobalAdminUserName = GUICtrlCreateLabel("Domain User Name:", 20, 227, 134, 17)
Global $Input1 = GUICtrlCreateInput("", 130, 222, 140, 21)
Global $Button02 = GUICtrlCreateButton("Add", 281, 202, 88, 64)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetTip(-1, "HelpDesk will be added by Default")
$Label6 = GUICtrlCreateGroup("User Account To Add To The Power Users Group", 10, 290, 372, 95)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Domain User Name:", 20, 335, 134, 17)
Global $Input2 = GUICtrlCreateInput("", 130, 332, 140, 21)
Global $Button03 = GUICtrlCreateButton("Add", 281, 310, 88, 64)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Button01 = GUICtrlCreateButton("Cancel", 10, 390, 372, 64)
$Version2 = GUICtrlCreateLabel("Version 1.0", 316, 455, 68, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
$Group1 = GUICtrlCreateGroup("Accounts To Be Added To The local Administrator Group", 10, 80, 372, 89)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("HelpDesk Is Added By Default To The Machine", 50, 105, 304, 20)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
Global $Radio1 = GUICtrlCreateRadio("AdminsStates", 16, 130, 129, 17)
Global $Radio2 = GUICtrlCreateRadio("AdminsAfrica", 150, 130, 105, 17)
Global $Radio3 = GUICtrlCreateRadio("AdminsEurope", 264, 130, 113, 17)
Global $AdminsStates = ("DomainPCAdminsStates")
Global $AdminsAfrica = ("DomainPCAdminsAfrica")
Global $AdminsEurope = ("DomainAdminsEurope")
Global $HelpDesk = ("DomainHelpDesk")
Global $UserAdmin = ("Domain" & $Input1)
Global $UserPower = ("Domain" & $Input2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetstate($Input1,$GUI_DISABLE)
GUICtrlSetstate($Input2,$GUI_DISABLE)
GUICtrlSetstate($Button02,$GUI_DISABLE)
GUICtrlSetstate($Button03,$GUI_DISABLE)
GUISetState()
 While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE, $Button01
    ;GUIDelete($localAdminsGUI)
    ;GUISetState ( @SW_SHOW ,$MainGUI )
    Exit
    ;Return ""
   
            Case $Radiobox1, $Radiobox2, $Input1, $Input2, $Button02, $Button03
     
   If BitAND(GUICtrlRead($Radiobox1), $GUI_CHECKED) Then
               GUICtrlSetstate($Input1,$GUI_DISABLE)
      GUICtrlSetstate($Input2,$GUI_ENABLE)
      GUICtrlSetstate($Button03,$GUI_ENABLE)
      GUICtrlSetstate($Button02,$GUI_DISABLE)
   Endif  
            If BitAND(GUICtrlRead($Radiobox2), $GUI_CHECKED) Then
               GUICtrlSetstate($Input1,$GUI_ENABLE)
      GUICtrlSetstate($Input2,$GUI_DISABLE)
      GUICtrlSetstate($Button03,$GUI_DISABLE)
      GUICtrlSetstate($Button02,$GUI_ENABLE)
   Endif  
  
    EndSwitch
WEnd

Func _AddAccounts1()
     If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) Then
      Run(@ComSpec & " /c " & "Net localgroup Administrators " & $AdminsStates & " /add", "", @SW_HIDE)
   EndIf
   If BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) Then
      Run(@ComSpec & " /c " & "Net localgroup Administrators " & $AdminsAfrica & " /add", "", @SW_HIDE)
   EndIf
   If BitAND(GUICtrlRead($Radio3), $GUI_CHECKED) Then
      Run(@ComSpec & " /c " & "Net localgroup Administrators " & $AdminsEurope & " /add", "", @SW_HIDE)
   EndIf
   Run(@ComSpec & " /c " & "Net localgroup Administrators " & $HelpDesk & " /add", "", @SW_HIDE)
   MsgBox(0, "Test", "DeBug")
EndFunc

I'm in great need of assistance if at all possible (noob).

The attached script is for adding domain accounts to the local machine's administrator groups or the power users group.

I'm trying to add accounts when the add button is pressed then the GUI close and unhides the maim GUI

The unhiding I'm OK with, it's the rest I'm having difficulty with.

It's probably a mess.

Any assist will be most grateful

Edited by Iceman682
Link to comment
Share on other sites

Maybe something like this?

#include <GuiTreeView.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#region ### START Koda GUI section ### Form=Z:GUI'slocalAdminsGUI.kxf
Global $GlobalAdminsGUI = GUICreate("Add local Admins", 394, 484)
GUICtrlCreateGroup("Select Computer Type", 10, 10, 372, 60)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $Radiobox1 = GUICtrlCreateRadio("Desktop", 40, 32, 65, 25)
GUICtrlSetTip(-1, "User Will Be Added To The local Power Users Group")
Global $Radiobox2 = GUICtrlCreateRadio("Desktop With AutoCAD or Laptop", 156, 32, 209, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateGroup("User Account To Be Added To local Administrators Group", 10, 179, 372, 98)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $GlobalAdminUserName = GUICtrlCreateLabel("Domain User Name:", 20, 227, 134, 17)
Global $Input1 = GUICtrlCreateInput("", 130, 222, 140, 21)
Global $Button02 = GUICtrlCreateButton("Add", 281, 202, 88, 64)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetTip(-1, "HelpDesk will be added by Default")
$Label6 = GUICtrlCreateGroup("User Account To Add To The Power Users Group", 10, 290, 372, 95)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Domain User Name:", 20, 335, 134, 17)
Global $Input2 = GUICtrlCreateInput("", 130, 332, 140, 21)
Global $Button03 = GUICtrlCreateButton("Add", 281, 310, 88, 64)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Button01 = GUICtrlCreateButton("Cancel", 10, 390, 372, 64)
$Version2 = GUICtrlCreateLabel("Version 1.0", 316, 455, 68, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
$Group1 = GUICtrlCreateGroup("Accounts To Be Added To The local Administrator Group", 10, 80, 372, 89)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("HelpDesk Is Added By Default To The Machine", 50, 105, 304, 20)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
Global $Radio1 = GUICtrlCreateRadio("AdminsStates", 16, 130, 129, 17)
Global $Radio2 = GUICtrlCreateRadio("AdminsAfrica", 150, 130, 105, 17)
Global $Radio3 = GUICtrlCreateRadio("AdminsEurope", 264, 130, 113, 17)
Global $AdminsStates = ("DomainPCAdminsStates")
Global $AdminsAfrica = ("DomainPCAdminsAfrica")
Global $AdminsEurope = ("DomainAdminsEurope")
Global $HelpDesk = ("DomainHelpDesk")
Global $UserAdmin = ("Domain" & $Input1)
Global $UserPower = ("Domain" & $Input2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUICtrlSetState($Input1, $GUI_DISABLE)
GUICtrlSetState($Input2, $GUI_DISABLE)
GUICtrlSetState($Button02, $GUI_DISABLE)
GUICtrlSetState($Button03, $GUI_DISABLE)
GUISetState()
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE, $Button01
            ;GUIDelete($localAdminsGUI)
            ;GUISetState ( @SW_SHOW ,$MainGUI )
            Exit
            ;Return ""

        Case $Radiobox1, $Radiobox2

            If BitAND(GUICtrlRead($Radiobox1), $GUI_CHECKED) Then
                GUICtrlSetState($Input1, $GUI_DISABLE)
                GUICtrlSetState($Input2, $GUI_ENABLE)
                GUICtrlSetState($Button03, $GUI_ENABLE)
                GUICtrlSetState($Button02, $GUI_DISABLE)
            EndIf
            If BitAND(GUICtrlRead($Radiobox2), $GUI_CHECKED) Then
                GUICtrlSetState($Input1, $GUI_ENABLE)
                GUICtrlSetState($Input2, $GUI_DISABLE)
                GUICtrlSetState($Button03, $GUI_DISABLE)
                GUICtrlSetState($Button02, $GUI_ENABLE)
            EndIf
        Case $Input1, $Input2

        Case $Button02
            If GUICtrlRead($Input1) = '' Then
                MsgBox(262144, "Error", "You must give a name !")
            Else
                _AddAccounts1(GUICtrlRead($Input1))
            EndIf
        Case $Button03
            If GUICtrlRead($Input2) = '' Then
                MsgBox(262144, "Error", "You must give a name !")
            Else
                _AddAccounts1(GUICtrlRead($Input2))
            EndIf

    EndSwitch
WEnd

Func _AddAccounts1($Newname)
    ;$newname to be a parameter in call to Net I assume
    GUISetState(@SW_HIDE, $GlobalAdminsGUI)
    If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) Then
        RunWait(@ComSpec & " /c " & "Net localgroup Administrators " & $AdminsStates & " /add", "", @SW_HIDE)
    EndIf
    If BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) Then
        RunWait(@ComSpec & " /c " & "Net localgroup Administrators " & $AdminsAfrica & " /add", "", @SW_HIDE)
    EndIf
    If BitAND(GUICtrlRead($Radio3), $GUI_CHECKED) Then
        Run(@ComSpec & " /c " & "Net localgroup Administrators " & $AdminsEurope & " /add", "", @SW_HIDE)
    EndIf
    RunWait(@ComSpec & " /c " & "Net localgroup Administrators " & $HelpDesk & " /add", "", @SW_HIDE)
    MsgBox(0, "Test", "DeBug")

    GUISetState(@SW_SHOW, $GlobalAdminsGUI)
EndFunc   ;==>_AddAccounts1
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...