Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell Command and Working Directory - HELP!!!

Status
Not open for further replies.

bytehead

Programmer
Jul 12, 2001
25
US
I am using the Shell Command to execute an Executable file on disk. But even though I specify a specific path to the Executable file, the application is looking in a different directory for the supporting data files.

I want to to look in the directory specified when executing the Shell Command.

Shell "C:\SEE\Support\SeeDLLExec.exe", vbNormalFocus

It seems VB remembers the last directory selected though the open/save dialog boxes. I need some quick HELP, please!

Thanks,
Brian
 
Brian,

Are the supporting data files in the same folder as the application?

Do you have access to the source code for the application?




[gray]Experience is something you don't get until just after you need it.[/gray]
 
Yes, all supporting files are in the same directory.

The executable, created by someone else, needs an input file and its respective data files. All of which exist in the same directory where the Shell command calls the Executable.

In the application, I allow the user to go open a text file from anywhere on disk, and VB is keeping that location n memory and is also where it looks for the supporting files for the Execuatable. If I open the text file from the same directory as the Executable file, all work fine.

Please, HELP!!!
 
Would it help if you open an existing file within your source directory using:-

retval = Shell("C:\SEE\Support\SeeDLLExec.exe C:\SEE\Support\MYFILENAME", 1)

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Unfortunetely using the Shell command does not reset the last remembered Windows Directory that a file was opened or saved from.

I need to use something other then shell, but just as simple.
 
Nope... Another Try?

Application is too darn smart. Somehow I need to set directory, and ChDir does not work. It really can not be this hard...
 
Add a reference to the Windows Script Host Object Model, then try the following:
Code:
Public Sub vbRun(strCommand As String, Optional strFolder As String)
    With New WshShell
        With .CreateShortcut("dummy.lnk")
            .TargetPath = strCommand
            .WorkingDirectory = strFolder
            .Save
        End With
        .Run "dummy.lnk"
    End With
    Kill "dummy.lnk"
End Sub
 
Here was the fix. Thanks to strongm for putting me in the right direction. And I knew it was going to be an easy fix...

Add reference to Windows Script Host Object Model then added the following to my code.

Dim objExec As New WshShell
objExec.CurrentDirectory = App.Path
objExec.Run ("SeeDLLExec.exe")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top