0

How can I run an embedded .exe file (installer) in C# Windows Forms applications the easiest way?

I just want to click a button and an installer should open. My .exe file's name is setup.

If I try Process.Start(setup.exe); I get an error:

The name 'setup' does not exist in the current context

And if I try

System.Diagnostics.Process.Start("setup");

it will open folder C:\Windows\System32\setup.

3
  • 1
    have you tried giving full path of exe incluing the folder its contained in ? Commented Oct 24, 2015 at 15:29
  • That's all you gotta do. Commented Oct 24, 2015 at 15:32
  • the exe file is embedded to the program, it hasn't got any external path. Commented Oct 24, 2015 at 21:03

1 Answer 1

2

If what you expect is the easiest way, then don't embed setup.exe as a resource, but as Content.

(Add setup.exe to your project, and right click on setup.exe in Solution Explorer to edit properties, set as content, and select Copy if newer.)

Another option if setup.exe is a project of your Visual Studio solution, is to automatically copy setup.exe in the output directory of the launcher project: Add a reference to setup.exe if it belongs to the solution, so it is automatically copied every time you compile and there was a change.

Last is the code that is pretty easy - you already have it, actually:

System.Diagnostics.Process.Start("HelloWorld.exe");

If needed, you can change the current directory:

Environment.CurrentDirectory = @"c:\someSetupExeDir";

But better, you can use Path.Combine:

String fullPath = Path.Combine(directoryPath, fileName);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! :D Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.