Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Programmer Here... 2

Status
Not open for further replies.
Jul 13, 2004
427
US
Hey all,

I'm trying to figure out how to use a .exe file in my project, specifically Robocopy.exe from the Windows Resource kit. Now i want this to be included in the project so that the resource kit does not have to be installed on the machine where the tool is run, but i'm having some difficulty. I've added robocopy.exe as an embedded resource, but i'm not sure how to actually call the executable and pass arguments to it.

Any help on starting this out would be appreciated. Please bear in mind that i am mearly a dabbler in programming (though it's getting addicting!), so be patient with me!!

~Intruder~
CEH, MCSA/MCSE 2000/2003

"The Less You Do, The Less Can Go Wrong" :)
 
You don't need to include the exe in your project.

Take it back out and then use System.Diagnostics.Process to launch the app with some arguments.

System.Diagnostics.Process p = new Process();

p.StartInfo.FileName = "robocopy.exe";
p.StartInfo.Arguments = "yourargumentsinastring";
p.Start();

That should get you started.
 
does that end up wrapping the .exe into the package when compiled then?

~Intruder~
CEH, CISSP, MCSA/MCSE 2000/2003

"The Less You Do, The Less Can Go Wrong" :)
 
got it now, thanks for the help. It's working great!

~Intruder~
CEH, CISSP, MCSA/MCSE 2000/2003

"The Less You Do, The Less Can Go Wrong" :)
 
If you place RoboCopy.exe in your project directory, you can then include it within your project output by doing the following:

Go to top of project and click on the "Show All Files"

You should see the robocopy.exe as a white file icon in your project

Right-click and choose includein project.

Go to properties of the file and choose Build Action "None" and Copy to Output Directory as "Copy if Newer"


Now you can use what JurkMonkey suggested except that
Code:
p.StartInfo.FileName = "robocopy.exe";

should really be changed to

Code:
p.StartInfo.FileName = Directory.GetCurrentDirectory()+@"\robocopy.exe";

What all this does is copy the robocopy.exe to whereever your project gets put. In the case you are compiling it will be put where the exe for your application ends up.

If you include your project in a setup project, it will get put in the same directory your exe goes when someone uses the installer.

Your application then expects the robocopy.exe to be in the same directory your app is located and calls it as a seperate application (as JurkMonkey has shown).

AFAIK, you cannot wrap an exe within an exe and expect it to run, but that's only my humble knowledge.

Keep in mind that with this method you really cannot use the robocopy.exe with any other application or stand-alone unless the user knows it exists in your app directory. And in the case the user already has the kit installed, you are merely doubling the amount of space it is taking up... this isn't a big deal really if your app is cutom for maybe a few people, but is considered bad practice if it were say a much larger external application you were trying to call (mb of files) and distributing your app to many people. In those cases, you should really install the robocopy.exe as it was intended either from your installer or with the regular distributable only because it does not promote the idea of installing multiple copies for the sake of ease of programming.
 
perfect. This is just for making this tool available to some people who basically can't read the help files :)

I have it working well now and appreciate your help!

~Intruder~
CEH, CISSP, MCSA/MCSE 2000/2003

"The Less You Do, The Less Can Go Wrong" :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top