Jump to content

Completely new to script and the like.


Spikemg1
 Share

Recommended Posts

Hello,

I am trying to make my job as a help desk specialist easier. The main function I am trying to get my GUI to do is take my input and place it into the various programs I use when adding a user to our system. I have the initial GUI set up so far but it only has the first tab done. In total there are roughly 8 locations I need to input new user info into our system. Currently it takes about 45 minutes to an hour to set up 1 user. I am hoping this will bring down the time. Once my co-worker retires her in a year or so. I don't want the new person that would replace her have to go through what I did. Just to learn how to add a user. Also this would theoretically eliminate any user errors that happen on a monthly basis for my co-worker.

With that being said. The first issue I am running into is getting my GUI to check to see if my .msc is open and bring forward, if not then open and bring it forward. The next part after that I don't quite understand, is how to take my user input and place it into that program. 

If anyone could give me a hand that would be amazing. I am completely willing to learn as well if you would want to give me what I am looking for in a teaching format.

P.S. This is the current state of my script.  :(

;=================================
;User Creation GUI Version 0.0.7
;Adding a user to Active Directory
;Created by: Spikemg1
;=================================
#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y

#include <AD.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

;Opens a connection to Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

#Region ### START Koda GUI section ### Form=\\wch.wchosp.org\userfolders\mgallion\my documents\projects\tabs.kxf

;All Global variables
Global $aOUs = _AD_GetAllOUs()
Global $callOU = ObjCreate("Scripting.Dictionary")
Global $itemBoxOptions1 = ""
Global $itemBoxOptions2 = ""
Global $itemBox1, $itemBox2
Global $firstName, $givenName
Global $lastName, $surName
Global $iuserName, $userName
Global $Combo1, $Combo2

;GUI Creation
Global $Form1_1_1 = GUICreate("Tab Sheet Ver. 1.0.0", 757, 452, 192, 143)

;AD Tab Sheet====================================================================
GUICtrlCreateTab(0, 0, 753, 449)
Global $TabSheet1 = GUICtrlCreateTabItem("ActiveDirectory")

;Group 1 of AD Tab
Global $ADGroup1 = GUICtrlCreateGroup("AD User Name Screen", 8, 32, 737, 105)

;New User First Name
Global $Label3 = GUICtrlCreateLabel("First Name", 16, 51, 54, 17)
$firstName = GUICtrlCreateInput("", 80, 51, 225, 21)

;New User Last Name
Global $Label2 = GUICtrlCreateLabel("Last Name", 16, 75, 55, 17)
$lastName = GUICtrlCreateInput("", 80, 75, 225, 21)

;New User LogOn Name
Global $Label1 = GUICtrlCreateLabel("User LogOn Name", 16, 107, 92, 17)
$userName = GUICtrlCreateInput("", 112, 107, 201, 21)


;Copy From User Template
Global $Label4 = GUICtrlCreateLabel("Copy From", 320, 91, 54, 17)
$Combo1 = GUICtrlCreateCombo("", 392, 91, 345, 25, BitOR($CBS_DROPDOWN,$WS_VSCROLL))

;Determines Where the New User Goes in AD
Global $Label5 = GUICtrlCreateLabel("Folder Location", 312, 48, 77, 17)
$Combo2 = GUICtrlCreateCombo("", 392, 48, 345, 25, BitOR($CBS_DROPDOWN,$WS_VSCROLL))
For $iOU = 1 to $aOUs[0][0]
    $callOU.Add($aOUs[$iOU][0] , $aOUs[$iOU][1])
    If($itemBoxOptions1 = "") Then
        $itemBoxOptions1 = $aOUs[$iOU][0]
    Else
        $itemBoxOptions1 = $itemBoxOptions1 & "|" & $aOUs[$iOU][0]
    EndIf
Next
$itemBox1 = GUictrlread($itemBoxOptions1)
GUICtrlSetData($Combo2, $itemBoxOptions1 , 'WCHUsers\TEST')
;End of AD Tab Group 1

;Group 2 of AD Tab
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ADGroup2 = GUICtrlCreateGroup("AD Password Screen", 8, 144, 737, 121)
Global $Password = GUICtrlCreateLabel("Password", 16, 168, 50, 17)
Global $ConfirmPassword = GUICtrlCreateLabel("Confirm", 16, 192, 39, 17)
Global $PasswordInput = GUICtrlCreateInput("", 72, 168, 217, 21, $ES_PASSWORD)
Global $ConfirmInput = GUICtrlCreateInput("", 64, 192, 225, 21, $ES_PASSWORD)
Global $Checkbox1 = GUICtrlCreateCheckbox("User must change password at next logon", 312, 160, 289, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Checkbox2 = GUICtrlCreateCheckbox("User cannot change password", 312, 184, 289, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("Password never expires", 312, 208, 289, 17)
Global $Checkbox4 = GUICtrlCreateCheckbox("Account is disabled", 312, 232, 289, 17)
;End of AD Tab group 2

;Group 3 of AD Tab.
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ADGroup3 = GUICtrlCreateGroup("Additional Information", 8, 272, 737, 137)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
;End of AD Tab Group 3

Global $CreateButton = GUICtrlCreateButton("Create Account", 568, 416, 91, 25)
Global $ExitButton = GUICtrlCreateButton("Exit", 664, 416, 75, 25)
;End of AD Tab Sheet=============================================================
#EndRegion ### END Koda GUI section ###


While 1
    Global $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $CreateButton

            ;Check for user first name
            $givenName = GUICtrlRead($firstName)
            If $givenName <> '' Then
                ConsoleWrite($givenName & @CRLF)
            Else
                MsgBox(0, 'error', 'Please provide user first name.')
            EndIf

            ;Check for user last name
            $surName = GUICtrlRead($lastName)
            If $surName <> '' Then
                ConsoleWrite($surName & @CRLF)
            Else
                MsgBox(0, 'Error', 'Please provide user last name.')
            EndIf

            ;Check for user logon name
            $iuserName = GUICtrlRead($userName & @CRLF)
            If $iuserName <> '' Then
                ConsoleWrite($iuserName & @CRLF)
            Else
                MsgBox(0, 'Error', 'Please provide a user logon name.')
            EndIf

            ;Review all info submitted
            MsgBox(1, 'Review User Info', _
                'First Name: ' & $givenName _
                & @CRLF &   'Last Name: ' & $surName _
                & @CRLF & 'LogOn Name: '& $iuserName _
                & @CRLF & 'User Destination:' & GUICtrlRead($Combo2) _
                & @CRLF & 'Copied User Template:' & GUICtrlRead($Combo1) _
                & @CRLF)
        Case $ExitButton
            Exit
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


;Close connection to Active Directory
_AD_Close()

 

Edited by Spikemg1
Link to comment
Share on other sites

Welcome to AutoIt forum.  When you want to submit code, use <> it is easier for us to view the code instead of having to download it.

you probably want to use ShellExecute to open mmcWCH.msc ?

Link to comment
Share on other sites

Took me about 5 minutes to figure out what you meant. Here you go.

What happens is, if its closed it opens the .msc. If it's open, it opens another instance of the program.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=\\wch.wchosp.org\userfolders\mgallion\my documents\projects\tabs.kxf
Global $Form1_1 = GUICreate("Tab Sheet Ver. 1.0.0", 620, 452, 244, 181)
GUICtrlCreateTab(0, 0, 617, 449)
Global $TabSheet1 = GUICtrlCreateTabItem("ActiveDirectory")
Global $ADGroup1 = GUICtrlCreateGroup("AD User Name Screen", 8, 32, 601, 105)
Global $Label3 = GUICtrlCreateLabel("First Name", 16, 51, 81, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Input3 = GUICtrlCreateInput("", 104, 51, 209, 21)
Global $Label2 = GUICtrlCreateLabel("Last Name", 16, 75, 81, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Input2 = GUICtrlCreateInput("", 104, 75, 209, 21)
Global $Label1 = GUICtrlCreateLabel("User LogOn Name", 16, 107, 136, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Input1 = GUICtrlCreateInput("", 160, 107, 153, 21)
Global $Label4 = GUICtrlCreateLabel("Copy From", 320, 91, 81, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Combo1 = GUICtrlCreateCombo("", 408, 91, 193, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
Global $Label5 = GUICtrlCreateLabel("Folder Location", 320, 48, 114, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Combo2 = GUICtrlCreateCombo("", 440, 48, 161, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ADGroup2 = GUICtrlCreateGroup("AD Password Screen", 8, 144, 601, 121)
Global $Password = GUICtrlCreateLabel("Password", 16, 168, 73, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $ConfirmPassword = GUICtrlCreateLabel("Confirm", 16, 192, 59, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $PasswordInput = GUICtrlCreateInput("", 96, 168, 193, 21, $ES_PASSWORD)
Global $ConfirmInput = GUICtrlCreateInput("", 96, 192, 193, 21, $ES_PASSWORD)
Global $Checkbox1 = GUICtrlCreateCheckbox("User must change password at next logon", 312, 160, 289, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Checkbox2 = GUICtrlCreateCheckbox("User cannot change password", 312, 184, 289, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("Password never expires", 312, 208, 289, 17)
Global $Checkbox4 = GUICtrlCreateCheckbox("Account is disabled", 312, 232, 289, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $SaveButton = GUICtrlCreateButton("Save", 456, 416, 75, 25)
Global $ExitButton = GUICtrlCreateButton("Exit", 536, 416, 75, 25)
Global $TabSheet2 = GUICtrlCreateTabItem("Meditech")
Global $SaveButton2 = GUICtrlCreateButton("Save", 456, 416, 75, 25)
Global $ExitButton2 = GUICtrlCreateButton("Exit", 536, 416, 75, 25)
Global $TabSheet3 = GUICtrlCreateTabItem("Kronos")
Global $TabSheet4 = GUICtrlCreateTabItem("Healthstream")
Global $TabSheet5 = GUICtrlCreateTabItem("Wombat")
Global $TabSheet6 = GUICtrlCreateTabItem("Foxmail")
Global $TabSheet7 = GUICtrlCreateTabItem("Outlook")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $SaveButton
            If Not WinActive('mmcWCH - [Console Root]') Then
                ShellExecute("C:\Users\Public\Desktop\mmcWCH.msc")
                WinWaitActive('mmcWCH - [Console Root]')
            EndIf           
        Case $ExitButton
            Exit

        case $SaveButton2

        Case $ExitButton2
            Exit

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Link to comment
Share on other sites

Maybe you mean to do something like this?

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $SaveButton
            If Not WinExists("mmcWCH") Then
                ShellExecute("C:\Users\Public\Desktop\mmcWCH.msc")
                If Not WinActive('mmcWCH - [Console Root]') Then WinActivate("mmcWCH")
            Else
                If Not WinActive('mmcWCH - [Console Root]') Then WinActivate("mmcWCH")
            EndIf
        Case $ExitButton
            Exit

        Case $SaveButton2

        Case $ExitButton2
            Exit

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Always carry a towel.

Link to comment
Share on other sites

Premade code is like a book written to tell you how to do it, read the code that the functions provide, and learn from that.

No need to reinvent the wheel, just learn from a wheel maker how it's done.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers
23 hours ago, Spikemg1 said:

I am trying to avoid using pre-made code since I am trying to learn how to do it myself. Thanks for the link though.

Ok, so you won't be using AutoIt3 nor C# and will write your script in assembler? :)
Just so you understand this comment: AutoIt3 has many build in functions and User Defined Functions, which are the base you use for your scripts.
I can assure you you won't want to code it all yourself unless you have ample time available.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Let's descibe some basics:

  • The AD UDF uses an API to directly access Active Directory - it doesn't automate a GUI. That's what your mmc does with with the input you provide via the gui.
  • Can you please describe what you want to achieve? I got from the code you posted: create a new user and set firstname, lastname, account name, password, options (must change passwort at first logon etc.),  create a home directory ...
  • Logging is quite easy. If you want I can provide the code I use for similar tasks.

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

17 minutes ago, water said:

Let's descibe some basics:

  • The AD UDF uses an API to directly access Active Directory - it doesn't automate a GUI. That's what your mmc does with with the input you provide via the gui.
  • Can you please describe what you want to achieve? I got from the code you posted: create a new user and set firstname, lastname, account name, password, options (must change passwort at first logon etc.),  create a home directory ...
  • Logging is quite easy. If you want I can provide the code I use for similar tasks.
  • I think I understand what the UDF is for. Which I am doing away with the mmc bit, after finding out that there is an easier way.
  • When we add new employee's these are all the fields we require for that user to have. So once the user is created it is automatically applies the Principals to the user. 
  • Sure that would be nice. My boss wants to have logs of every user added to our system in case of any errors.
  • Also the question about the combo box is for all the OU Locations without having to type it in.
Edited by Spikemg1
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...