Jump to content
Sign in to follow this  

Reading an Edit box and writing a modded output

Recommended Posts

Hi guys, brand new to the forum and brand new to AutoIt. I am a systems engineer and am very novice at scripting and I have put together a Frankenstein script to do the following:

Run an MSI on remote machine(s) silently. My method of doing this is basically scripting a GUI on top of this command in the DOS prompt: \\Filepath\PSTools\psexec \\(AssetID(s)) -u domain\fakeuser -p fakepassword msiexec /i "\\PathToMSI\sweetMSI.msi" /qb

The way I am doing this is having the user enter the AssetID(s), path to MSI, username, and password and using those variables in the following line of code:

Run(@ComSpec & " /c \\FilePath\PsTools\psexec \\"& $input1 &" -u "& $input2 &" -p "& $input3 &" msiexec /i "& $input4 &" /qf" & @CRLF, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)

My problem is this:

This command allows for multiple asset IDs to be used like this "\\Asset1,Asset2,Asset3 -u username etc...) I want to be able to take the user input from the Edit box I have where they enter AssetIDs separated by line breaks and then have them entered into the command with the syntax noted above. Here is the rest of my code so if it helps:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Region ### START Koda GUI section ### Form=
$MSIForm = GUICreate("Remote MSI Installer", 612, 394, 206, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 40, 161, 298, $ES_WANTRETURN + $WS_VSCROLL)
GUICtrlSetData(-1, "")
$CompName = GUICtrlCreateLabel("Enter Computer Names:", 16, 16, 116, 17)
$MSIPath = GUICtrlCreateInput("", 200, 40, 233, 21)
$User = GUICtrlCreateInput("", 200, 112, 121, 21)
$Pass = GUICtrlCreateInput("", 344, 112, 121, 21, $ES_PASSWORD)
$LabelU = GUICtrlCreateLabel("Username:", 200, 88, 55, 17)
$LabelP = GUICtrlCreateLabel("Password:", 344, 88, 53, 17)
$BrowseButton = GUICtrlCreateButton("Browse .msi...", 448, 40, 81, 25, $WS_GROUP)
$RunButton = GUICtrlCreateButton("Run", 504, 352, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Run the program")
$CloseButton = GUICtrlCreateButton("Close", 408, 352, 81, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Quit the program")
$Edit2 = GUICtrlCreateEdit("", 192, 152, 401, 185, $ES_WANTRETURN + $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_READONLY)
GUICtrlSetData(-1, "")
#EndRegion ### END Koda GUI section ###

Func main()

While 1
    $msg = GUIGetMsg()
        Case $msg = $GUI_EVENT_CLOSE or $msg = $CloseButton
        Case $msg = $BrowseButton
            $File2open = FileOpenDialog ("Browse...", "C:\", "MSI Installer (*.msi)") ;returns the file path
            GUICtrlSetData($MSIPath, $File2open)       ;set input data

If $msg = $RunButton Then RunButton()


Func RunButton()

$result= _CMDreturn(@CRLF)
GUICtrlSetData($Edit2, $result)


Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
Global $input1 = GUICtrlRead($Edit1)
Global $input2 = GUICtrlRead($User)
Global $input3 = GUICtrlRead($Pass)
Global $input4 = GUICtrlRead($MSIPath)
$cmdreturn = ""
    $stream = Run(@ComSpec & " /c \\FilePath\PsTools\psexec \\"& $input1 &" -u "& $input2 &" -p "& $input3 &" msiexec /i "& $input4 &" /qb" & @CRLF, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    Return $cmdreturn

As I said, I am a Systems Engineer, not a coder and I already know this code is probably very inefficient. Please be gentle :huh2:

EDIT: changed the code to reflect what I have.

Edited by chad57

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...