View Full Version : Running an exe in the same directory
jason8
12-29-2005, 05:14 PM
I'm building my project as a web/email executable and I want to run an application in the same directory as that executable (whereever it is run from) when a user clicks a button.
I'm using this code but it doesnt seem to work.
File.Open("myapp.exe", "", SW_SHOWNORMAL);
Any help would be greatly appreciated.
Jason
yosik
12-29-2005, 08:37 PM
File.Open is to open a file. In order to run an exe, you need to use the File.Run action.
Good luck
Yossi
Daniel TM
12-29-2005, 08:45 PM
I'm building my project as a web/email executable and I want to run an application in the same directory as that executable (whereever it is run from) when a user clicks a button.
I'm using this code but it doesnt seem to work.
File.Open("myapp.exe", "", SW_SHOWNORMAL);
Any help would be greatly appreciated.
Jason
try this:
get_current_folder = Folder.GetCurrent();
run_myapp = File.Run("AutoPlay\\Docs\\myapp.exe", "", ""..get_current_folder.."", SW_SHOWNORMAL, false);
If you copy the script above and paste it into a button, once you click on that button your AutoPlay Application will run myapp.exe from the same folder your executable is.
Intrigued
12-29-2005, 09:11 PM
Take a look at my example I worked out for AMS 6 (works in AMS 6). It was even added to the Examples section for AMS 5:
http://www.indigorose.com/forums/showthread.php?t=11327
Or, here is the code:
--[[ NOTE: This function only works AFTER you Build (F7) the project!
The following function takes one argument (runexe = path and name of .exe)...
and returns one string (strPath = the path of...
the location of the .exe), NOT the temp ran-from location!
]]
function fnEXEOrigLoca(runexe)
resFile = File.Run(runexe, "", "", SW_SHOWNORMAL, false)
strCWF = Folder.GetCurrent()
strPath = String.Replace(_CommandLineArgs[1], "SFXSOURCE:", "", true)
return strPath;
end
-- An example "function call" (to use the function)
fnEXEOrigLoca(_DesktopFolder.."\\app_name.exe")
-- This Message box can be removed (it's just for visual feedback)
Dialog.Message("", strPath)
jason8
12-29-2005, 09:14 PM
get_current_folder = Folder.GetCurrent();
run_myapp = File.Run("AutoPlay\\Docs\\myapp.exe", "", ""..get_current_folder.."", SW_SHOWNORMAL, false);
Thanks for the help but trying to use that doesn't work either.
I've built a file called slideshow.exe in autoplay, and another file called player.exe. I dont want to put myapp.exe into slideshow's autoplay files.
I want slideshow.exe and myapp.exe to be in the same directory and a button in slideshow.exe to run myapp.exe.
Any suggestions?
Thanks again
Intrigued
12-29-2005, 09:19 PM
Jason, his code does not work because the Docs folder of the AMS project is not the home of the .exe at run-time. Please note my post below his (and one above your last post here). It shows you how to access the folder of the AMS .exe, again, at run-time. It works after you have built the project to a .exe.
Work with that code and you will find success, for sure.
:)
jason8
12-30-2005, 07:41 AM
When I run this code, it only wants to run something in the desktop folder, i've tried to work out how to run a file from the same directory, but it keeps failing and in the dialog box it shows just the name and path of the exe I am running and not the one I want to run.
function fnEXEOrigLoca(runexe)
resFile = File.Run(runexe, "", "", SW_SHOWNORMAL, false)
strCWF = Folder.GetCurrent()
strPath = String.Replace(_CommandLineArgs[1], "SFXSOURCE:", "", true)
return strPath;
end
-- An example "function call" (to use the function)
fnEXEOrigLoca(_DesktopFolder.."\\app_name.exe")
-- This Message box can be removed (it's just for visual feedback)
Dialog.Message("", strPath)
Any ideas?
jason8
12-30-2005, 08:07 AM
Figured it out now. Thank you.
local ncnt = Table.Count(_CommandLineArgs);
for n, cmline in _CommandLineArgs do
if (n == ncnt) then
strSFXmid = String.Mid(_CommandLineArgs[n], 11, -1); -- return string to right of SFXSOURCE:
strSFXApPath = String.SplitPath(strSFXmid).Drive..String.SplitPat h(strSFXmid).Folder;
Dialog.Message("Debug Only Notice", strSFXApPath);
File.Run(strSFXApPath.."\\myapp.exe", "", "", SW_SHOWNORMAL, false)
end
end
Intrigued
12-30-2005, 12:14 PM
Great Jason! I know that feeling of victory you have just felt, oh, it's addictive!
:D
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.