Jump to content
Sign in to follow this  
kjpolker

ShellExecute to loacate a file ANYWHERE?

Recommended Posts

kjpolker

I want to be able to launch an executable file with autoit no matter where it is, in other words will search entire computer for it.

I tried using the ShellExecute('PROGRAMNAME') command however the program I want to start is on a different partition on my hard drive, it is in Drive D: instead of C: I was looking for a way to be able to open up from different drives but making it universal like. I don't want to actually specify where the program is so if I am on the D: drive as my main drive (therefore it would really be c:) it can still locate the file, or if a friend had the programmed buried in some random drive (like f:) than it can STILL locate the program. Is this possible? Or do I absolutly have to tell it where the executable file is?

Share this post


Link to post
Share on other sites
Richard Robertson

You need to tell it where the program is. If it were to search the hard drive, you could accidentally run the wrong program if you had two "program.exe" files.

Share this post


Link to post
Share on other sites
kjpolker

Than how is it capable of running on other computers than mine? Like if I took this to my friends and ran it his username would obviously be his name and not mine, therefore creating an error of "unable to find x" Is it same with pictures? Loading a picture into a GUI.

Share this post


Link to post
Share on other sites
omikron48

Just use an ini file to store the program path so you don't have to recompile your script to cater to different program locations. Either that, or you can just take the program path in as a commandline parameter.

Share this post


Link to post
Share on other sites
Mison

Hi,

You can use a macro.. http://www.autoitscript.com/autoit3/docs/macros.htm

For example, this script will open Downloads folder in the current user's My Documents folder..

ShellExecute(@MyDocumentsDir&"\Downloads")
Edited by Mison

Hi ;)

Share this post


Link to post
Share on other sites
kjpolker

Hi,

You can use a macro.. http://www.autoitscript.com/autoit3/docs/macros.htm

For example, this script will open Downloads folder in the current user's My Documents folder..

ShellExecute(@MyDocumentsDir&"\Downloads")

Well after thinking about it I decided my best bet would be to somehow make a browse button where the user would need to locate the application and it would than save this for everytime he started up, now all I can guess is that I make a browse button (easy) somehow make that browse button link to an actual browsing window, and when he locates to the application in than takes the path of it and writes it to an ini file. than the program just opens the file based on the path written in the ini. Can I please get a example or two of this since I have never ever written an ini =/ I would very much appreciate anything at all. Thanks

Share this post


Link to post
Share on other sites
Mison

To select than save...

$var1 = FileOpenDialog ( "Select application", "", "Exe (*.exe)" )
IniWrite ( "config.ini", "App" , "Test" , $var1 )

to open and read from ini:

$var1 = IniRead("config.ini", "App", "Test", "NotFound")
MsgBox(4096, "Result", $var1)

To run an app without save/read from ini...

$var1 = FileOpenDialog ( "Select application", "", "Exe (*.exe)" )
Run($var1)

Hi ;)

Share this post


Link to post
Share on other sites
TurionAltec

Check the help file for iniread and iniwrite examples.

If the application in question is an installed application, check the registry to see if it stores the program location. For example, Office 2003 stores it's location in:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot

Share this post


Link to post
Share on other sites
omikron48

#include <Misc.au3>
_Singleton("AutoIt Automated Script")
Opt("MustDeclareVars", 1)
HotKeySet("{PAUSE}", "_Close")
Func _Close()
    Exit
EndFunc
Func _ControlClick($title, $text, $controlID)
    WinWait($title, $text)
    WinActivate($title, $text)
    Sleep(200)
    ControlClick($title, $text, $controlID)
EndFunc

Global $ininame = "_install_7zip_4-65.ini"
Global $section = "Options"
If Not FileExists($ininame) Then
    IniWrite($ininame, $section, "Path", ".\7zip 4.65\7zip_4-65.exe")
    Exit
EndIf

Global $exec = IniRead($ininame, $section, "Path", ".\7zip 4.65\7zip_4-65.exe")

If $CmdLine[0] == 1 Then
    $exec = $CmdLine[1]
EndIf

Run($exec)
If Not @error Then
    _ControlClick("7-Zip 4.65 Setup ", "Choose Install Location", "[TEXT:&Install]")
    _ControlClick("7-Zip 4.65 Setup ", "7-Zip 4.65 has been installed on your", "[TEXT:&Finish]")
    WinWaitClose("7-Zip 4.65 Setup ", "7-Zip 4.65 has been installed on your")
EndIf

The resulting ini file this generates and uses contains:

[Options]
Path=.\7zip 4.65\7zip_4-65.exe

IMO, you don't need to make a GUI to set the program path for your script. Just make an ini file and just edit it directly whenever you want it to point to a different location.

BTW, I use the script posted above to install 7zip 4.65 on Windows machines. The parts you're interested in are the IniWrite and IniRead.

EDIT: Wow, two replies already. My copy/pasta skills are slow...

Edited by omikron48

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  

×