diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index f158097b..73391a44 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -125,6 +125,42 @@ namespace ServiceLib.Common return null; } + public static void RemoveTunDevice() + { + try + { + var sum = MD5.HashData(Encoding.UTF8.GetBytes("wintunsingbox_tun")); + var guid = new Guid(sum); + string pnputilPath = @"C:\Windows\System32\pnputil.exe"; + string arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" /subtree """; + // string command = $"C:\\Windows\\System32\\pnputil.exe /remove-device \"SWD\\Wintun\\{{{guid}}}\" /subtree"; + + Logging.SaveLog("pnp command: " + arg); + + // Try to remove the device + Process proc = new() + { + StartInfo = new() + { + FileName = pnputilPath, + Arguments = arg, + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true + } + }; + + proc.Start(); + var output = proc.StandardOutput.ReadToEnd(); + proc.WaitForExit(); + Logging.SaveLog("pnputil output log: " + output); + } + catch (Exception ex) + { + Logging.SaveLog(_tag, ex); + } + } + /// /// 逗号分隔的字符串,先排序后转List /// @@ -904,4 +940,4 @@ namespace ServiceLib.Common #endregion Platform } -} \ No newline at end of file +}