溫馨提示×

c# processstartinfo如何設置工作目錄

c#
小樊
224
2024-11-23 00:33:03
欄目: 編程語言

在C#中,使用ProcessStartInfo類啟動一個進程時,可以通過設置WorkingDirectory屬性來指定工作目錄

using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "your_executable.exe"; // 替換為你要執行的程序的可執行文件名
        startInfo.Arguments = "your_arguments"; // 替換為你要傳遞給程序的參數
        startInfo.WorkingDirectory = @"C:\your_working_directory\"; // 替換為你的工作目錄路徑
        startInfo.UseShellExecute = false;
        startInfo.CreateNoWindow = true;

        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();
    }
}

在這個示例中,將your_executable.exe替換為你要執行的程序的可執行文件名,將your_arguments替換為你要傳遞給程序的參數,將C:\your_working_directory\替換為你的工作目錄路徑。然后,使用Process.Start()方法啟動進程。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女