Jump to content

beginer ShellExecute


Recommended Posts

HI

Is It possible to (run) application from the (inputbox) without filename ?How?? :)

I can open only the folder. Try this one please.

#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <Array.au3>

#region ### START Koda GUI section ### Form=c:\users\el-zaeem\desktop\backup\bacckup form.kxf
$Form1_1 = GUICreate("input", 407, 360, 230, 132)
$path_source = GUICtrlCreateInput("", 72, 43, 497, 21)
$browes_source = GUICtrlCreateButton("", 17, 40, 49, 41, $WS_GROUP)
$exit = GUICtrlCreateButton("exit", 17, 160, 49, 41, $WS_GROUP)
$shell = GUICtrlCreateButton("shell It", 17, 100, 49, 41, $WS_GROUP)
GUICtrlCreateLabel(" press It" , 20, 15)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $browes_source
            $file = FileOpenDialog("Select file", @ProgramFilesDir & "", "Application (*.exe)", 1 + 4)
            If @error Then
                GUICtrlSetData($path_source, "")
            Else
                $iconfile_to_use = $file
                $array = StringSplit($iconfile_to_use, '\', 1)
                $name = $array[$array[0]]
                $newname = StringReplace($name, ".exe", "")
                $hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
                _GUIImageList_AddIcon($hImage, $iconfile_to_use, 0, True)
                _GUICtrlButton_SetImageList($browes_source, $hImage, 4)
                GUICtrlSetData($path_source, $file)

            EndIf
        Case $shell
             ShellExecute("", "","$path_source","open",@SW_SHOWDEFAULT);This part is my problem.It is opening Just the folder.

        Case $exit

            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

You had the parameters for ShellExecute in the wrong order. Also, the quotes around $path_source aren't needed (turns it from a variable into a string), and the GUICtrlRead function needed to be used to get the data from that variable. The variable itself contains the Ctrl ID.

ShellExecute(GUICtrlRead($path_source), "","","open",@SW_SHOWDEFAULT);This part is my problem.It is opening Just the folder.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

  • Moderators

ussr,

Look at the first 3 parameters in your ShellExecute line:

ShellExecute("", "","$path_source",....

You should have:

filename   - The name of the file to run                                                      : You have "" so how does the function know what to run?
parameters - [optional] Any parameters for the program. Blank ("") uses none                  : Here your syntax is correct
workingdir - [optional] The working directory. Blank ("") uses the current working directory. : You have a literal string which is not a folder name

Basically AutoIt defaults to opening @WorkingDir (which you set by using FileOpenDialog) in Explorer as it has no idea what you are trying to do! ;)

So I recommend that you use the correct parameters - the function will then work. ;)

You can get the folder and executable name from the content of the input like this:

$sChoice = GUICtrlRead($path_source)
ShellExecute($sChoice, "", StringRegExpReplace($sChoice, "(^.*)\\(.*)", "\1"), "open", @SW_SHOWDEFAULT)

I hope that helps. :)

M23

Edit: Typnig!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

It still isn't quite right.

All you needed was

ShellExecute(GUICtrlRead($path_source))
The &"" just adds an empty string to the end which will have no effect at all.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

ussr,

You can use ProcessExists to get the PID - you can extract the process name from the full path like this:

$sProcessName = StringRegExpReplace($GUICtrlRead($path_source), "^.*\\", "")

I hope this helps. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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