Jump to content

Script with GUI which allows users to launch executable files in given directory


MattHiggs
 Share

Recommended Posts

Hey all.  So a month ago I helped some fellow scripters who needed a way to, from a pre-configured list of folders (in ini file), select a folder, list the contents in that folder, and then be able to launch a particular executable in that folder from an autoit GUI.  Having done something very similar already, I modified my code somewhat and provided him the following, and after updating it to get rid of the errors some encountered, I would like to share it here.  What this will allow you to do is, from the directory you have selected with the executables (can handle exe, zip, rar, 7z, and msi) you double click a selection, or select one or multiple files you want to install (or in the case of archive file extract), and if the file is an executable, will attempt to silently install the applications for you.  Msi files can easily be installed silently, but the exe files will be scanned with a signature detection app, determine the installer that the application uses, then if the installer has known silent installation parameters, will use them to silently install the executable, or just regularly launch it if not.  Here is the code and attached are the misc files you need.  Have a blast.

; *** Start added by AutoIt3Wrapper ***
#include <FileConstants.au3>
#include <ListBoxConstants.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Zip.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Region ### START Koda GUI section ### Form=c:\users\whiggs\onedrive\always script\form\openjv3.kxf
$Form1 = GUICreate("Install Launcher", 500, 593, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$MenuItem1 = GUICtrlCreateMenu("Add")
$MenuItem2 = GUICtrlCreateMenuItem("Folder", $MenuItem1)
$Label1 = GUICtrlCreateLabel("Pick your poison", 176, 16, 147, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$dumm = GUICtrlCreateDummy()
$Combo1 = GUICtrlCreateCombo("", 40, 56, 409, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE,$CBS_SORT,$WS_HSCROLL))
GUICtrlSetTip(-1, "Select the path you wish to view....")
$List1 = GUICtrlCreateList("", 24, 96, 449, 422, BitOR($LBS_NOTIFY, $LBS_MULTIPLESEL, $LBS_HASSTRINGS, $WS_VSCROLL, $WS_BORDER))
$Button1 = GUICtrlCreateButton("Run", 48, 536, 89, 33, $BS_NOTIFY)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("Exit", 360, 536, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
If Not FileExists ( @ScriptDir & "\settings.ini" ) Then
addPath()
Else
    $array2 = IniReadSection ( @ScriptDir & "\settings.ini", "settings" )
        Local $store2[$array2[0][0]]
        $here2 = 0
        For $i = 1 To $array2[0][0] Step 1
            GUICtrlSetData ( $Combo1, $array2[$i][1] )
        ;   $here2 += 1
        Next
        ;GUICtrlSetData ( $Combo1, $store2 )
EndIf
GUIRegisterMsg($WM_COMMAND, "doubleClick")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem2
            addPath()

        Case $Combo1
            _GUICtrlListBox_ResetContent ( $List1 )
            $use = GUICtrlRead ( $Combo1 )
            If Not FileExists ( $use ) Then
                #Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=None, Miscellaneous=Top-most attribute
MsgBox($MB_OK + 262144,"invalid path","the path you selected does not exist or is inaccessible on local device/using current user.")
#EndRegion --- CodeWizard generated code End ---
                Else


            GUICtrlSetState ( $Button1, 128 )
            GUICtrlSetStyle ($List1, BitOR($LBS_NOTIFY, $LBS_MULTIPLESEL, $LBS_HASSTRINGS, $WS_VSCROLL, $WS_BORDER))
            $thelist = _FileListToArrayRec ( $use, "*", Default, Default, $FLTAR_SORT, Default )
            For $i = 1 To $thelist[0] Step 1
                GUICtrlSetData ( $List1, $thelist[$i] )
            Next
                EndIf

        Case $List1
            $listselect = _GUICtrlListBox_GetSelItemsText ( $List1 )
            If $listselect[0] > 0 Then
                GUICtrlSetState ( $Button1, 64 )
            Else
                GUICtrlSetState ( $Button1, 128 )
            EndIf

        Case $Button1
            $listsel = _GUICtrlListBox_GetSelItemsText ( $List1 )
            For $f = 1 To $listsel[0] Step 1
                apps ($listsel[$f])
            Next

        Case $Button2
            Exit
    EndSwitch
WEnd

Func addPath ()
    If Not FileExists ( @ScriptDir & "\settings.ini" ) Then
    #Region --- CodeWizard generated code Start ---


;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
MsgBox($MB_OK + $MB_ICONASTERISK,"Select paths","You need to select some file share paths so program knows where to look")
#EndRegion --- CodeWizard generated code End ---
        $hold = 0
    Else
        $hold = IniReadSection ( @ScriptDir & "\settings.ini", "settings" )
    EndIf

    Do
        $init = FileSelectFolder ( "Select path to add", "" )
        If $init <> "" Then
            If IsArray ( $hold ) Then
                $hold[0][0] += 1
                IniWrite ( @ScriptDir & "\settings.ini", "settings", "path " & $hold[0][0], $init )
            Else
                $hold += 1
                IniWrite ( @ScriptDir & "\settings.ini", "settings", "path " & $hold, $init )
            EndIf

        EndIf
        #Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=None
If Not IsDeclared("continue") Then Local $continue
$continue = MsgBox($MB_YESNO,"More?","Are there any more you would like to enter?")
        Until $continue = $IDNO
        $array = IniReadSection ( @ScriptDir & "\settings.ini", "settings" )
        Local $store[$array[0][0]]
        $here = 0
        For $i = 1 To $array[0][0] Step 1
            GUICtrlSetData ( $Combo1, $array[$i][1] )
            ;$here += 1
        Next
        ;GUICtrlSetData ( $Combo1, $store )
    EndFunc

#EndRegion --- CodeWizard generated code End ---
Func doubleClick($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam
    Select
        Case $nID = $List1
            Switch $nNotifyCode
                Case $LBN_DBLCLK
                    $one = GUICtrlRead($List1)
                    If StringRight ( $one, 4 ) == ".exe" Or StringRight ( $one, 4 ) == ".msi" Or StringRight ( $one, 4 ) == ".zip" Or StringRight ( $one, 4 ) == ".rar" Or StringRight ( $one, 3 ) == ".7z" Then
                        apps ($one)
                    EndIf
            EndSwitch
    EndSelect
EndFunc

Func apps ($file)
    $filepath = GUICtrlRead ( $Combo1 )
    $setfile = $filepath & "\" & $file
    Select
            Case StringRight($setfile, 3) == "msi"
                RunWait(@ComSpec & " /c " & 'msiexec.exe /i ' & '"' & $setfile & '"' & ' /qb', "", @SW_HIDE)
            Case StringRight($setfile, 3) == "zip"
                Global $stringSPL = StringSplit($setfile, ".", $STR_NOCOUNT)
                _Zip_UnzipAll($setfile, @DesktopDir & "\short\" & $stringSPL[0], 532)
            Case StringRight($setfile, 3) == "rar"
                Local $rarsplit = StringSplit($setfile, ".", $STR_NOCOUNT)
                RunWait(@ComSpec & " /c " & 'unrar e "' & $setfile & '" "' & @DesktopDir & '\short\' & $rarsplit[0] & '\"', "C:\Program Files\WinRAR")
            Case StringRight($setfile, 2) == "7z"
                Local $7split = StringSplit($setfile, ".", $STR_NOCOUNT)
                RunWait(@ComSpec & " /c " & '7z x "' & $setfile & '" -o"' & @DesktopDir & '\short\' & $7split[0] & '\"', "C:\Program Files\7-Zip")
            Case StringRight($setfile, 11) == "application"
                ShellExecuteWait($setfile, "", $filepath)
            Case StringRight($setfile, 3) == "msu"
                RunWait(@ComSpec & " /c " & 'wusa.exe ' & $setfile & ' /quiet /norestart', "" )
            Case StringRight($setfile, 3) == "exe"
                        If Not FileExists (@ScriptDir & "\peid.exe") Then
                            FileInstall("C:\Users\whiggs\OneDrive\always script\mdt\PEiD.exe", @ScriptDir & "\peid.exe")
                        EndIf
                        Run ("peid.exe -hard " & '"' & $setfile & '"', @ScriptDir, @SW_HIDE )
                        WinWait ( "PEiD v0.95" )
                        $IDString= ControlGetText("PEiD v0.95", "", "[CLASS:Edit; INSTANCE:2]")
                        Do
                            Sleep (100)
                            $IDString= ControlGetText("PEiD v0.95", "", "Edit2")
                        Until ($IDString <>"Scanning...") And ($IDString <> "" )
                        WinClose ("PEiD v0.95")
                        $foundsomething = "n"
                        If StringInStr ($IDString, "Inno Setup") Then
                            RunWait ( @ComSpec & " /c " & '"' & $setfile & '"' & " /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-", "", @SW_HIDE )
                            $foundsomething = "y"
                        ElseIf StringInStr ( $IDString, "Delphi" ) Then
                            RunWait ( @ComSpec & " /c " & '"' & $setfile & '"' & " /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-", "", @SW_HIDE )
                            $foundsomething = "y"
                        ElseIf StringInStr ($IDString, "Wise") Then
                            RunWait ( @ComSpec & " /c " & '"' & $setfile & '"' & " /s", "", @SW_HIDE )
                        ElseIf StringInStr ($IDString, "Nullsoft") Then
                            RunWait ( @ComSpec & " /c " & '"' & $setfile & '"' & " /S", "", @SW_HIDE )
                        ElseIf StringInStr ($IDString, "Installshield 2003") Then
                            ;ShellExecuteWait ( $setfile, "/s /v /qb", $filepath )
                            RunWait ( @ComSpec & ' /c "' & $setfile & ' /s /v"/qb"', "", @SW_HIDE )
                        Else
                            RunWait ( @ComSpec & " /c " & '"' & $setfile & '"', "", @SW_HIDE )
                        EndIf
        Case Else
            Sleep (100)
    EndSelect
EndFunc

 

scriptb.jpg.5ecf3b55c09a139fa062ad2303cd7534.jpg

 

 

script.jpg.07b8d6e58e44f4e1dbd1b7d9a0fe0455.jpg

Zip.au3

peid.exe

Edited by MattHiggs
Link to comment
Share on other sites

  • 2 weeks later...

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...