Jump to content
Sign in to follow this  
lhk69

Change variables and Recompile

Recommended Posts

lhk69

Hi.

Im new and looking for some direction. I have a script, works fine. I have hard-codded username and password in the script. Id like the ability to have a menu option ("Edit Credentials") to change the variables in the script $UNAME and $PWORD and recomplie the script with these new values.

ALSO: Ideally, id like to have domain login access to even GET to the "Edit Credentials" menu option.

Here is my script.

;*********************** INCLUDES *******************************************
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <constants.au3>
#include <date.au3>
#include <Process.au3>
#include <String.au3>

;*********************** VARIABLES *******************************************
Global $mod_date = _NowDate()
Global $prog_ver = "1.1"
Global $ProgName = "Quota Functions"
Global $b = True
Global $DName = "noa"
Global $UName = "USERNAME"
Global $PWord = "PASSWORD"
Global $Temp_Dir = "C:\temp"

Go_Main_Gui()


;*********************** FUNCTIONS *******************************************

Func Go_Main_Gui()

    ;Construct Main GUI
    $Main_Form1 = GUICreate($ProgName, 300, 350, -1, -1)

        ;Create menu items
        $filemenu = GUICtrlCreateMenu("File")
            $newitem = GUICtrlCreateMenuItem("New", $filemenu)
            $saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
            $separator1 = GUICtrlCreateMenuItem("", $filemenu, 3)
            $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
        $editmenu = GUICtrlCreateMenu("Edit")
            $edititem = GUICtrlCreateMenuItem("Edit Credintials", $editmenu)
        $helpmenu = GUICtrlCreateMenu("Help")
            $helpitem = GUICtrlCreateMenuItem("Contents", $helpmenu)
            $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

        ;Create button controls
        $modify_button = GUICtrlCreateButton("Modify a Quota", 20, 15, 265, 50, 0)
        $list_button = GUICtrlCreateButton("List a quota", 20, 75, 265, 50, 0)
        $other_button = GUICtrlCreateButton("Other Quota Functions", 20, 135, 265, 50, 0)
        $exit_button = GUICtrlCreateButton("Exit", 20, 195, 265, 50, 0)

        GUISetState()

    ;Wait for an action from the GUI
    While 1
        $v_action= GUIGetMsg()
        Select
            Case $v_action= $GUI_EVENT_CLOSE Or $v_action= $exititem Or $v_action= $exit_button
                Exit

            Case $v_action= $Modify_button
                GUIDelete()
                Do_Modify()

            Case $v_action= $list_button
                GUIDelete()
                Do_List()

            Case $v_action= $edititem
                MsgBox(0, $ProgName, "Clicking this does NOTHING.....yet.")

            Case $v_action= $Other_button
                MsgBox(0, $ProgName, "Functions not yet implimented yet.")

            Case $v_action= $helpitem
                MsgBox(0, $ProgName, "Currently in development.")

            Case $v_action= $aboutitem
                MsgBox(0, $ProgName, "Written By: ME" & @CRLF & "     Version: " & $prog_ver & @CRLF & "    Created: 7/14/2011" & @CRLF & "    Modified: " & $mod_date)

            Case Else
                ;;;
        EndSelect
    WEnd
EndFunc   ;==>Go_Main_Gui

Func Do_Modify()

    $Mod_Form1 = GUICreate($ProgName, 500, 200, 192, 124)

    $Label1 = GUICtrlCreateLabel("Please provide the following information:", 20, 30, 326, 17)

    $Label2 = GUICtrlCreateLabel("Server:", 50, 65, 40, 17, $SS_RIGHT)
    $Input_Server = GUICtrlCreateInput("", 100, 65, 120, 20)

    $Label3 = GUICtrlCreateLabel("Path:", 50, 100, 40, 17, $SS_RIGHT)
    $Input_Path = GUICtrlCreateInput("", 100, 95, 200, 20)

    $Label4 = GUICtrlCreateLabel("Limit:", 50, 130, 40, 17, $SS_RIGHT)
    $Input_Limit = GUICtrlCreateInput("", 100, 125, 50, 20)

    $Button_Start = GUICtrlCreateButton("Start", 350, 40, 113, 40, $WS_GROUP)
    $Button_Cancel = GUICtrlCreateButton("Cancel", 350, 100, 113, 40, $WS_GROUP)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Go_Main_Gui()

            Case $Button_Cancel
                GUIDelete()
                Go_Main_Gui()

            Case $Button_Start
                $Q_Server = GUICtrlRead($Input_Server)
                $Q_Path = GUICtrlRead($Input_Path)
                $Q_Limit = GUICtrlRead($Input_Limit)

                MsgBox(0, $ProgName, "Parameters are:" & @CRLF & @CRLF & $Q_Server & @CRLF & $Q_Path & @CRLF & $Q_Limit)

                $pid = RunWait(@ComSpec & " /c " & "PsExec.exe \\" & $Q_Server & " -u " & $DName & "\" & $UName & " -p " & $PWord & " dirquota q m /PATH:" & $Q_Path & " /LIMIT:" & $Q_Limit, @WindowsDir, @SW_HIDE)

                ProcessWaitClose($pid)
                MsgBox(0, "Program returned with exit code:", $pid)

                If $pid = 0 Then
                    MsgBox(0, $ProgName, "Quota Successfully Modified." & @CRLF & @CRLF & $Q_Limit & @CRLF & $Q_Path & @CRLF & $Q_Limit)
                    Exit
                Else
                    MsgBox(0, $ProgName, "ERROR!!!!!   Program returned with an ERROR exit code:", $pid)
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Do_Modify

Func Do_List()

    $List_Form1 = GUICreate($ProgName, 500, 200, 192, 124)

    $v_Label_Info = GUICtrlCreateLabel("Please provide the following information:", 20, 30, 326, 17)

    $v_Label_Input_Server = GUICtrlCreateLabel("Server:", 50, 65, 40, 17, $SS_RIGHT)
    $v_Input_Server = GUICtrlCreateInput("SERVER", 100, 65, 120, 20)

    $v_Label_Input_Path = GUICtrlCreateLabel("Path:", 50, 100, 40, 17, $SS_RIGHT)
    $v_Input_Path = GUICtrlCreateInput("PATH", 100, 95, 200, 20)

    $Button_Start = GUICtrlCreateButton("Start", 350, 40, 113, 40, $WS_GROUP)
    GUICtrlSetState(-1,$GUI_FOCUS)
    $Button_Cancel = GUICtrlCreateButton("Cancel", 350, 100, 113, 40, $WS_GROUP)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Go_Main_Gui()

            Case $Button_Cancel
                GUIDelete()
                Go_Main_Gui()

            Case $Button_Start
                $v_Server = GUICtrlRead($v_Input_Server)
                $v_Path = GUICtrlRead($v_Input_Path)
                GUIDelete()

                MsgBox(0,"",DOS_Capture('PsExec.exe \\' & $v_Server & ' -u ' & $DName & '\' & $UName & ' -p ' & $PWord & ' dirquota q l /PATH:' & $v_Path))
                                Go_Main_Gui()
        EndSwitch
    WEnd
EndFunc   ;==>Do_List

Func DOS_Capture($Command_to_run)

        _RunDOS($Command_to_run & " >" & $Temp_Dir & "\RESULTS.DAT 2>&1")

        ;Find the error code
        $v_File = FileOpen($Temp_Dir & "\RESULTS.DAT",0)
        While 1
            $line_read = FileReadLine($v_file)
            If @error = -1 Then ExitLoop
            If StringInStr($line_read, "error code") then
                $error_code = StringTrimRight(StringRight($line_read, 2),1)
                if $error_code <> 0 then
                    MsgBox(0, "ERROR", "PsExec exited with an error" & @lf & @lf & "The Server or Path might be incorrect")
                    Go_Main_Gui()
                EndIf
            Endif
        Wend
        FileClose($v_File)

        ;If error code 0, then return results
        $v_File = FileOpen($Temp_Dir & "\RESULTS.DAT",0)
        $STD_OUT = FileRead($v_File)
        FileClose($v_File)
        FileDelete($Temp_Dir & "\RESULTS.DAT")

    Return $STD_OUT

EndFunc
Edited by lhk69

Share this post


Link to post
Share on other sites
BrewManNH

You can't recompile a compiled script, what you can do is use a file to hold the username and password, such as an ini file, and have the script change and read them from there. Or create a registry setting that does it the same way.


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

Share this post


Link to post
Share on other sites
lhk69

You can't recompile a compiled script, what you can do is use a file to hold the username and password, such as an ini file, and have the script change and read them from there. Or create a registry setting that does it the same way.

Brewman.

Is there NO way to "include" the .au3 file, write a change to it, then command line recompile it?

Im trying to encode username/password with domain admin rights. This CANNOT be hacked or have some ini file read.

Im new, sorry for being stupid. If there is some better way to encrypt the settings or whatever, please let me know. I respect your opinion.

Thanks.

Share this post


Link to post
Share on other sites
LurchMan

Look at _StringEncrypt() in the help file. You can encrypt it, store it into an ini file / registry key, then decrypt it as you pull it back in.

Helpful hint: You can also name your ini file with a different extension to confuse people - AutoIt won't care.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
lhk69

Im sorry. I just don’t "get" it. What purpose does writing the info out to the reg or encrypted ini file do for me? If im not understanging it, please explain it to me.

I need to hand this program out - compiled, with an hard coded user/password in it. Every so often, we need to change the user/pass. If I get hit by a bus and cant edit the .au3 script, id like there to be an alternative method of changing these variables in the program.

Cant I include the .au3 script, if the credentials need modified, copy it out to a temp dir, edit it, then re-compile it with a command line call. Then delete the au3 file I copied out??

Share this post


Link to post
Share on other sites
Blue_Drache

Store the .ini on a specific network location, or make a script that "calls home" looking for an updated version on the network. If an updated version is found, run an update routine and restart the program. It's what World of Warcraft does.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
LurchMan

To re-compile the script would require that you also include the main AutoIt exe along with the Compiler inside your script. Then you would have to have someway of restarting it after it has been "updated". This was is just messy and the same came be accomplished much cleaner and more efficiently using an INI file.

The purpose of using an INI file is a simplistic way to store dynamic variables that need to be changed outside of the script after it has been compiled.

I'm sorry if this still doesn't make sense, I'm not sure how else to explain it. If you haven't already, use the _StringEncrypt () function and look at what the encrypted text looks like. As far as my job is concerned (IT Admin) this encryption has been sufficient for storing passwords and such. Which is actually more secure than having a hard coded variable in the script, because you could use a hex editor to view the exe and it would be in plain text within it.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
BrewManNH

Im sorry. I just don’t "get" it. What purpose does writing the info out to the reg or encrypted ini file do for me? If im not understanging it, please explain it to me.

I need to hand this program out - compiled, with an hard coded user/password in it. Every so often, we need to change the user/pass. If I get hit by a bus and cant edit the .au3 script, id like there to be an alternative method of changing these variables in the program.

Cant I include the .au3 script, if the credentials need modified, copy it out to a temp dir, edit it, then re-compile it with a command line call. Then delete the au3 file I copied out??

If you include the script in your program, you'll need to also include the Aut2Exe program as well, otherwise you can't compile it. Including a domain admin's credentials in an autoit script, even a compiled one, is opening a security hole in your domain, unless it's encrypted. Even with it encrypted, it's going to be a security risk because the decrypt key is going to be in the script itself. Autoit scripts are not very secure so these credentials will not be secure.

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

Share this post


Link to post
Share on other sites
lhk69

Thank you both.

I do get it now. I have written some code to write out encrypted entried into an ini file.

I see where you were going with this.

Thanks again for the point in the right direction.

Share this post


Link to post
Share on other sites
pieeater

hashing is a much more appropriate way to do this rather than encrypting/decrypting.


[spoiler]My UDFs: Login UDF[/spoiler]

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  

×