v2rayN/v2rayN/ServiceLib/Common/ProcUtils.cs
nirvanalinlei b3102b34b3
Some checks failed
release Linux / build (Release) (push) Has been cancelled
release macOS / build (Release) (push) Has been cancelled
release Windows desktop (Avalonia UI) / build (Release) (push) Has been cancelled
release Windows / build (Release) (push) Has been cancelled
release Linux / deb (push) Has been cancelled
release Linux / rpm (push) Has been cancelled
修复 sing-box TUN 模式下 relay 出站的 mux 问题 (#9018)
* Fix sing-box selector generation for dynamic group tags

* 修复 TUN 模式下 DNS 失败及 Windows 提权重启后 TUN 状态丢失

* 按上游意见回滚 TUN 提权时保留启用状态的改动
2026-04-02 20:47:34 +08:00

69 lines
1.8 KiB
C#

namespace ServiceLib.Common;
public static class ProcUtils
{
private static readonly string _tag = "ProcUtils";
public static void ProcessStart(string? fileName, string arguments = "")
{
_ = ProcessStart(fileName, arguments, null);
}
public static int? ProcessStart(string? fileName, string arguments, string? dir)
{
if (fileName.IsNullOrEmpty())
{
return null;
}
try
{
if (fileName.Contains(' '))
{
fileName = fileName.AppendQuotes();
}
if (arguments.Contains(' '))
{
arguments = arguments.AppendQuotes();
}
Process proc = new()
{
StartInfo = new ProcessStartInfo
{
UseShellExecute = true,
FileName = fileName,
Arguments = arguments,
WorkingDirectory = dir ?? string.Empty
}
};
_ = proc.Start();
return dir is null ? null : proc.Id;
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
}
return null;
}
public static bool RebootAsAdmin(bool blAdmin = true)
{
try
{
ProcessStartInfo startInfo = new()
{
UseShellExecute = true,
Arguments = Global.RebootAs,
WorkingDirectory = Utils.StartupPath(),
FileName = Utils.GetExePath().AppendQuotes(),
Verb = blAdmin ? "runas" : null,
};
return Process.Start(startInfo) != null;
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
return false;
}
}
}