代码之家  ›  专栏  ›  技术社区  ›  OFNEILL

尝试在C中启动Tunnelbear.exe#

  •  1
  • OFNEILL  · 技术社区  · 2 年前

    所以我需要以编程方式在C#中启动TunnelBear.exe(一个VPN),然后再次杀死它。cmd中的命令是(转到目录后) TunnelBear.exe --on

    这是我在C#中尝试的:

    var process = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = @"C:\Program Files (x86)\TunnelBear\TunnelBear.exe",
            Arguments = @"TunnelBear.exe --on",
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardOutput = true,
            RedirectStandardInput = true
        }
    };
    process.Start();
    
    1 回复  |  直到 2 年前
        1
  •  0
  •   0x436f72647265    2 年前

    首先,欢迎来到SO。

    我认为您混淆了ProcessStartInfo的用法,您指定了一个应该启动的FileName,然后将带有应用程序名称的完整参数传递给该应用程序。 尝试更改 Argument 只有`“--on”,看看这是否有效?

    或者更改 UseShellExecute true 然后移除 FileName 部分并添加 Working Directory 实例

    var process = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            WorkingDirectory = @"C:\Program Files (x86)\TunnelBear",
            Arguments = @"TunnelBear.exe --on",
            UseShellExecute = true,
            CreateNoWindow = true,
            RedirectStandardOutput = true,
            RedirectStandardInput = true
        }
    };
    process.Start();