Shell, Application.StartupPath

  • 14 years ago

    Using VB.NET 2005.....

    I have the following line:

    Shell (Application.StartupPath + "PrintLog.exe", AppWinStyle.NormalFocus) (swapping the + for & does not change the fact the file cant be found)

    VB tells me that the file is not found, but I put PrintLog.exe in the same folder as my vbproj project file.

    Why wont it run PrintLog.exe?

    If I write it out like this:

    Shell ("""C:\Documents And Settings\Jay\Desktop\Game\PrintLog.exe""", AppWinStyle.NormalFocus)

    This version of the code will run with no problems.

    However, I need it to accept Application.StartupPath so that the two exe's can be used on any pc and App A is not trying to find App B through a filepath that exists on my pc. Otherwise I'd have to rename every computer I want to use it on as "Jay"

    Can someone please tell me what I did wrong?

    thanks

  • 14 years ago
    You should always step through your code to see what the trouble is.  Make sure variables are what they should be and functions return what you expect them to.  In this case application.startuppath returns a string like this "c:\mystartdirectory"...Notice there is no "\" at the end which is why you are having the problem.  You should use application.startuppath & "\PrintLog.exe".  Hope that helps.
  • 14 years ago

    You should use Process.Start instead of Shell and use IO.Path.Combine to combine paths, which will add a separator character if and only if required:

    Process.Start(IO.Path.Combine(Application.StartupPath, "PrintLog.exe"))

    Having said that, the advice previously given was completely sound.  You would have found the issue there in about half a second if you'd debugged.  In fact, the error message would have even showed you the path it was looking for.  Had you taken the time to read that you'd have seen that the path was wrong.





  • 14 years ago

    whoa, slow down jmcilhinney you dont have to sound so rough. So I'm not the best at this, please forgive me for trying to learn from my mistakes.

    As suggested  in the previous post I did change the line of code to:

    Shell(Application.StartupPath &

    "\PrintLog.exe", AppWinStyle.NormalFocus)

    This line still gets highlighted and I still get the error File Not Found. FileNotFound Exception was unhandled. It shows no path or nothing .... it gives me 3 options to choose from: 1) Verify that the file exists in the specified location 2) When using relative paths, make sure the current directory is correct 3) Get general help for this exception.

    the only thing the debugger shows me the value of is AppWinStyle ... when I put my mouse over AppWinStyle.NormalFocus it shows AppWinStyle.NormalFocus 1.

    I have read the documentation on this and I do not understand why it will not work. So take it easy, you didn't need to lash out at me like I'm 4 years old. I would not have posted here if I have not tried myself more than once to fix the error.

    I will try your suggestion Process.Start and see what that does.

  • 14 years ago

    Might I suggest you make the following changes to your code.  First comment out the current line you have that is generating an error.  Then just before it or after it type the following:

    msgbox(application.startuppath & "\PrintLog.exe")

    By displaying the application.startuppath in a msgbox you'll know exactly what your getting from it.  This way you can rule out the possibility that the path you are passing to shell is incorrect.

    The reason I think the path may be wrong is what you said here "VB tells me that the file is not found, but I put PrintLog.exe in the same folder as my vbproj project file.".  If you are running your application in debug mode the the startup path probably isn't the same as the vbproj file.  It's actually in the debug folder under bin.  At least that's where my application starts from when I'm in debug mode.

  • 14 years ago

    you were right TwoFaced!

    when I test out the path with the msgbox it returns the value

    "C:\Documents And Settings\Blaknite\Desktop\Game\bin\PrintLog.exe"

    I have now put a copy of PrintLog.exe there and everything runs smoothly now :)

    I am still learning how VB.Net works, I did not know that VB.Net ran the program from another location.

    LOL, sometimes I get the feeling I should have stuck with VB6.

    I took college lessons for VB6, guess I need to go back and learn VB.Net! :D

     

  • 14 years ago

    I'm right there with you as far as learning vb.net.  I just take it a day at a time.  I think you'll be very happy you didn't stick with vb6.  The only peace of advice I can give is don't take anything for granted.  When something isn't working right check those variables.  Never assume values are what they should be or what you think they are.

  • 14 years ago

    Well I am definitely impressed with .Net and plan to stay with it that's for sure. I am pleased that .Net provides controls I only wish I had in VB6 rather than having to go off and make my own or trying to hunt them down if someone else made them and put them somewhere on the net for public use.

    I also feel that the code windows provide better error help than compared to VB6. I like the fact that it has an idea of what I tried to do and I can click a code correction that it suggests :)

    All in all , Good Stuff!

    Again, thanks for the help!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth