Question

How do I specify in C# where to install a specific program? I tried using .WorkingDirectory but it didn't work. I want to install the Notepad++ installer inside the NotepadFolder in Desktop, how do I do that?

    static void LaunchInstaller()
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = @"C:\Users\UserOne\Downloads\npp.6.1.5.Installer.exe";
        startInfo.WorkingDirectory = @"C:\Users\UserOne\Desktop\NotepadFolder";
        //The line above doesn't work. Notepad++ still installs to its current directory, in ProgramFiles
        startInfo.Arguments = "/S";
        Process.Start(startInfo);
    }

I saw the code below at dotnetperls.com. They didn't specify the use of the two strings and its arguments so I'm confuse right now:

static void LaunchCommandLineApp()
{
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

try
{
    Process exeProcess = Process.Start(startInfo)
    {
    exeProcess.WaitForExit();
    }
}
catch{}
}
Was it helpful?

Solution 2

Woohoo! Thank you for spenders link, my code works! You just have to add /D=your installation directory in the Arguments.. Here's my updated code:

    static void LaunchInstaller()
    {
        const string installdir = @"C:\Users\UserOne\Desktop\NotepadFolder";

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = @"C:\Users\UserOne\Downloads\npp.6.1.5.Installer.exe";
        startInfo.Arguments = "/S /D=" + installdir; //My new code
        Process.Start(startInfo);
    }

OTHER TIPS

This is not really programming related and I'm voting to close... In the meantime...

It's authored with Nullsoft Install System v2.46.

Take a look at the docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top