Click to See Complete Forum and Search --> : Running a program via a remote program


StevDevil
February 26th, 2006, 02:41 PM
My program runs another program, which the user has to choose.
The problem is that the program which needs to be runned, needs other files (like dll files).
When my program is in another folder (e.g., my program is located at C:\Program Files\myprogram.exe, the targeted program is in D:\Program Files\targetedprogram.exe), the targeted program tries to find those dll files in C:\Program Files\ , but these files aren't there of course.
Any help how to let the targeted program look for his dll files in D:\Program Files ?

Please help!

jhammer
February 27th, 2006, 11:36 AM
I am assuming that the exe you are trying to run are .NET assemblies.
If that is true, then all the dlls must be in the same directory as the exe, or in the GAC (Placing Assemblies in the Global Assembly Cache (http://j1hammer.blogspot.com/2006/02/placing-assemblies-in-global-assembly.html)).
There are other advanced way of telling the exe the exact locations of dll (such as probing and code base, check out google).
Also check this: http://www.codeproject.com/dotnet/assemblydeployment.asp

StevDevil
February 27th, 2006, 11:54 AM
I thought of something like my program copying a small program into the targeted program's folder, is that possible?
That small program would then exec the targeted exe, including all other files.
Or maybe it can be done with a bat file?

(please give the command for execing a program in a bat file)

jhammer
February 27th, 2006, 03:33 PM
Use File.Copy to copy any file you need to the target folder.

In order to run the program:

Process.Start("C:\\1.exe"); // or whatever folder


If you wish to do it in a bat file:
You can run bat files the same way.

Maybe the bat file will look like this:

copy C:\SourcePath\file.exe C:\TargetPath
...
C:\\1.exe

StevDevil
February 27th, 2006, 03:44 PM
Thanks for the help, the problem's almost solved, but my question about the bat file was, what's the command in the bat file to run a program (like in my program its Process.Start), and is it possible to temporarly copy the bat file to the targeted folder, and when that program has started, remove the bat file again.

jhammer
February 28th, 2006, 01:59 AM
In order to start a program in a bat file you need to simply type the name of the exe. If you want you can include full path. You might want to include command line arguments.
For example:

notepad
copy x.bat C:\Target\y.bat

This will start notepad and copy a file.

You can use the word "start" if you wish to wait till the program finished before continueing.

notepad
start notepad
notepad

The third notepad will only run after the second one is closed.

Of course you can delete the batch file after it is finished (use File.Delete). If you try to delete the bat file when it is running you will get an exception.

exterminator
February 28th, 2006, 02:08 AM
IMO, a batch file is at least a collection of commands that you can run under command prompt (similar to the shell scripts that you have for unix). So, the commands that you need to run an application from command prompt can be put into that batch file and that file can be run on cmd prompt. If you don't want to set the whole path of the exe in the batch file - you may want to set the environment variable "path" for the application on windows. Regards.

StevDevil
February 28th, 2006, 03:30 AM
Of course you can delete the batch file after it is finished (use File.Delete). If you try to delete the bat file when it is running you will get an exception.

When does the batch file stop running: when all the commands are completed, or do I need a command like Quit to stop it?

exterminator
February 28th, 2006, 04:32 AM
Calling exit would exit the command prompt.. you can leave it to that.

StevDevil
February 28th, 2006, 04:53 AM
Thanks, almost done.
Only the very last questions:

how can I via .NET change the extension of a file? (because I will use streamwriter to creater a file program.txt, and rename it to program.bat)
Or can the streamwriter write as well in a .bat file?

And when you rightclick on a shortcut you can change the target (e.g. for the game Wolfenstein Enemy Territory, the game I make this program for I have this target, it also runs a mod (etpro) and an extra script (MasterScript.cfg): "C:\Program Files\En. Territory\ET.exe" set fs_game etpro + exec MasterScript.cfg

Can I do this with a batch file as well?

StevDevil
February 28th, 2006, 11:39 AM
Use File.Copy to copy any file you need to the target folder.

In order to run the program:

Process.Start("C:\\1.exe"); // or whatever folder


If you wish to do it in a bat file:
You can run bat files the same way.

Maybe the bat file will look like this:

copy C:\SourcePath\file.exe C:\TargetPath
...
C:\\1.exe


Please tlle me what's wrong with the following code (it's all that I have that's gotta do with the File.Copy):

File.Copy("ETBat.bat",etLocation);

etLocation is a string which contains the location to where ETBat.bat has to be copied.

Please help!