36#pragma comment(lib, "advapi32.lib")
37#pragma comment(lib, "ole32.lib")
38#pragma comment(lib, "setupapi.lib")
39#pragma comment(lib, "newdev.lib")
44 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 }
48 L
"SYSTEM\\CurrentControlSet\\Control\\Network\\%ls\\%ls\\Connection";
49#define ADAPTER_REGKEY_PATH_MAX \
50 (_countof(L"SYSTEM\\CurrentControlSet\\Control\\Network\\") - 1 + 38 + _countof(L"\\") - 1 \
51 + 38 + _countof(L"\\Connection"))
69 WCHAR libpath[MAX_PATH];
73 if (!GetSystemDirectoryW(libpath, _countof(libpath)))
79 const size_t path_length = wcslen(libpath) + 1 + wcslen(libname);
80 if (path_length >= _countof(libpath))
82 SetLastError(ERROR_INSUFFICIENT_BUFFER);
85 wcscat_s(libpath, _countof(libpath), L
"\\");
86 wcscat_s(libpath, _countof(libpath), libname);
88 *m = LoadLibraryW(libpath);
93 fptr = GetProcAddress(*m, funcname);
114 for (s = szz; s[0]; s += wcslen(s) + 1)
134 for (LPCWSTR s = szzHay; s[0]; s += wcslen(s) + 1)
136 if (wcsicmp(s, szNeedle) == 0)
163 _Inout_ LPBOOL pbRebootRequired);
184 _Inout_ LPBOOL pbRebootRequired)
186 if (pbRebootRequired == NULL)
188 return ERROR_BAD_ARGUMENTS;
191 SP_DEVINSTALL_PARAMS devinstall_params = { .cbSize =
sizeof(SP_DEVINSTALL_PARAMS) };
192 if (!SetupDiGetDeviceInstallParams(hDeviceInfoSet, pDeviceInfoData, &devinstall_params))
194 DWORD dwResult = GetLastError();
199 if ((devinstall_params.Flags & (DI_NEEDREBOOT | DI_NEEDRESTART)) != 0)
201 *pbRebootRequired = TRUE;
204 return ERROR_SUCCESS;
226 _Inout_ LPBOOL pbRebootRequired)
228 SP_REMOVEDEVICE_PARAMS params = {
229 .ClassInstallHeader = {
230 .cbSize =
sizeof(SP_CLASSINSTALL_HEADER),
231 .InstallFunction = DIF_REMOVE,
233 .Scope = DI_REMOVEDEVICE_GLOBAL,
238 if (!SetupDiSetClassInstallParams(hDeviceInfoSet, pDeviceInfoData, ¶ms.ClassInstallHeader,
239 sizeof(SP_REMOVEDEVICE_PARAMS)))
241 DWORD dwResult = GetLastError();
247 if (!SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfoSet, pDeviceInfoData))
249 DWORD dwResult = GetLastError();
255 check_reboot(hDeviceInfoSet, pDeviceInfoData, pbRebootRequired);
256 return ERROR_SUCCESS;
280 _In_ BOOL bEnable,
_Inout_ LPBOOL pbRebootRequired)
282 SP_PROPCHANGE_PARAMS params = {
283 .ClassInstallHeader = {
284 .cbSize =
sizeof(SP_CLASSINSTALL_HEADER),
285 .InstallFunction = DIF_PROPERTYCHANGE,
287 .StateChange = bEnable ? DICS_ENABLE : DICS_DISABLE,
288 .Scope = DICS_FLAG_GLOBAL,
293 if (!SetupDiSetClassInstallParams(hDeviceInfoSet, pDeviceInfoData, ¶ms.ClassInstallHeader,
294 sizeof(SP_PROPCHANGE_PARAMS)))
296 DWORD dwResult = GetLastError();
302 if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDeviceInfoSet, pDeviceInfoData))
304 DWORD dwResult = GetLastError();
311 check_reboot(hDeviceInfoSet, pDeviceInfoData, pbRebootRequired);
312 return ERROR_SUCCESS;
334 _Inout_ LPBOOL pbRebootRequired)
358 _Inout_ LPBOOL pbRebootRequired)
381 if (pszValue == NULL)
383 return ERROR_BAD_ARGUMENTS;
386 DWORD dwValueType = REG_NONE, dwSize = 0;
387 DWORD dwResult = RegQueryValueEx(hKey, szName, NULL, &dwValueType, NULL, &dwSize);
388 if (dwResult != ERROR_SUCCESS)
390 SetLastError(dwResult);
403 LPWSTR szValue = (LPWSTR)malloc(dwSize);
406 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwSize);
407 return ERROR_OUTOFMEMORY;
410 dwResult = RegQueryValueEx(hKey, szName, NULL, NULL, (LPBYTE)szValue, &dwSize);
411 if (dwResult != ERROR_SUCCESS)
422 if (dwValueType == REG_EXPAND_SZ)
426 dwSizeExp = dwSize * 2, dwCountExp =
428 dwSizeExp /
sizeof(WCHAR);
430 dwSizeExp /
sizeof(WCHAR)
433 LPWSTR szValueExp = (LPWSTR)malloc(dwSizeExp);
434 if (szValueExp == NULL)
437 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwSizeExp);
438 return ERROR_OUTOFMEMORY;
441 DWORD dwCountExpResult = ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
442 if (dwCountExpResult == 0)
445 __FUNCTION__, szName);
450 else if (dwCountExpResult <= dwCountExp)
454 *pszValue = szValueExp;
455 return ERROR_SUCCESS;
462 dwSizeExp = dwCountExpResult *
sizeof(WCHAR);
465 dwSizeExp = (dwCountExpResult + 1) *
sizeof(WCHAR);
467 dwCountExp = dwCountExpResult;
468 szValueExp = (LPWSTR)malloc(dwSizeExp);
469 if (szValueExp == NULL)
472 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwSizeExp);
473 return ERROR_OUTOFMEMORY;
476 dwCountExpResult = ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
478 *pszValue = szValueExp;
479 return ERROR_SUCCESS;
485 return ERROR_SUCCESS;
490 msg(
M_NONFATAL,
"%s: \"%ls\" registry value is not string (type %u)",
491 __FUNCTION__, szName, dwValueType);
492 return ERROR_UNSUPPORTED_TYPE;
517 _In_ int iNumAttempts,
_Out_ LPGUID pguidAdapter)
519 DWORD dwResult = ERROR_BAD_ARGUMENTS;
521 if (pguidAdapter == NULL || iNumAttempts < 1)
523 return ERROR_BAD_ARGUMENTS;
527 HKEY hKey = SetupDiOpenDevRegKey(hDeviceInfoSet, pDeviceInfoData, DICS_FLAG_GLOBAL, 0,
528 DIREG_DRV, KEY_READ);
529 if (hKey == INVALID_HANDLE_VALUE)
531 dwResult = GetLastError();
536 while (iNumAttempts > 0)
540 LPWSTR szCfgGuidString = NULL;
541 dwResult = RegQueryValueEx(hKey, L
"NetCfgInstanceId", NULL, NULL, NULL, NULL);
542 if (dwResult != ERROR_SUCCESS)
544 if (dwResult == ERROR_FILE_NOT_FOUND && --iNumAttempts > 0)
560 dwResult =
get_reg_string(hKey, L
"NetCfgInstanceId", &szCfgGuidString);
561 if (dwResult != ERROR_SUCCESS)
566 dwResult = SUCCEEDED(CLSIDFromString(szCfgGuidString, (LPCLSID)pguidAdapter))
568 : ERROR_INVALID_DATA;
569 free(szCfgGuidString);
601 _In_ DWORD dwProperty,
_Out_opt_ LPDWORD pdwPropertyRegDataType,
602 _Out_ LPVOID *ppData)
604 DWORD dwResult = ERROR_BAD_ARGUMENTS;
608 return ERROR_BAD_ARGUMENTS;
613 DWORD dwRequiredSize = 0;
614 if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, pDeviceInfoData, dwProperty,
615 pdwPropertyRegDataType, bBufStack,
sizeof(bBufStack),
619 *ppData = malloc(dwRequiredSize);
622 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwRequiredSize);
623 return ERROR_OUTOFMEMORY;
626 memcpy(*ppData, bBufStack, dwRequiredSize);
627 return ERROR_SUCCESS;
631 dwResult = GetLastError();
632 if (dwResult == ERROR_INSUFFICIENT_BUFFER)
635 *ppData = malloc(dwRequiredSize);
638 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwRequiredSize);
639 return ERROR_OUTOFMEMORY;
642 if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, pDeviceInfoData, dwProperty,
643 pdwPropertyRegDataType, *ppData, dwRequiredSize,
646 return ERROR_SUCCESS;
650 dwResult = GetLastError();
652 __FUNCTION__, dwProperty);
659 __FUNCTION__, dwProperty);
668 _In_ LPCWSTR szHwId,
_Inout_ LPBOOL pbRebootRequired,
_Out_ LPGUID pguidAdapter)
671 HMODULE libnewdev = NULL;
673 if (szHwId == NULL || pbRebootRequired == NULL || pguidAdapter == NULL)
675 return ERROR_BAD_ARGUMENTS;
679 HDEVINFO hDevInfoList = SetupDiCreateDeviceInfoList(&
GUID_DEVCLASS_NET, hwndParent);
680 if (hDevInfoList == INVALID_HANDLE_VALUE)
682 dwResult = GetLastError();
683 msg(
M_NONFATAL,
"%s: SetupDiCreateDeviceInfoList failed", __FUNCTION__);
688 WCHAR szClassName[MAX_CLASS_NAME_LEN];
689 if (!SetupDiClassNameFromGuid(&
GUID_DEVCLASS_NET, szClassName, _countof(szClassName), NULL))
691 dwResult = GetLastError();
692 msg(
M_NONFATAL,
"%s: SetupDiClassNameFromGuid failed", __FUNCTION__);
693 goto cleanup_hDevInfoList;
697 SP_DEVINFO_DATA devinfo_data = { .cbSize =
sizeof(SP_DEVINFO_DATA) };
698 if (!SetupDiCreateDeviceInfo(hDevInfoList, szClassName, &
GUID_DEVCLASS_NET, szDeviceDescription,
699 hwndParent, DICD_GENERATE_ID, &devinfo_data))
701 dwResult = GetLastError();
702 msg(
M_NONFATAL,
"%s: SetupDiCreateDeviceInfo failed", __FUNCTION__);
703 goto cleanup_hDevInfoList;
707 if (!SetupDiSetSelectedDevice(hDevInfoList, &devinfo_data))
709 dwResult = GetLastError();
710 msg(
M_NONFATAL,
"%s: SetupDiSetSelectedDevice failed", __FUNCTION__);
711 goto cleanup_hDevInfoList;
715 if (!SetupDiSetDeviceRegistryProperty(hDevInfoList, &devinfo_data, SPDRP_HARDWAREID,
716 (
const BYTE *)szHwId,
717 (DWORD)((wcslen(szHwId) + 1) *
sizeof(WCHAR))))
719 dwResult = GetLastError();
720 msg(
M_NONFATAL,
"%s: SetupDiSetDeviceRegistryProperty failed", __FUNCTION__);
721 goto cleanup_hDevInfoList;
725 if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, hDevInfoList, &devinfo_data))
727 dwResult = GetLastError();
728 msg(
M_NONFATAL,
"%s: SetupDiCallClassInstaller(DIF_REGISTERDEVICE) failed", __FUNCTION__);
729 goto cleanup_hDevInfoList;
737#ifdef HAVE_DIINSTALLDEVICE
738 if (!DiInstallDevice(hwndParent, hDevInfoList, &devinfo_data, NULL, 0, pbRebootRequired))
741 typedef BOOL(WINAPI * DiInstallDeviceFn)(HWND, HDEVINFO, SP_DEVINFO_DATA *, SP_DRVINFO_DATA *,
743 DiInstallDeviceFn installfn =
find_function(L
"newdev.dll",
"DiInstallDevice", &libnewdev);
747 dwResult = GetLastError();
749 goto cleanup_hDevInfoList;
752 if (!installfn(hwndParent, hDevInfoList, &devinfo_data, NULL, 0, pbRebootRequired))
755 dwResult = GetLastError();
757 goto cleanup_remove_device;
763cleanup_remove_device:
764 if (dwResult != ERROR_SUCCESS)
767 SP_REMOVEDEVICE_PARAMS removedevice_params = {
768 .ClassInstallHeader = {
769 .cbSize =
sizeof(SP_CLASSINSTALL_HEADER),
770 .InstallFunction = DIF_REMOVE,
772 .Scope = DI_REMOVEDEVICE_GLOBAL,
777 if (SetupDiSetClassInstallParams(hDevInfoList, &devinfo_data,
778 &removedevice_params.ClassInstallHeader,
779 sizeof(SP_REMOVEDEVICE_PARAMS)))
782 if (SetupDiCallClassInstaller(DIF_REMOVE, hDevInfoList, &devinfo_data))
785 check_reboot(hDevInfoList, &devinfo_data, pbRebootRequired);
802 FreeLibrary(libnewdev);
804 SetupDiDestroyDeviceInfoList(hDevInfoList);
835 if (pguidAdapter == NULL)
837 return ERROR_BAD_ARGUMENTS;
841 HDEVINFO hDevInfoList = SetupDiGetClassDevsEx(&
GUID_DEVCLASS_NET, NULL, hwndParent,
842 DIGCF_PRESENT, NULL, NULL, NULL);
843 if (hDevInfoList == INVALID_HANDLE_VALUE)
845 dwResult = GetLastError();
846 msg(
M_NONFATAL,
"%s: SetupDiGetClassDevsEx failed", __FUNCTION__);
851 SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data = { .cbSize =
sizeof(
852 SP_DEVINFO_LIST_DETAIL_DATA) };
853 if (!SetupDiGetDeviceInfoListDetail(hDevInfoList, &devinfo_list_detail_data))
855 dwResult = GetLastError();
856 msg(
M_NONFATAL,
"%s: SetupDiGetDeviceInfoListDetail failed", __FUNCTION__);
857 goto cleanup_hDevInfoList;
861 for (DWORD dwIndex = 0;; dwIndex++)
864 SP_DEVINFO_DATA devinfo_data = { .cbSize =
sizeof(SP_DEVINFO_DATA) };
865 if (!SetupDiEnumDeviceInfo(hDevInfoList, dwIndex, &devinfo_data))
867 if (GetLastError() == ERROR_NO_MORE_ITEMS)
869 LPOLESTR szAdapterId = NULL;
870 StringFromIID((REFIID)pguidAdapter, &szAdapterId);
871 msg(
M_NONFATAL,
"%s: Adapter %ls not found", __FUNCTION__, szAdapterId);
872 CoTaskMemFree(szAdapterId);
873 dwResult = ERROR_FILE_NOT_FOUND;
874 goto cleanup_hDevInfoList;
888 if (dwResult != ERROR_SUCCESS)
895 if (memcmp(pguidAdapter, &guidAdapter,
sizeof(GUID)) == 0)
897 dwResult = funcOperation(hDevInfoList, &devinfo_data, pbRebootRequired);
903 SetupDiDestroyDeviceInfoList(hDevInfoList);
910 _Inout_ LPBOOL pbRebootRequired)
918 _Inout_ LPBOOL pbRebootRequired)
929 PROCESS_INFORMATION pi;
930 DWORD proc_flags = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT;
932 ZeroMemory(&si,
sizeof(si));
933 ZeroMemory(&pi,
sizeof(pi));
936 WCHAR appName[MAX_PATH];
937 WCHAR netsh_exe[] = L
"\\netsh.exe";
938 UINT sysdir_len = GetSystemDirectoryW(appName, _countof(appName));
941 wcscpy_s(appName, _countof(appName), L
"C:\\Windows\\system32");
943 else if (sysdir_len + _countof(netsh_exe) > _countof(appName))
945 return ERROR_INSUFFICIENT_BUFFER;
947 wcscat_s(appName, _countof(appName), netsh_exe);
949 if (CreateProcessW(appName, cmdline, NULL, NULL, FALSE, proc_flags, NULL, NULL, &si, &pi))
951 WaitForSingleObject(pi.hProcess, INFINITE);
952 if (!GetExitCodeProcess(pi.hProcess, &exit_code))
954 exit_code = GetLastError();
956 CloseHandle(pi.hProcess);
957 CloseHandle(pi.hThread);
961 exit_code = GetLastError();
974 if (pguidAdapter == NULL || szName == NULL)
976 return ERROR_BAD_ARGUMENTS;
980 LPOLESTR szDevClassNetId = NULL;
984 LPOLESTR szAdapterId = NULL;
985 StringFromIID((REFIID)pguidAdapter, &szAdapterId);
994 dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hKey);
995 if (dwResult != ERROR_SUCCESS)
997 SetLastError(dwResult);
999 msg(msg_flag,
"%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
1000 goto cleanup_szAdapterId;
1003 LPWSTR szOldName = NULL;
1005 if (dwResult != ERROR_SUCCESS)
1007 SetLastError(dwResult);
1008 msg(msg_flag,
"%s: Error reading adapter name", __FUNCTION__);
1013 const WCHAR *szFmt = L
"netsh interface set interface name=\"%"
1014 L
"ls\" newname=\"%ls\"";
1015 size_t ncmdline = wcslen(szFmt) + wcslen(szOldName) + wcslen(szName) + 1;
1016 WCHAR *szCmdLine = malloc(ncmdline *
sizeof(WCHAR));
1017 swprintf_s(szCmdLine, ncmdline, szFmt, szOldName, szName);
1024 if (dwResult != ERROR_SUCCESS)
1026 SetLastError(dwResult);
1027 msg(msg_flag,
"%s: Error renaming adapter", __FUNCTION__);
1034 CoTaskMemFree(szAdapterId);
1035 CoTaskMemFree(szDevClassNetId);
1046 if (ppAdapter == NULL)
1048 return ERROR_BAD_ARGUMENTS;
1052 HDEVINFO hDevInfoList = SetupDiGetClassDevsEx(&
GUID_DEVCLASS_NET, NULL, hwndParent,
1053 DIGCF_PRESENT, NULL, NULL, NULL);
1054 if (hDevInfoList == INVALID_HANDLE_VALUE)
1056 dwResult = GetLastError();
1057 msg(
M_NONFATAL,
"%s: SetupDiGetClassDevsEx failed", __FUNCTION__);
1062 SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data = { .cbSize =
sizeof(
1063 SP_DEVINFO_LIST_DETAIL_DATA) };
1064 if (!SetupDiGetDeviceInfoListDetail(hDevInfoList, &devinfo_list_detail_data))
1066 dwResult = GetLastError();
1067 msg(
M_NONFATAL,
"%s: SetupDiGetDeviceInfoListDetail failed", __FUNCTION__);
1068 goto cleanup_hDevInfoList;
1072 LPOLESTR szDevClassNetId = NULL;
1078 for (DWORD dwIndex = 0;; dwIndex++)
1081 SP_DEVINFO_DATA devinfo_data = { .cbSize =
sizeof(SP_DEVINFO_DATA) };
1082 if (!SetupDiEnumDeviceInfo(hDevInfoList, dwIndex, &devinfo_data))
1084 if (GetLastError() == ERROR_NO_MORE_ITEMS)
1091 msg(
M_WARN |
M_ERRNO,
"%s: SetupDiEnumDeviceInfo(%u) failed", __FUNCTION__,
1098 DWORD dwDataType = REG_NONE;
1099 LPWSTR szzDeviceHardwareIDs = NULL;
1101 &dwDataType, (LPVOID)&szzDeviceHardwareIDs);
1102 if (dwResult != ERROR_SUCCESS)
1109 if (dwDataType == REG_SZ)
1111 if (szzHwIDs && !
wcszistr(szzHwIDs, szzDeviceHardwareIDs))
1114 goto cleanup_szzDeviceHardwareIDs;
1117 else if (dwDataType == REG_MULTI_SZ)
1121 for (LPWSTR s = szzDeviceHardwareIDs;; s += wcslen(s) + 1)
1126 goto cleanup_szzDeviceHardwareIDs;
1139 goto cleanup_szzDeviceHardwareIDs;
1145 if (dwResult != ERROR_SUCCESS)
1148 goto cleanup_szzDeviceHardwareIDs;
1152 LPOLESTR szAdapterId = NULL;
1153 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
1162 dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_READ, &hKey);
1163 if (dwResult != ERROR_SUCCESS)
1165 SetLastError(dwResult);
1167 msg(
M_WARN |
M_ERRNO,
"%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
1168 goto cleanup_szAdapterId;
1174 if (dwResult != ERROR_SUCCESS)
1176 SetLastError(dwResult);
1177 msg(
M_WARN |
M_ERRNO,
"%s: Cannot determine %ls adapter name", __FUNCTION__,
1183 size_t hwid_size = (
wcszlen(szzDeviceHardwareIDs) + 1) *
sizeof(WCHAR);
1184 size_t name_size = (wcslen(
szName) + 1) *
sizeof(WCHAR);
1189 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__,
1191 dwResult = ERROR_OUTOFMEMORY;
1192 goto cleanup_szName;
1195 memcpy(&node->
guid, &guidAdapter,
sizeof(GUID));
1203 pAdapterTail->
pNext = node;
1204 pAdapterTail = node;
1208 *ppAdapter = pAdapterTail = node;
1216 CoTaskMemFree(szAdapterId);
1217cleanup_szzDeviceHardwareIDs:
1218 free(szzDeviceHardwareIDs);
1221 dwResult = ERROR_SUCCESS;
1223 CoTaskMemFree(szDevClassNetId);
1224cleanup_hDevInfoList:
1225 SetupDiDestroyDeviceInfoList(hDevInfoList);
1234 while (pAdapterList)
1237 pAdapterList = pAdapterList->
pNext;
Network adapter list node.
LPWSTR szzHardwareIDs
Device hardware ID(s)
struct tap_adapter_node * pNext
Pointer to next adapter.
LPWSTR szName
Adapter name.
DWORD tap_list_adapters(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szzHwIDs, _Out_ struct tap_adapter_node **ppAdapter)
Creates a list of existing network adapters.
static DWORD enable_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _Inout_ LPBOOL pbRebootRequired)
Enables the device.
static LPCWSTR wcszistr(_In_z_ LPCWSTR szzHay, _In_z_ LPCWSTR szNeedle)
Checks if string is contained in the string of strings.
static DWORD execute_on_first_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _In_ devop_func_t funcOperation, _Inout_ LPBOOL pbRebootRequired)
Performs a given task on an adapter.
DWORD(* devop_func_t)(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _Inout_ LPBOOL pbRebootRequired)
Function that performs a specific task on a device.
static DWORD get_net_adapter_guid(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _In_ int iNumAttempts, _Out_ LPGUID pguidAdapter)
Returns network adapter ID.
static DWORD disable_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _Inout_ LPBOOL pbRebootRequired)
Disables the device.
DWORD tap_set_adapter_name(_In_ LPCGUID pguidAdapter, _In_ LPCWSTR szName, _In_ BOOL bSilent)
Sets adapter name.
static const WCHAR szAdapterRegKeyPathTemplate[]
static DWORD ExecNetsh(PWSTR cmdline)
#define ADAPTER_REGKEY_PATH_MAX
static DWORD get_device_reg_property(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _In_ DWORD dwProperty, _Out_opt_ LPDWORD pdwPropertyRegDataType, _Out_ LPVOID *ppData)
Returns a specified Plug and Play device property.
static size_t wcszlen(_In_z_ LPCWSTR szz)
Returns length of string of strings.
DWORD tap_create_adapter(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szDeviceDescription, _In_ LPCWSTR szHwId, _Inout_ LPBOOL pbRebootRequired, _Out_ LPGUID pguidAdapter)
Creates a TUN/TAP adapter.
static void * find_function(const WCHAR *libname, const char *funcname, HMODULE *m)
Dynamically load a library and find a function in it.
DWORD tap_delete_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _Inout_ LPBOOL pbRebootRequired)
Deletes an adapter.
static DWORD delete_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _Inout_ LPBOOL pbRebootRequired)
Deletes the device.
static DWORD check_reboot(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _Inout_ LPBOOL pbRebootRequired)
Checks device install parameters if a system reboot is required.
void tap_free_adapter_list(_In_ struct tap_adapter_node *pAdapterList)
Frees a list of network adapters.
static const GUID GUID_DEVCLASS_NET
static DWORD get_reg_string(_In_ HKEY hKey, _In_ LPCWSTR szName, _Out_ LPWSTR *pszValue)
Reads string value from registry key.
DWORD tap_enable_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _In_ BOOL bEnable, _Inout_ LPBOOL pbRebootRequired)
Enables or disables an adapter.
static DWORD change_device_state(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData, _In_ BOOL bEnable, _Inout_ LPBOOL pbRebootRequired)
Changes the device state.