Results 1 to 9 of 9

Thread: Shell Command and App.Path

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Posts
    253

    Shell Command and App.Path

    Hello,

    I'm trying to invoke from my program another VB program that's in an EXE file using the Shell command. The problem is that this program needs to refer to an Access database using App.Path, and if I run it using Shell, it tries to refer to a different directory than the one it would refer if I run it by just clicking the file in the windows explorer. The result is that it can't find the database when I use Shell because it's in a different directory.

    How can I cause Shell not to change the directory or get the same result in another way?

    Thanks very much.

  2. #2
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    Suggestion:
    Change the current directory in the application executing "SHELL" to the same directory that the shelled program is in.
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Shell Command and App.Path

    Originally posted by Forest Dragon
    Hello,

    I'm trying to invoke from my program another VB program that's in an EXE file using the Shell command. The problem is that this program needs to refer to an Access database using App.Path, and if I run it using Shell, it tries to refer to a different directory than the one it would refer if I run it by just clicking the file in the windows explorer. The result is that it can't find the database when I use Shell because it's in a different directory.

    How can I cause Shell not to change the directory or get the same result in another way?

    Thanks very much.
    ok this sounds kinda of confusing.. but are you saying if you have 2 apps

    C:\appdir1\app1.exe
    C:\appdir2\app2.exe

    and in app1 you do
    shell "C:\appdir2\app2.exe"

    that it makes app2's app.path show "C:\appdir1"?????

  4. #4
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249

    Not exactly...

    What you do in the main program is this:

    VB Code:
    1. Dim sRemotePath as String
    2.  
    3. ' configure the sRemotePath to be the path of the shelled app
    4. sRemotePath = "C:\Remote App Path"
    5.  
    6. ' now change the current working directory
    7. ChDir = sRemotePath
    8.  
    9. ' now shell your app
    10. SHELL "My Remote App.EXE"


    I hope it works!
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Not exactly...

    Originally posted by PhilRob56
    What you do in the main program is this:

    VB Code:
    1. Dim sRemotePath as String
    2.  
    3. ' configure the sRemotePath to be the path of the shelled app
    4. sRemotePath = "C:\Remote App Path"
    5.  
    6. ' now change the current working directory
    7. ChDir = sRemotePath
    8.  
    9. ' now shell your app
    10. SHELL "My Remote App.EXE"


    I hope it works!
    what about if a 3rd party program is being used as well and changes the current directory.. you can't plan for that kind of stuff...

  6. #6
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    I agree.
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Posts
    253

    Unhappy

    PhilRob56:
    I have already tried something similar to your code and unfortunately it didn't work, but thanks anyway.

    kleinma:
    My problem is that the program invoked using the Shell command refers to an Access database using App.Path. If I run it by just clicking the file from the Windows Explorer, this path will be the real path of the file and so the database will be found because it was put there before. However, if I invoke it using the Shell command, the path that App.Path refers to is not the current path of the program and not the path of the database too, so it cannot be found.

    Does anyone have an idea?

  8. #8
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    Does the Shelled program support Command Line parameters? If so perhaps the path to the DB can be added to the Shell string....

    Also, I wonder what the App.Path is for the Shelled program. If we can find out what it defaults to when Shelled, then maybe there's a way to set it using the API.
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  9. #9
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249

    MS KB Article.

    I see that the ShellExecute API allows you to specify the default directory.

    Perhaps it's worth a look?

    http://support.microsoft.com/default...b;en-us;170918
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width