mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 22:36:20 +00:00
放弃使用Vanara.PInvoke.SetupAPI的方式清除设备驱动,恢复使用pnputil,并传入instance ID参数清除sing-tun可能残留下的wintun设备驱动
This commit is contained in:
parent
f5d359fded
commit
5878929430
3 changed files with 4 additions and 29 deletions
|
@ -22,7 +22,6 @@ using ZXing;
|
|||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
using ZXing.Windows.Compatibility;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
@ -1142,12 +1141,12 @@ namespace v2rayN
|
|||
taskService.RootFolder.RegisterTaskDefinition(TaskName, task);
|
||||
}
|
||||
|
||||
public static void RemoveTunDevice()
|
||||
public static void RemoveDeviceForPnputil(string removeArg)
|
||||
{
|
||||
try
|
||||
{
|
||||
string pnputilPath = @"C:\Windows\System32\pnputil.exe";
|
||||
string arg = $" /remove-device /deviceid \"wintun\"";
|
||||
string arg = $" /remove-device " + removeArg;
|
||||
|
||||
// Try to remove the device
|
||||
Process proc = new()
|
||||
|
@ -1171,29 +1170,6 @@ namespace v2rayN
|
|||
}
|
||||
}
|
||||
|
||||
public static bool RemoveDeviceByDevIstId(string deviceInstanceId)
|
||||
{
|
||||
var isRemoved = false;
|
||||
var devs = SetupAPI.SetupDiGetClassDevs(SetupAPI.GUID_DEVCLASS_NET, null, HWND.NULL, SetupAPI.DIGCF.DIGCF_PROFILE);
|
||||
var instanceIdSize = deviceInstanceId.Length + 1;
|
||||
var devInfo = new SetupAPI.SP_DEVINFO_DATA() { cbSize = (uint)Marshal.SizeOf<SetupAPI.SP_DEVINFO_DATA>() };
|
||||
var instanceId = new StringBuilder(instanceIdSize);
|
||||
uint index = 0;
|
||||
|
||||
while (SetupAPI.SetupDiEnumDeviceInfo(devs, index++, ref devInfo))
|
||||
{
|
||||
var success = SetupAPI.SetupDiGetDeviceInstanceId(devs, devInfo, instanceId, (uint)instanceIdSize, out uint size);
|
||||
if (success && size == instanceIdSize && instanceId.ToString() == deviceInstanceId)
|
||||
{
|
||||
isRemoved = SetupAPI.SetupDiRemoveDevice(devs, ref devInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
SetupAPI.SetupDiDestroyDeviceInfoList(devs);
|
||||
|
||||
return isRemoved;
|
||||
}
|
||||
|
||||
public static string GetSingboxTunDeviceInstanceId(string deviceName)
|
||||
{
|
||||
string deviceInstanceId = string.Empty;
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace v2rayN.Handler
|
|||
{
|
||||
ShowMsg(true, $"{node!.GetSummary()}");
|
||||
CoreStop();
|
||||
Utils.RemoveDeviceByDevIstId(Utils.GetSingboxTunDeviceInstanceId(Global.DefaultSingboxTunDeviceName));
|
||||
Utils.RemoveDeviceForPnputil(Utils.GetSingboxTunDeviceInstanceId(Global.DefaultSingboxTunDeviceName));
|
||||
CoreStart(node);
|
||||
}
|
||||
executingResetEvents.ForEach(result => result.Set());
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<PackageReference Include="QRCoder.Xaml" Version="1.4.3" />
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.10.1" />
|
||||
<PackageReference Include="Vanara.PInvoke.SetupAPI" Version="4.0.0" />
|
||||
<PackageReference Include="ZXing.Net.Bindings.Windows.Compatibility" Version="0.16.12" />
|
||||
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
|
||||
<PackageReference Include="ReactiveUI.Validation" Version="3.1.7" />
|
||||
|
|
Loading…
Reference in a new issue