Sign in to follow this  
Followers 0
Country73

LocalAdminPWD_Change

3 posts in this topic

This script is designed for creating an EXE that locks in the Local Admin Account Name and the password you wish to change it to.

Once ran, creates the EXE that can be ran manually or pushed out remotely against your workstations.

Good way to get around displaying the password in clear text when pushing through SMS, or someone fat-fingering it when making a manual change.

At launch:

Creates C:\edt\LAPC (LocalAdminPasswordChanger)

Installs the following files to that directory:

CUSRMGR.EXE - used for changing the local admin password

Admin.ico - used for the ICON of the compiled script

Aut2.exe, AutoItSc.bin & upx.exe - used in the compiling stage

SaveDialog appears and asks where you wish to create your PWDCGH.exe

You will then see the prompt for:

Account Name:

Password:

Confirm:

Confirm will make sure that Password & Confirm are identical.

It will then go through the complexity of you password to make sure there are, at least:

One lowercase letter

One uppercase letter

One number

One special character

Once it passes the complexity check, you can then compile the script.

The EXE is now ready to be pushed through SMS, ran manually by a double-click, or pushed out to remote workstations with other remote tools. (ie PSEXEC.exe)

I wrote this script back on 02/03/2009, but had to go back in and add in a new function.

Thanks to the post from Greg Nottage - http://www.autoitscript.com/forum/index.ph...77&hl=ADMPW

Only update required, prior to run, is to change the FileInstall for your ICON and the CUSRMGR.EXE locations. Lines 58 & 59 in script.

(Unless of course your AutoIT is installed someplace other than "C:\Program Files\AutoIt3")

Due to the standards I have to write my code in at work, there's quite a few comments throughout.

Some reason they don't line up when posted here, but hopefully it's still clear enough to follow.

I've also included the ICON that I use for the MainGUI, and for the Compiled program

#cs --------------------------------------------------------------------------------------------
 AutoIt Version:    3.3.0.0
 Author:            Chris Hatt
 Contributor:       Greg Nottage - AutoIT Forum / Example Scripts
                        http://www.autoitscript.com/forum/index.php?showtopic=91777&hl=ADMPW
                        Supplied the Complexity Check section.
                    
 Name:              PWDGEN.EXE
 
 Version:   1.0
 Function:          Creates a script to store the Local Admin Account and new password.
                    Completion will wrap the script up into PWDCHG.EXE so the password is not 
                    visible in clear text.
                    Execution of newly created PWDCHG.EXE: 
                        1) Manually launched, double click, on a workstation
                        2) Pushed through SMS against remote workstations
                        3) Remotely ran/pushed to remote workstations using various remote tools
    
 Creation Date:     02/03/2009
 Updated:           02/20/2009
                    Better recording, Corporate Standards, in the registry and log file.
 Updated:           03/26/2009
                    Incorporated a complexity checker for length,upper/lowercase,numbers,special characters
#ce --------------------------------------------------------------------------------------------
#Region     ;Includes
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#EndRegion  ;==>END Includes
;
#Region     ;Options
OPT('TrayMenuMode',1)                                                                           ;No default menu for tray icon - removes Auto Pause when clicked
Opt('MustDeclareVars',1)                                                                                ;Make sure all Variables are declared
#EndRegion  ;==END Options
;
#Region     ;Global Variables
Global $Main                                                        ;Variable for MainGUI
Global $MainIcon    = 'C:\Program Files\AutoIt3\Pics\Admin.ico'                             ;Icon to use in GUI
Global $ACCT                                                        ;Variable for Local Admin AccountName
Global $iPassword                                                   ;Variable for Password
Global $iConfirmPw                                                  ;Variable for ConfirmPassword
Global $CONF                                                        ;Variable to Confirm Passwords match/meet complexity standards
Global $CREA                                                        ;Variable to Compile the new EXE
Global $RELOAD                                                      ;Clear all fields/similar to reload of program
Global $Local                                                       ;Variable for Save Location after compile
Global $Storage                                                     ;Location for the compile files to load to on launch
Global $strPassw                                                    ;Variable used for reading the $iPassword entry
Global $strConfirmPw                                                        ;Variable used for reading the $iConfirmPw entry
Global $strError                                                            ;Variable used for catching errors while checking complexity
Global $strComplexPW                                                ;Variable used for the return on checking complexity
#EndRegion  ;==>END Global Variables
;
#Region     ;Storage location, copy of required files
SplashTextOn('','Loading necessary files to compile script...',400,150,150,150,0,'',22,200)
DirCreate('C:\edt\LAPC')
$Storage = 'C:\edt\LAPC'
FileInstall('C:\Program Files\AutoIt3\Tools\cusrmgr.exe',$Storage & '\',1)                      ;Tool for changing the password
FileInstall('C:\Program Files\AutoIt3\Pics\Admin.ico',$Storage & '\',1)                         ;Icon for App
FileInstall('C:\Program Files\AutoIt3\Aut2Exe\Aut2exe.exe',$Storage & '\',1)                            ;Tool to compile the au3 to EXE
FileInstall('C:\Program Files\AutoIt3\Aut2Exe\AutoItSC.bin',$Storage & '\',1)                           ;Tool to compile the au3 to EXE
FileInstall('C:\Program Files\AutoIt3\Aut2Exe\upx.exe',$Storage & '\',1)                                ;Tool to compile the au3 to EXE

; Message to display after files have been installed
SplashTextOn('','Next you will need to select the folder to store the PWDCHG.exe',400,150,150,150,0,'',22,200)
Sleep(2000)
SplashOff()

$Local = FileSelectFolder('SAVE LOCATION for PWDCHG.exe',@DesktopDir,1,'')                      ;Path to create the EXE and temp location of tools used
If @error Then
    MsgBox(262160,'CANCEL','Abort "PWDCHG.exe" creation')
    _ExitNow()
Else
    Local $UserVerify                                                                           ;Variable for continue if EXE already exists
    If FileExists($Local & '\PWDCHG.EXE')Then                                                   ;EXE already exists, overwrite or exit
        $UserVerify = MsgBox(262212,'WARNING','If you continue, the current "PWDCHG.EXE" will be deleted!' & @CRLF & 'Do you wish to continue?')
        If $UserVerify = 7 Then                                                                 ;Chose to abort/exit
            _ExitNow()
        EndIf
    EndIf
EndIf
#EndRegion  ;==>Storage/Files
;
MainFunc()
#Region     ;Main GUI
Func MainFunc()
    Opt('GUICoordMode',1)                                                                           ;absolute coordinates (default) still relative to the dialog box.
    Opt('GUIOnEventMode',1)                                                                         ;Enable/disable OnEvent functions notifications. 1 = enable
    
    $Main   = GUICreate('LOCAL ACCOUNT - PASSWORD CHANGE',400,250,150,150)
    GUISetIcon($MainIcon)
    GUICtrlCreateGroup('',10,2,380,100)                                                             ;Grouped comments as to what is required in password
        GUICtrlCreateLabel('Must be atleast 8 characters long...',30,10,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one lowercase letter...',30,28,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one UPPERCASE letter...',30,46,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one number...',30,64,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one special character...',30,82,340,18)
        GUICtrlSetFont(-1,12,400)
    GUICtrlCreateGroup('',-99,-99,1,1)
    GUICtrlSetBkColor(-1,0x000000)
    
    $ACCT   = GUICtrlCreateInput('',120,120,250,18,$ES_UPPERCASE)                                   ;Input for AccountName
    $iPassword  = GUICtrlCreateInput('',120,140,250,18,$ES_PASSWORD)                                ;Input for New Password
    $iConfirmPw = GUICtrlCreateInput('',120,160,250,18,$ES_PASSWORD)                                ;Input for Confirm New Password
    
    GUICtrlCreateLabel('Account Name:',5,120,100,12,$ES_RIGHT)                                      ;Label for AccountName
    GUICtrlCreateLabel('Password:',5,140,100,12,$ES_RIGHT)                                          ;Label for Password
    GUICtrlCreateLabel('Confirm:',5,160,100,12,$ES_RIGHT)                                           ;Label for Confirm Password
    
    $CONF   = GUICtrlCreateButton('CONFIRM',120,190,81,33)                                          ;Button to confirm the passwords match/meet complexity
    $CREA   = GUICtrlCreateButton('CREATE',205,190,81,33)                                           ;Button to create/compile completed script
    $RELOAD = GUICtrlCreateButton('RELOAD',290,190,81,33)                                           ;Button to clear all fields/start from scratch
    
    GUICtrlSetState($CREA,$GUI_DISABLE)                                                             ;Not available until complexity/match has been met
    GUICtrlSetOnEvent($CONF,'compare')                                                              ;Func to run on button click
    GUICtrlSetOnEvent($CREA,'create')                                                               ;Func to run on button click
    GUICtrlSetOnEvent($RELOAD,'ReDo')                                                               ;Func to run on button click
    GUISetOnEvent($GUI_EVENT_CLOSE,'_ExitNow')                                                      ;Close of application
    GUISetState(@SW_SHOW)                                                                           ;Show the GUI
    
    While 1                                                                                         ;Loop waiting for interaction from user
        Sleep(10)
    WEnd
EndFunc
#EndRegion  ;==>END Main
;
#Region     ;EXIT - Clear all files/temps used in creation of EXE
Func _ExitNow()
    If FileExists($Storage & '\Aut2Exe.exe') Then FileDelete($Storage & '\Aut2Exe.exe')
    If FileExists($Storage & '\pwdchg.au3') Then FileDelete($Storage & '\pwdchg.au3')
    If FileExists($Storage & '\AutoItSC.bin') Then FileDelete($Storage & '\AutoItSC.bin')
    If FileExists($Storage & '\upx.exe') Then FileDelete($Storage & '\upx.exe')
    If FileExists($Storage & '\cusrmgr.exe') Then FileDelete($Storage & '\cusrmgr.exe')
    If FileExists($Storage & '\Admin.ico') Then FileDelete($Storage & '\Admin.ico')
    Sleep(200)
    FileRecycleEmpty('C:\')
    Exit
EndFunc
#EndRegion  ;==>END EXIT
;
#Region     ;Button Function - Clears all fields for new creation
Func ReDo()
    GUICtrlSetData($ACCT,'')                                                                    ;Clear AccountName field
    GUICtrlSetData($iPassword,'')                                                               ;Clear Password field
    GUICtrlSetData($iConfirmPw,'')                                                              ;Clear Confirm Password field
    GUICtrlSetState($ACCT,$GUI_ENABLE)                                                          ;Re-enable AccountName field
    GUICtrlSetState($iPassword,$GUI_ENABLE)                                                     ;Re-enable Password field
    GUICtrlSetState($iConfirmPw,$GUI_ENABLE)                                                    ;Re-enable Confirm Password field
    GUICtrlSetState($CONF,$GUI_ENABLE)                                                          ;Re-enable Confirm Button
    GUICtrlSetState($CREA,$GUI_DISABLE)                                                         ;Re-enable Create Button
    GUICtrlSetState($ACCT,$GUI_FOCUS)                                                           ;Focus on AccountName field
EndFunc
#EndRegion  ;==>END ReDo
;
#Region     ;Compare    - Ensure entries prior to creation
Func compare()  ;Compares passwords to make sure they match
    $strPassw = GUICtrlRead($iPassword)                                                             ;Read in the Password
    $strConfirmPw = GUICtrlRead($iConfirmPw)                                                        ;Read in the Confirm Password
    $strError = ""                                                                                  ;Variable for Errors is blank

    If $strPassw <> "" Then                                                                         ;NOT blank
    ElseIf $strPassw = "" Then                                                                      ;Password Blank
        $strError = $strError & "Password" & @CRLF
    EndIf
    
    If $strConfirmPw <> "" Then                                                                     ;NOT blank
    ElseIf $strConfirmPw = "" Then                                                                  ;ConfirmPassword Blank
        $strError = $strError & "Confirm password" & @CRLF
    EndIf
    
    If $strError <> "" Then                                                                         ;Error returned NOT blank
        MsgBox(262144,'ERROR!','The following entries need completing:' & @CRLF & @CRLF & $strError)
        GUICtrlSetData($iPassword,'')                                                               ;Clear Password field
        GUICtrlSetData($iConfirmPw,'')                                                              ;Clear Confirm Password field
        GUICtrlSetState($iPassword,$GUI_FOCUS)                                                      ;Focus on Password field
    ElseIf $strError = "" Then                                                                      ;No Errors
        If $strPassw = $strConfirmPw Then                                                           ;Passwords Match
            $strComplexPW = _IsComplex()                                                            ;Check Complexity of Password
            If $strComplexPW = 1 Then                                                               ;Correct setup; create EXE
                MsgBox(262208,'MATCH','Passwords match!' & @CRLF & 'Select "CREATE" to compile your script into "PWDCHG.exe"' & @CRLF & @CRLF & _
                'Or select "RELOAD" to recreate')
                GUICtrlSetState($ACCT,$GUI_DISABLE)                                                 ;Lockout changing of AccountName
                GUICtrlSetState($iPassword,$GUI_DISABLE)                                            ;Lockout changing of Password
                GUICtrlSetState($iConfirmPw,$GUI_DISABLE)                                           ;Lockout changing of Confirm Password
                GUICtrlSetState($CREA,$GUI_ENABLE)                                                  ;Enable Create button
                GUICtrlSetState($CONF,$GUI_DISABLE)                                                 ;Disable Confirm button
                GUICtrlSetState($CREA,$GUI_FOCUS)                                                   ;Focus on Create button
            Else
                ;Re-type password as it doesn't meet complexity requirements
                MsgBox(262144,'Password is...','Not complex!' & @CRLF & @CRLF & 'Please enter a password that' & @CRLF & 'meets the complexity requirements.')
                GUICtrlSetData($iPassword,'')                                                       ;Clear Password field
                GUICtrlSetData($iConfirmPw,'')                                                      ;Clear Confirm Password field
                GUICtrlSetState($iPassword,$GUI_FOCUS)                                              ;Focus on Password field
            EndIf
        Else                                                                                        ;Password and Confirm Password don't match
            MsgBox(262144,'Passwords...','Do not match!' & @CRLF & 'Please re-enter the passwords.')
            GUICtrlSetData($iPassword,'')                                                           ;Clear Password field
            GUICtrlSetData($iConfirmPw,'')                                                          ;Clear Confirm Password field
            GUICtrlSetState($iPassword,$GUI_FOCUS)                                                  ;Focus on Password field
        EndIf
    EndIf
EndFunc
#EndRegion  ;==>Compare
;
#Region     ;_IsComplex
Func _IsComplex()
    Local $iStrength = 0                                                                            ;Variable for complexity check
    Local $strReturn
    
    If StringLen($strPassw) >= 8 Then                                                               ;Check length of password
        $iStrength = $iStrength + 1
    EndIf
    $strReturn = _CheckValue(97,122,$strPassw)                                                      ;Check for Lowercase letters a - z
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(65,90,$strPassw)                                                       ;Check for Uppercase letters A - Z
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(48,57,$strPassw)                                                       ;Check for numbers 0 - 9
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(33,47,$strPassw)                                                       ;Check for special characters ! - /
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(58,64,$strPassw)                                                       ;Check for special characters : - @
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(91,96,$strPassw)                                                       ;Check for special characters [ - `
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(123,255,$strPassw)                                                     ;Check for special characters { - y
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf

    If $iStrength >= 5 Then
        Return(1)
    EndIf
EndFunc
#EndRegion  ;==>END_IsComplex
;
#Region     ;_CheckValue    -   Loop through character codes to see if exists in password
Func _CheckValue($x,$y,$strPassw)
    Local $iLoopvar = 0
    For $iLoopvar = $x To $y
        If StringInStr($strPassw, Chr($iLoopvar), 1,1, 1) > 0 Then
            Return(1)
        EndIf
    Next
EndFunc
#EndRegion  ;==>END_CheckValue
;
#Region     ;Create/Compile EXE
Func create()
    GUICtrlSetState($CREA,$GUI_DISABLE)                                                             ;Disable Create button
    GUICtrlSetState($RELOAD,$GUI_DISABLE)                                                           ;Disable Reload button
    GUISetState(@SW_HIDE,$Main)                                                                     ;Hide MainGUI
    SplashTextOn('','Please wait while the new Password Change script is compiled.',400,150,150,150,0,'',22,200)
    
    ;Verify all the necessary files are still on machine, these were loaded at launch of main program
    If Not FileExists($Storage & '\cusrmgr.exe') Then
        MsgBox(262160,'ERROR','"CUSRMGR.EXE" was not copied over on application launch!')
        _ExitNow()
    EndIf
    If Not FileExists($Storage & '\Aut2exe.exe')Then
        MsgBox(262160,'ERROR','Compiler was not copied over on application launch!')
        _ExitNow()
    EndIf
    Local $FCreate                                                                                  ;Variable used for opening/creating new script
    $FCreate = FileOpen($Storage & '\pwdchg.au3',2)
    If $FCreate = -1 Then
        MsgBox(262160,'ERROR','Unable to create at:' & @CRLF & $Storage & @CRLF & @CRLF & 'Make sure you have rights to that directory!')
        _ExitNow()
    Else
        FileWriteLine($FCreate,'If Not FileExists("C:\edt\LAPC") Then DirCreate("C:\edt\LAPC")')
        FileWriteLine($FCreate,'FileInstall("' & $Storage & '\cusrmgr.exe","c:\edt\LAPC\",1)')
        FileWriteLine($FCreate,'RegWrite("HKLM\SOFTWARE\SSC_INVENTORY_CONTROL","PWDCHG","REG_SZ","1.0")')
        FileWriteLine($FCreate,'$var = ShellExecuteWait("c:\edt\LAPC\cusrmgr.exe","-u ' & GUICtrlRead($ACCT) & ' -P ' & GUICtrlRead($iPassword) & '","","")')
        FileWriteLine($FCreate,'If Not $var = 0 Then')
        FileWriteLine($FCreate,'$msg = "Password for ' & GUICtrlRead($ACCT) & ' did not change!" & @TAB & @MON&"_"&@MDAY&"_"&@YEAR')
        FileWriteLine($FCreate,'RegWrite("HKLM\SOFTWARE\SSC_INVENTORY_CONTROL\PWDCHG","ERROR_LastAdminPassChange_" & @YEAR & "_" & @MON,"REG_SZ","ERROR - Password not changed - ' & GUICtrlRead($ACCT) & ' - " & @MON & "_" & @MDAY & "_" & @YEAR)')
        FileWriteLine($FCreate,'Else')
        FileWriteLine($FCreate,'$msg = "Password for ' & GUICtrlRead($ACCT) & ' changed on:" & @TAB & @MON&"_"&@MDAY&"_"&@YEAR')
        FileWriteLine($FCreate,'RegWrite("HKLM\SOFTWARE\SSC_INVENTORY_CONTROL\PWDCHG","LastAdminPassChange_" & @YEAR & "_" & @MON,"REG_SZ","' & GUICtrlRead($ACCT) & ' - " & @MON & "_" & @MDAY & "_" & @YEAR)')
        FileWriteLine($FCreate,'EndIf')
        FileWriteLine($FCreate,'$file = FileOpen("C:\edt\LAPC\LastAdminPassChange.log",1)')
        FileWriteLine($FCreate,'If $file = -1 Then')
        FileWriteLine($FCreate,'Exit')
        FileWriteLine($FCreate,'Else')
        FileWriteLine($FCreate,'FileWriteLine($file,$msg)')
        FileWriteLine($FCreate,'EndIf')
        FileWriteLine($FCreate,'FileClose($file)')
        FileWriteLine($FCreate,'If FileExists("C:\edt\LAPC\cusrmgr.exe") Then FileDelete("C:\edt\LAPC\cusrmgr.exe")')
        FileWriteLine($FCreate,'Exit')
        FileClose($FCreate)
        ;String to compile the new script to EXE
        ShellExecuteWait($Storage & '\Aut2exe.exe','/in "' & $Storage & '\pwdchg.au3" /out "' & $Local & '\PWDCHG.EXE" /icon "' & $Storage & '\Admin.ico"')
    EndIf
    SplashOff()
    SplashTextOn('','Your newly packaged PWDCHG.EXE has been created.',400,150,150,150,0,'',22,200)
    Sleep(4000)
    SplashOff()
    _ExitNow()
EndFunc
#EndRegion  ;==>END Create/Compile
;

Admin.ico


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites



Great script! When I apply the executable to remote machines as part of a log on script, it only works on those machines where the logging on user has admin rights. Is there a way to incorporate a run as admin function within the executable?

This script is designed for creating an EXE that locks in the Local Admin Account Name and the password you wish to change it to.

Once ran, creates the EXE that can be ran manually or pushed out remotely against your workstations.

Good way to get around displaying the password in clear text when pushing through SMS, or someone fat-fingering it when making a manual change.

At launch:

Creates C:\edt\LAPC (LocalAdminPasswordChanger)

Installs the following files to that directory:

CUSRMGR.EXE - used for changing the local admin password

Admin.ico - used for the ICON of the compiled script

Aut2.exe, AutoItSc.bin & upx.exe - used in the compiling stage

SaveDialog appears and asks where you wish to create your PWDCGH.exe

You will then see the prompt for:

Account Name:

Password:

Confirm:

Confirm will make sure that Password & Confirm are identical.

It will then go through the complexity of you password to make sure there are, at least:

One lowercase letter

One uppercase letter

One number

One special character

Once it passes the complexity check, you can then compile the script.

The EXE is now ready to be pushed through SMS, ran manually by a double-click, or pushed out to remote workstations with other remote tools. (ie PSEXEC.exe)

I wrote this script back on 02/03/2009, but had to go back in and add in a new function.

Thanks to the post from Greg Nottage - http://www.autoitscript.com/forum/index.ph...77&hl=ADMPW

Only update required, prior to run, is to change the FileInstall for your ICON and the CUSRMGR.EXE locations. Lines 58 & 59 in script.

(Unless of course your AutoIT is installed someplace other than "C:\Program Files\AutoIt3")

Due to the standards I have to write my code in at work, there's quite a few comments throughout.

Some reason they don't line up when posted here, but hopefully it's still clear enough to follow.

I've also included the ICON that I use for the MainGUI, and for the Compiled program

#cs --------------------------------------------------------------------------------------------
 AutoIt Version:    3.3.0.0
 Author:            Chris Hatt
 Contributor:       Greg Nottage - AutoIT Forum / Example Scripts
                        http://www.autoitscript.com/forum/index.php?showtopic=91777&hl=ADMPW
                        Supplied the Complexity Check section.
                    
 Name:              PWDGEN.EXE
 
 Version:   1.0
 Function:          Creates a script to store the Local Admin Account and new password.
                    Completion will wrap the script up into PWDCHG.EXE so the password is not 
                    visible in clear text.
                    Execution of newly created PWDCHG.EXE: 
                        1) Manually launched, double click, on a workstation
                        2) Pushed through SMS against remote workstations
                        3) Remotely ran/pushed to remote workstations using various remote tools
    
 Creation Date:     02/03/2009
 Updated:           02/20/2009
                    Better recording, Corporate Standards, in the registry and log file.
 Updated:           03/26/2009
                    Incorporated a complexity checker for length,upper/lowercase,numbers,special characters
#ce --------------------------------------------------------------------------------------------
#Region     ;Includes
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#EndRegion  ;==>END Includes
;
#Region     ;Options
OPT('TrayMenuMode',1)                                                                           ;No default menu for tray icon - removes Auto Pause when clicked
Opt('MustDeclareVars',1)                                                                                ;Make sure all Variables are declared
#EndRegion  ;==END Options
;
#Region     ;Global Variables
Global $Main                                                        ;Variable for MainGUI
Global $MainIcon    = 'C:\Program Files\AutoIt3\Pics\Admin.ico'                             ;Icon to use in GUI
Global $ACCT                                                        ;Variable for Local Admin AccountName
Global $iPassword                                                   ;Variable for Password
Global $iConfirmPw                                                  ;Variable for ConfirmPassword
Global $CONF                                                        ;Variable to Confirm Passwords match/meet complexity standards
Global $CREA                                                        ;Variable to Compile the new EXE
Global $RELOAD                                                      ;Clear all fields/similar to reload of program
Global $Local                                                       ;Variable for Save Location after compile
Global $Storage                                                     ;Location for the compile files to load to on launch
Global $strPassw                                                    ;Variable used for reading the $iPassword entry
Global $strConfirmPw                                                        ;Variable used for reading the $iConfirmPw entry
Global $strError                                                            ;Variable used for catching errors while checking complexity
Global $strComplexPW                                                ;Variable used for the return on checking complexity
#EndRegion  ;==>END Global Variables
;
#Region     ;Storage location, copy of required files
SplashTextOn('','Loading necessary files to compile script...',400,150,150,150,0,'',22,200)
DirCreate('C:\edt\LAPC')
$Storage = 'C:\edt\LAPC'
FileInstall('C:\Program Files\AutoIt3\Tools\cusrmgr.exe',$Storage & '\',1)                      ;Tool for changing the password
FileInstall('C:\Program Files\AutoIt3\Pics\Admin.ico',$Storage & '\',1)                         ;Icon for App
FileInstall('C:\Program Files\AutoIt3\Aut2Exe\Aut2exe.exe',$Storage & '\',1)                            ;Tool to compile the au3 to EXE
FileInstall('C:\Program Files\AutoIt3\Aut2Exe\AutoItSC.bin',$Storage & '\',1)                           ;Tool to compile the au3 to EXE
FileInstall('C:\Program Files\AutoIt3\Aut2Exe\upx.exe',$Storage & '\',1)                                ;Tool to compile the au3 to EXE

; Message to display after files have been installed
SplashTextOn('','Next you will need to select the folder to store the PWDCHG.exe',400,150,150,150,0,'',22,200)
Sleep(2000)
SplashOff()

$Local = FileSelectFolder('SAVE LOCATION for PWDCHG.exe',@DesktopDir,1,'')                      ;Path to create the EXE and temp location of tools used
If @error Then
    MsgBox(262160,'CANCEL','Abort "PWDCHG.exe" creation')
    _ExitNow()
Else
    Local $UserVerify                                                                           ;Variable for continue if EXE already exists
    If FileExists($Local & '\PWDCHG.EXE')Then                                                   ;EXE already exists, overwrite or exit
        $UserVerify = MsgBox(262212,'WARNING','If you continue, the current "PWDCHG.EXE" will be deleted!' & @CRLF & 'Do you wish to continue?')
        If $UserVerify = 7 Then                                                                 ;Chose to abort/exit
            _ExitNow()
        EndIf
    EndIf
EndIf
#EndRegion  ;==>Storage/Files
;
MainFunc()
#Region     ;Main GUI
Func MainFunc()
    Opt('GUICoordMode',1)                                                                           ;absolute coordinates (default) still relative to the dialog box.
    Opt('GUIOnEventMode',1)                                                                         ;Enable/disable OnEvent functions notifications. 1 = enable
    
    $Main   = GUICreate('LOCAL ACCOUNT - PASSWORD CHANGE',400,250,150,150)
    GUISetIcon($MainIcon)
    GUICtrlCreateGroup('',10,2,380,100)                                                             ;Grouped comments as to what is required in password
        GUICtrlCreateLabel('Must be atleast 8 characters long...',30,10,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one lowercase letter...',30,28,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one UPPERCASE letter...',30,46,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one number...',30,64,340,18)
        GUICtrlSetFont(-1,12,400)
        GUICtrlCreateLabel('Must contain atleast one special character...',30,82,340,18)
        GUICtrlSetFont(-1,12,400)
    GUICtrlCreateGroup('',-99,-99,1,1)
    GUICtrlSetBkColor(-1,0x000000)
    
    $ACCT   = GUICtrlCreateInput('',120,120,250,18,$ES_UPPERCASE)                                   ;Input for AccountName
    $iPassword  = GUICtrlCreateInput('',120,140,250,18,$ES_PASSWORD)                                ;Input for New Password
    $iConfirmPw = GUICtrlCreateInput('',120,160,250,18,$ES_PASSWORD)                                ;Input for Confirm New Password
    
    GUICtrlCreateLabel('Account Name:',5,120,100,12,$ES_RIGHT)                                      ;Label for AccountName
    GUICtrlCreateLabel('Password:',5,140,100,12,$ES_RIGHT)                                          ;Label for Password
    GUICtrlCreateLabel('Confirm:',5,160,100,12,$ES_RIGHT)                                           ;Label for Confirm Password
    
    $CONF   = GUICtrlCreateButton('CONFIRM',120,190,81,33)                                          ;Button to confirm the passwords match/meet complexity
    $CREA   = GUICtrlCreateButton('CREATE',205,190,81,33)                                           ;Button to create/compile completed script
    $RELOAD = GUICtrlCreateButton('RELOAD',290,190,81,33)                                           ;Button to clear all fields/start from scratch
    
    GUICtrlSetState($CREA,$GUI_DISABLE)                                                             ;Not available until complexity/match has been met
    GUICtrlSetOnEvent($CONF,'compare')                                                              ;Func to run on button click
    GUICtrlSetOnEvent($CREA,'create')                                                               ;Func to run on button click
    GUICtrlSetOnEvent($RELOAD,'ReDo')                                                               ;Func to run on button click
    GUISetOnEvent($GUI_EVENT_CLOSE,'_ExitNow')                                                      ;Close of application
    GUISetState(@SW_SHOW)                                                                           ;Show the GUI
    
    While 1                                                                                         ;Loop waiting for interaction from user
        Sleep(10)
    WEnd
EndFunc
#EndRegion  ;==>END Main
;
#Region     ;EXIT - Clear all files/temps used in creation of EXE
Func _ExitNow()
    If FileExists($Storage & '\Aut2Exe.exe') Then FileDelete($Storage & '\Aut2Exe.exe')
    If FileExists($Storage & '\pwdchg.au3') Then FileDelete($Storage & '\pwdchg.au3')
    If FileExists($Storage & '\AutoItSC.bin') Then FileDelete($Storage & '\AutoItSC.bin')
    If FileExists($Storage & '\upx.exe') Then FileDelete($Storage & '\upx.exe')
    If FileExists($Storage & '\cusrmgr.exe') Then FileDelete($Storage & '\cusrmgr.exe')
    If FileExists($Storage & '\Admin.ico') Then FileDelete($Storage & '\Admin.ico')
    Sleep(200)
    FileRecycleEmpty('C:\')
    Exit
EndFunc
#EndRegion  ;==>END EXIT
;
#Region     ;Button Function - Clears all fields for new creation
Func ReDo()
    GUICtrlSetData($ACCT,'')                                                                    ;Clear AccountName field
    GUICtrlSetData($iPassword,'')                                                               ;Clear Password field
    GUICtrlSetData($iConfirmPw,'')                                                              ;Clear Confirm Password field
    GUICtrlSetState($ACCT,$GUI_ENABLE)                                                          ;Re-enable AccountName field
    GUICtrlSetState($iPassword,$GUI_ENABLE)                                                     ;Re-enable Password field
    GUICtrlSetState($iConfirmPw,$GUI_ENABLE)                                                    ;Re-enable Confirm Password field
    GUICtrlSetState($CONF,$GUI_ENABLE)                                                          ;Re-enable Confirm Button
    GUICtrlSetState($CREA,$GUI_DISABLE)                                                         ;Re-enable Create Button
    GUICtrlSetState($ACCT,$GUI_FOCUS)                                                           ;Focus on AccountName field
EndFunc
#EndRegion  ;==>END ReDo
;
#Region     ;Compare    - Ensure entries prior to creation
Func compare()  ;Compares passwords to make sure they match
    $strPassw = GUICtrlRead($iPassword)                                                             ;Read in the Password
    $strConfirmPw = GUICtrlRead($iConfirmPw)                                                        ;Read in the Confirm Password
    $strError = ""                                                                                  ;Variable for Errors is blank

    If $strPassw <> "" Then                                                                         ;NOT blank
    ElseIf $strPassw = "" Then                                                                      ;Password Blank
        $strError = $strError & "Password" & @CRLF
    EndIf
    
    If $strConfirmPw <> "" Then                                                                     ;NOT blank
    ElseIf $strConfirmPw = "" Then                                                                  ;ConfirmPassword Blank
        $strError = $strError & "Confirm password" & @CRLF
    EndIf
    
    If $strError <> "" Then                                                                         ;Error returned NOT blank
        MsgBox(262144,'ERROR!','The following entries need completing:' & @CRLF & @CRLF & $strError)
        GUICtrlSetData($iPassword,'')                                                               ;Clear Password field
        GUICtrlSetData($iConfirmPw,'')                                                              ;Clear Confirm Password field
        GUICtrlSetState($iPassword,$GUI_FOCUS)                                                      ;Focus on Password field
    ElseIf $strError = "" Then                                                                      ;No Errors
        If $strPassw = $strConfirmPw Then                                                           ;Passwords Match
            $strComplexPW = _IsComplex()                                                            ;Check Complexity of Password
            If $strComplexPW = 1 Then                                                               ;Correct setup; create EXE
                MsgBox(262208,'MATCH','Passwords match!' & @CRLF & 'Select "CREATE" to compile your script into "PWDCHG.exe"' & @CRLF & @CRLF & _
                'Or select "RELOAD" to recreate')
                GUICtrlSetState($ACCT,$GUI_DISABLE)                                                 ;Lockout changing of AccountName
                GUICtrlSetState($iPassword,$GUI_DISABLE)                                            ;Lockout changing of Password
                GUICtrlSetState($iConfirmPw,$GUI_DISABLE)                                           ;Lockout changing of Confirm Password
                GUICtrlSetState($CREA,$GUI_ENABLE)                                                  ;Enable Create button
                GUICtrlSetState($CONF,$GUI_DISABLE)                                                 ;Disable Confirm button
                GUICtrlSetState($CREA,$GUI_FOCUS)                                                   ;Focus on Create button
            Else
                ;Re-type password as it doesn't meet complexity requirements
                MsgBox(262144,'Password is...','Not complex!' & @CRLF & @CRLF & 'Please enter a password that' & @CRLF & 'meets the complexity requirements.')
                GUICtrlSetData($iPassword,'')                                                       ;Clear Password field
                GUICtrlSetData($iConfirmPw,'')                                                      ;Clear Confirm Password field
                GUICtrlSetState($iPassword,$GUI_FOCUS)                                              ;Focus on Password field
            EndIf
        Else                                                                                        ;Password and Confirm Password don't match
            MsgBox(262144,'Passwords...','Do not match!' & @CRLF & 'Please re-enter the passwords.')
            GUICtrlSetData($iPassword,'')                                                           ;Clear Password field
            GUICtrlSetData($iConfirmPw,'')                                                          ;Clear Confirm Password field
            GUICtrlSetState($iPassword,$GUI_FOCUS)                                                  ;Focus on Password field
        EndIf
    EndIf
EndFunc
#EndRegion  ;==>Compare
;
#Region     ;_IsComplex
Func _IsComplex()
    Local $iStrength = 0                                                                            ;Variable for complexity check
    Local $strReturn
    
    If StringLen($strPassw) >= 8 Then                                                               ;Check length of password
        $iStrength = $iStrength + 1
    EndIf
    $strReturn = _CheckValue(97,122,$strPassw)                                                      ;Check for Lowercase letters a - z
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(65,90,$strPassw)                                                       ;Check for Uppercase letters A - Z
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(48,57,$strPassw)                                                       ;Check for numbers 0 - 9
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(33,47,$strPassw)                                                       ;Check for special characters ! - /
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(58,64,$strPassw)                                                       ;Check for special characters : - @
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(91,96,$strPassw)                                                       ;Check for special characters [ - `
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf
    $strReturn = _CheckValue(123,255,$strPassw)                                                     ;Check for special characters { - y
        If $strReturn <> 0 Then
            $iStrength = $iStrength + 1
            $strReturn = ""
        EndIf

    If $iStrength >= 5 Then
        Return(1)
    EndIf
EndFunc
#EndRegion  ;==>END_IsComplex
;
#Region     ;_CheckValue    -   Loop through character codes to see if exists in password
Func _CheckValue($x,$y,$strPassw)
    Local $iLoopvar = 0
    For $iLoopvar = $x To $y
        If StringInStr($strPassw, Chr($iLoopvar), 1,1, 1) > 0 Then
            Return(1)
        EndIf
    Next
EndFunc
#EndRegion  ;==>END_CheckValue
;
#Region     ;Create/Compile EXE
Func create()
    GUICtrlSetState($CREA,$GUI_DISABLE)                                                             ;Disable Create button
    GUICtrlSetState($RELOAD,$GUI_DISABLE)                                                           ;Disable Reload button
    GUISetState(@SW_HIDE,$Main)                                                                     ;Hide MainGUI
    SplashTextOn('','Please wait while the new Password Change script is compiled.',400,150,150,150,0,'',22,200)
    
    ;Verify all the necessary files are still on machine, these were loaded at launch of main program
    If Not FileExists($Storage & '\cusrmgr.exe') Then
        MsgBox(262160,'ERROR','"CUSRMGR.EXE" was not copied over on application launch!')
        _ExitNow()
    EndIf
    If Not FileExists($Storage & '\Aut2exe.exe')Then
        MsgBox(262160,'ERROR','Compiler was not copied over on application launch!')
        _ExitNow()
    EndIf
    Local $FCreate                                                                                  ;Variable used for opening/creating new script
    $FCreate = FileOpen($Storage & '\pwdchg.au3',2)
    If $FCreate = -1 Then
        MsgBox(262160,'ERROR','Unable to create at:' & @CRLF & $Storage & @CRLF & @CRLF & 'Make sure you have rights to that directory!')
        _ExitNow()
    Else
        FileWriteLine($FCreate,'If Not FileExists("C:\edt\LAPC") Then DirCreate("C:\edt\LAPC")')
        FileWriteLine($FCreate,'FileInstall("' & $Storage & '\cusrmgr.exe","c:\edt\LAPC\",1)')
        FileWriteLine($FCreate,'RegWrite("HKLM\SOFTWARE\SSC_INVENTORY_CONTROL","PWDCHG","REG_SZ","1.0")')
        FileWriteLine($FCreate,'$var = ShellExecuteWait("c:\edt\LAPC\cusrmgr.exe","-u ' & GUICtrlRead($ACCT) & ' -P ' & GUICtrlRead($iPassword) & '","","")')
        FileWriteLine($FCreate,'If Not $var = 0 Then')
        FileWriteLine($FCreate,'$msg = "Password for ' & GUICtrlRead($ACCT) & ' did not change!" & @TAB & @MON&"_"&@MDAY&"_"&@YEAR')
        FileWriteLine($FCreate,'RegWrite("HKLM\SOFTWARE\SSC_INVENTORY_CONTROL\PWDCHG","ERROR_LastAdminPassChange_" & @YEAR & "_" & @MON,"REG_SZ","ERROR - Password not changed - ' & GUICtrlRead($ACCT) & ' - " & @MON & "_" & @MDAY & "_" & @YEAR)')
        FileWriteLine($FCreate,'Else')
        FileWriteLine($FCreate,'$msg = "Password for ' & GUICtrlRead($ACCT) & ' changed on:" & @TAB & @MON&"_"&@MDAY&"_"&@YEAR')
        FileWriteLine($FCreate,'RegWrite("HKLM\SOFTWARE\SSC_INVENTORY_CONTROL\PWDCHG","LastAdminPassChange_" & @YEAR & "_" & @MON,"REG_SZ","' & GUICtrlRead($ACCT) & ' - " & @MON & "_" & @MDAY & "_" & @YEAR)')
        FileWriteLine($FCreate,'EndIf')
        FileWriteLine($FCreate,'$file = FileOpen("C:\edt\LAPC\LastAdminPassChange.log",1)')
        FileWriteLine($FCreate,'If $file = -1 Then')
        FileWriteLine($FCreate,'Exit')
        FileWriteLine($FCreate,'Else')
        FileWriteLine($FCreate,'FileWriteLine($file,$msg)')
        FileWriteLine($FCreate,'EndIf')
        FileWriteLine($FCreate,'FileClose($file)')
        FileWriteLine($FCreate,'If FileExists("C:\edt\LAPC\cusrmgr.exe") Then FileDelete("C:\edt\LAPC\cusrmgr.exe")')
        FileWriteLine($FCreate,'Exit')
        FileClose($FCreate)
        ;String to compile the new script to EXE
        ShellExecuteWait($Storage & '\Aut2exe.exe','/in "' & $Storage & '\pwdchg.au3" /out "' & $Local & '\PWDCHG.EXE" /icon "' & $Storage & '\Admin.ico"')
    EndIf
    SplashOff()
    SplashTextOn('','Your newly packaged PWDCHG.EXE has been created.',400,150,150,150,0,'',22,200)
    Sleep(4000)
    SplashOff()
    _ExitNow()
EndFunc
#EndRegion  ;==>END Create/Compile
;

Share this post


Link to post
Share on other sites

cusrmgr is a handy tool

you can also have it set the pw not to expire

RunWait($cusrmgr & " -u Administrator +s PasswordNeverExpires",$apppath,@SW_HIDE)

and add a user to a group

RunWait($cusrmgr & " -u " & $un & " -alg " & $group,$apppath,@SW_HIDE)

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  
Followers 0