Executing files from a small VB program

K

ketil

Im attempting to develop a small program that will act as a console for
private users.

Here they can add their favourite .exe files or whatever, with a path
and a program/game name. The program will then run whatever based on a
path.

Problem:
- When attempting this code as final to start the program
System.Diagnostics.Process.Start(), with the varibale or path inside
the clams, the files the .exe need to run are copied into the bin
folder and there is a windows error message (standard one).

My take is that the program attempts to start the program in the bin
folder instead of the folder where the .exe is located.

I've tried a number of codes ive found on the net, but they are all
incomplete, or are not meant to work in Visual Studio 7.x (usually
there are commands involved that are not present in VS, and so the tool
tells me to define them).

Any takers?
 
H

Herfried K. Wagner [MVP]

Here they can add their favourite .exe files or whatever, with a path
and a program/game name. The program will then run whatever based on a
path.

Problem:
- When attempting this code as final to start the program
System.Diagnostics.Process.Start(), with the varibale or path inside
the clams, the files the .exe need to run are copied into the bin
folder and there is a windows error message (standard one).

My take is that the program attempts to start the program in the bin
folder instead of the folder where the .exe is located.

Are you sure you are passing the complete path of the exectable file you
want to start to 'Process.Start'?

\\\
System.Diagnostics.Process.Start("C:\bla\foo.exe");
///
 
R

Razio

Here is two examples I hardcoded and tested just by running it alone:

Didn't work, like any other game i tried:
System.Diagnostics.Process.Start("C:\Program Files\Eidos\Hitman
Contracts\HitmanContracts.exe")

Neverwinter nights did'nt work either.

Worked:
System.Diagnostics.Process.Start("C:\Program Files\test.avi")

winrar and photoshop also worked...so im suspecting that it has
something to do with games :p ?
 
C

Chris Dunaway

I would suggest looking at the shortcuts for the games in question and
make sure that you are duplicating the correct path, the correct
command line arguments and also make sure that the current directory is
set correctly. Most shortcuts have a parameter called "Start In" which
may be required by some games.
 
R

Razio

Yeah, it think its the start in value aswell thats bugging me, could
any of you give me btn_click example of how I set all these parameters?
 
C

Chris Dunaway

It would be something like this using a ProcessStartInfo object:

Public Sub StartProcess()

Dim startInfo As New ProcessStartInfo("appname.exe")

startInfo.WorkingDirectory = "c:\whatever"
startInfo.Arguments = "command line arguments here"

Process.Start(startInfo)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top