vb.net running exe files

Discussion in 'MCAD / MCSD / MCPD' started by Cheeze, Apr 6, 2006.

  1. Cheeze

    Cheeze Bit Poster

    37
    0
    14
    As part of my training (training myself with books, slowly lol) I am trying to write a little app.

    In the app I am trying to launch an external program... which I have managed using shell, but the external program crashes due to a "wrong working directory" error. The program works fine when run normally, just not when executed from my app. Any ideas how I can set or define the working directory so the app runs fine from my prog?

    I am using Visual Basic 2005 btw

    Many thanks
     
    Certifications: An M.O.T.
    WIP: Hopefull MCAD and MCSD
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    I would guess that it depends on the app. Many apps can take a switch or parameter to define their working directory.

    Otherwise you can run a script that starts with a cd into that directory.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. Cheeze

    Cheeze Bit Poster

    37
    0
    14
    I'll have a try at that thanks!
     
    Certifications: An M.O.T.
    WIP: Hopefull MCAD and MCSD
  4. Cheeze

    Cheeze Bit Poster

    37
    0
    14
    No I'm struggling.

    Here's my code:

    Private Sub btnLaunchBF2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLaunchBF2.Click
    Dim BF2path As String

    BF2path = txtBF2path.Text

    If BF2path = "" Then
    MsgBox("Please select the location of BF2.exe!!!")
    Else

    Shell(BF2path)

    End If

    End Sub

    I need to make sure that the working directory for bf2.exe is set correctly, at the moment it's presuming that the program is running in the same folder as my app.
     
    Certifications: An M.O.T.
    WIP: Hopefull MCAD and MCSD
  5. d-Faktor
    Honorary Member

    d-Faktor R.I.P - gone but never forgotten.

    810
    0
    39
    is bf2path enclosed in quotes?
     
  6. Cheeze

    Cheeze Bit Poster

    37
    0
    14
    no but I have tried that.
     
    Certifications: An M.O.T.
    WIP: Hopefull MCAD and MCSD
  7. d-Faktor
    Honorary Member

    d-Faktor R.I.P - gone but never forgotten.

    810
    0
    39
    i'm no coder or developer, but i would think that simplification, elimination and deduction also apply to debugging scripts, just as they do to troubleshooting server problems. so have you tried stripping the script to its basics, to a working state, and then one by one adding more functions and variables?

    if i'm not mistaken, something like the following should already work on its own, right?

    shell ("drive\folder1\folder2\executable")

    if it does, you can take it from there, and add more to it piece by piece, each time running a test to see if it still works. you will encounter your problem soon enough.
     
  8. Cheeze

    Cheeze Bit Poster

    37
    0
    14
    Tried that too. Don't get me wrong, the file does run but whilst loading it encounters a working directory problem. The file runs fine normally though so I thought there must be someway of setting a working dir, I have seen stuff about it in the help files and by doing searches but nothing has come of it so far.

    I do appreciate your help though, I've always found everyone in these forums to be extremely patient and helpful.
     
    Certifications: An M.O.T.
    WIP: Hopefull MCAD and MCSD
  9. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    OK - I'll make a couple of suggestions, although I am not familiar with the script language.

    1) Investigate 'BF2' to see if it has switches or parameters to set the path.

    2) Try including the *full* path to the executable - that does it for some apps.

    3) Prepend a 'cd <blah>' to the system call as previously suggested.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  10. d-Faktor
    Honorary Member

    d-Faktor R.I.P - gone but never forgotten.

    810
    0
    39
  11. Cheeze

    Cheeze Bit Poster

    37
    0
    14
    d-Faktor was right, although he/she couldn't tell me the exact code, they were bang on with how to get it working. All I had to add was:

    ChDir("directory path here")

    Before executing the shell command.

    Thank you very much, I appreciate all your advice.
     
    Certifications: An M.O.T.
    WIP: Hopefull MCAD and MCSD

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.