Helpful Information
 
 
Category: Visual Basic Programming
Launching another exe from a different directory

I am trying to launch a separate executable in a controlled development environment using the Shell Function from a VB 6.0 application located in a different directory.

For discussion's sake, let me define a few items:

My VB application = MyVB.exe
My Target app = Target.exe

root
|
|_VBDir
|___MyVB.exe
|
|_TargetDir
|___Target.exe

Because this is a controlled dev environment, I cannot simply move MyVB.exe into the TargetDir; it must reside in a separate directory.

Normally, Shell works fine. However, this particular case, my Target.exe has relative links in it. When I run my app from my VBDir, all of the Target.exe's relative links are wrong and Target.exe barfs.

Does anyone know how to launch another executable from within a VB app where the "Start in" directory is correctly set to the Target.exe's?

Many thanks,
Steve

What is the exact command that you are using to execute the command with Shell()?

Here's the code. I've changed the exe & dir names to match my example above, but this is otherwise identical to what I run:

Dim RetVal
Dim MyPath

MyPath = "C:\TargetDir\Target.exe"

RetVal = Shell(MyPath, vbNormalFocus)

I think what you are looking for is SetCurrentDirectory (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemIODirectoryClassSetCurrentDirectoryTopic.asp)


Public Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long










privacy (GDPR)