如何在 C# 中指定安装特定程序的位置?我尝试使用 .WorkingDirectory 但它没有用。我想在桌面的 NotepadFolder 中安装 Notepad++ 安装程序,我该怎么做?
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);
}
我在dotnetperls.com看到了下面的代码。他们没有指定两个字符串及其参数的使用,所以我现在很困惑:
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{}
}