Sign in to follow this  
Followers 0
pancwk

run exe from parent directory

8 posts in this topic

I want to run a exe program from parent directory or parents parent directory.

how to run exe from parent directory?

Can anyone help me? Thanks!

Share this post


Link to post
Share on other sites



Check "Run" in the helpfile. Look at the working directory parameter.

Share this post


Link to post
Share on other sites

Check "Run" in the helpfile. Look at the working directory parameter.

actuaaly I did that before I ask the question.

I need an example on how to run an exe from parent directory. Thank you anyway.

can anybody give me an example?

Share this post


Link to post
Share on other sites

I am using ShellExecute for more parameters etc.

ShellExecute ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] )

filename The name of the file to run (EXE, .txt, .lnk, etc). 

parameters [optional] Any parameters for the program. Blank ("") uses none. 

workingdir [optional] The working directory. Blank ("") uses the current working directory. 

verb [optional] The "verb" to use, common verbs include:
  open = (default) Opens the file specified. The file can be an executable file, a document file, or a folder
  edit = Launches an editor and opens the document for editing. If "filename" is not a document file, the function will fail
  print = Prints the document file specified. If "filename" is not a document file, the function will fail
  properties = Displays the file or folder's properties 

showflag [optional] The "show" flag of the executed program:
  @SW_HIDE = Hidden window
  @SW_MINIMIZE = Minimized window
  @SW_MAXIMIZE = Maximized window

Good Luck


This world is crazy

Share this post


Link to post
Share on other sites

I am using ShellExecute for more parameters etc.

ShellExecute ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] )

filename The name of the file to run (EXE, .txt, .lnk, etc). 

parameters [optional] Any parameters for the program. Blank ("") uses none. 

workingdir [optional] The working directory. Blank ("") uses the current working directory. 

verb [optional] The "verb" to use, common verbs include:
  open = (default) Opens the file specified. The file can be an executable file, a document file, or a folder
  edit = Launches an editor and opens the document for editing. If "filename" is not a document file, the function will fail
  print = Prints the document file specified. If "filename" is not a document file, the function will fail
  properties = Displays the file or folder's properties 

showflag [optional] The "show" flag of the executed program:
  @SW_HIDE = Hidden window
  @SW_MINIMIZE = Minimized window
  @SW_MAXIMIZE = Maximized window

Good Luck

I succeeded by using:

ShellExecute ( "abc.exe" , "" , "../../" )

Thanks!!!

Share this post


Link to post
Share on other sites

You normally use ShellExecute when you want to open files with their associated program.

You use Run when you want to call programs directly.

Run("notepad.exe")
Run("notepad.exe", "C:\")

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey,

This function will return the parent directory (it's messy but it works right?), so all you need to do is call the _ParentDir() function on the WorkingDir parameter ;)

#include <Constants.au3>

ConsoleWrite(_ParentDir() & @CRLF)

Func _ParentDir()
    $iPID = Run(@ComSpec & " /c cd .. & cd", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $sOutput = "" & StdoutRead($iPID) & StderrRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return $sOutput
EndFunc   ;==>_ParentDir
Edited by JamesBrooks

Share this post


Link to post
Share on other sites

#cs ================================================================
    Heres my contribution to the topic, Fugly but functional ;)
    ================================================================
#ce;
ConsoleWrite(@SCRIPTFULLPATH & @LF)
ConsoleWrite("Parent Directory relative to script."& @LF & @TAB)
ConsoleWrite(_PathTrace() & @LF)
ConsoleWrite("As above but with trailing slash '\'."& @LF & @TAB)
ConsoleWrite(_PathTrace(1,0) & @LF)
ConsoleWrite("Parent of Parent directory."& @LF & @TAB)
ConsoleWrite(_PathTrace(2) & @LF)
ConsoleWrite(@AUTOITEXE & @LF)
ConsoleWrite("The directory of your exe/Interpreter."& @LF & @TAB)
ConsoleWrite(_PathTrace(0,1,@AUTOITEXE) & @LF)
ConsoleWrite("Parent directory relative to your exe/Interpreter."& @LF & @TAB)
ConsoleWrite(_PathTrace(1,1,@AUTOITEXE) & @LF)
ConsoleWrite("alternate directory delim '/' example."& @LF & @TAB)
ConsoleWrite(_PathTrace(2,1,"x:/bin/env/dev/AK47.exe",47) & @LF)
; Example, execute a program setting its working dir to the scripts parent directory
RunWait("CMD.exe /c TITLE Notice working dir? && CD && PAUSE",_PathTrace())
#cs ================================================================
 Trace backward in a path string and return the relative path.
    Depth ~ 1 = "..\" , 2 = "..\..\" etc
 Trail ~ Strip trailing delimeter? 1 = strip | 0 = keep
 RTarget ~ Full file path to extract a relative directory from.
 Delim ~ Ascii value to use as directory delimeter default is "\"
    ================================================================
#ce;
FUNC _PathTrace($Depth = 1,$Trail = 1,$RTarget = @SCRIPTFULLPATH,$Delim = 92)
RETURN StringLeft($RTarget,StringInStr($RTarget,Chr($Delim),0,-$Depth -1) - $Trail)
ENDFUNC

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  
Followers 0