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)", __FUNCTION__,
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)
930 PROCESS_INFORMATION pi;
931 DWORD proc_flags = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT;
932 WCHAR *cmdline_dup = NULL;
934 ZeroMemory(&si,
sizeof(si));
935 ZeroMemory(&pi,
sizeof(pi));
940 cmdline_dup = _wcsdup(cmdline);
942 && CreateProcessW(NULL, cmdline_dup, NULL, NULL, FALSE, proc_flags, NULL, NULL, &si, &pi))
944 WaitForSingleObject(pi.hProcess, INFINITE);
945 if (!GetExitCodeProcess(pi.hProcess, &exit_code))
947 exit_code = GetLastError();
950 CloseHandle(pi.hProcess);
951 CloseHandle(pi.hThread);
955 exit_code = GetLastError();
969 if (pguidAdapter == NULL || szName == NULL)
971 return ERROR_BAD_ARGUMENTS;
975 LPOLESTR szDevClassNetId = NULL;
979 LPOLESTR szAdapterId = NULL;
980 StringFromIID((REFIID)pguidAdapter, &szAdapterId);
989 dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hKey);
990 if (dwResult != ERROR_SUCCESS)
992 SetLastError(dwResult);
994 msg(msg_flag,
"%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
995 goto cleanup_szAdapterId;
998 LPWSTR szOldName = NULL;
1000 if (dwResult != ERROR_SUCCESS)
1002 SetLastError(dwResult);
1003 msg(msg_flag,
"%s: Error reading adapter name", __FUNCTION__);
1008 const WCHAR *szFmt = L
"netsh interface set interface name=\"%"
1009 L
"ls\" newname=\"%ls\"";
1010 size_t ncmdline = wcslen(szFmt) + wcslen(szOldName) + wcslen(szName) + 1;
1011 WCHAR *szCmdLine = malloc(ncmdline *
sizeof(WCHAR));
1012 swprintf_s(szCmdLine, ncmdline, szFmt, szOldName, szName);
1019 if (dwResult != ERROR_SUCCESS)
1021 SetLastError(dwResult);
1022 msg(msg_flag,
"%s: Error renaming adapter", __FUNCTION__);
1029 CoTaskMemFree(szAdapterId);
1030 CoTaskMemFree(szDevClassNetId);
1041 if (ppAdapter == NULL)
1043 return ERROR_BAD_ARGUMENTS;
1047 HDEVINFO hDevInfoList = SetupDiGetClassDevsEx(&
GUID_DEVCLASS_NET, NULL, hwndParent,
1048 DIGCF_PRESENT, NULL, NULL, NULL);
1049 if (hDevInfoList == INVALID_HANDLE_VALUE)
1051 dwResult = GetLastError();
1052 msg(
M_NONFATAL,
"%s: SetupDiGetClassDevsEx failed", __FUNCTION__);
1057 SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data = { .cbSize =
sizeof(
1058 SP_DEVINFO_LIST_DETAIL_DATA) };
1059 if (!SetupDiGetDeviceInfoListDetail(hDevInfoList, &devinfo_list_detail_data))
1061 dwResult = GetLastError();
1062 msg(
M_NONFATAL,
"%s: SetupDiGetDeviceInfoListDetail failed", __FUNCTION__);
1063 goto cleanup_hDevInfoList;
1067 LPOLESTR szDevClassNetId = NULL;
1073 for (DWORD dwIndex = 0;; dwIndex++)
1076 SP_DEVINFO_DATA devinfo_data = { .cbSize =
sizeof(SP_DEVINFO_DATA) };
1077 if (!SetupDiEnumDeviceInfo(hDevInfoList, dwIndex, &devinfo_data))
1079 if (GetLastError() == ERROR_NO_MORE_ITEMS)
1086 msg(
M_WARN |
M_ERRNO,
"%s: SetupDiEnumDeviceInfo(%u) failed", __FUNCTION__,
1093 DWORD dwDataType = REG_NONE;
1094 LPWSTR szzDeviceHardwareIDs = NULL;
1096 &dwDataType, (LPVOID)&szzDeviceHardwareIDs);
1097 if (dwResult != ERROR_SUCCESS)
1104 if (dwDataType == REG_SZ)
1106 if (szzHwIDs && !
wcszistr(szzHwIDs, szzDeviceHardwareIDs))
1109 goto cleanup_szzDeviceHardwareIDs;
1112 else if (dwDataType == REG_MULTI_SZ)
1116 for (LPWSTR s = szzDeviceHardwareIDs;; s += wcslen(s) + 1)
1121 goto cleanup_szzDeviceHardwareIDs;
1134 goto cleanup_szzDeviceHardwareIDs;
1140 if (dwResult != ERROR_SUCCESS)
1143 goto cleanup_szzDeviceHardwareIDs;
1147 LPOLESTR szAdapterId = NULL;
1148 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
1157 dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_READ, &hKey);
1158 if (dwResult != ERROR_SUCCESS)
1160 SetLastError(dwResult);
1162 msg(
M_WARN |
M_ERRNO,
"%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
1163 goto cleanup_szAdapterId;
1169 if (dwResult != ERROR_SUCCESS)
1171 SetLastError(dwResult);
1172 msg(
M_WARN |
M_ERRNO,
"%s: Cannot determine %ls adapter name", __FUNCTION__,
1178 size_t hwid_size = (
wcszlen(szzDeviceHardwareIDs) + 1) *
sizeof(WCHAR);
1179 size_t name_size = (wcslen(
szName) + 1) *
sizeof(WCHAR);
1184 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__,
1186 dwResult = ERROR_OUTOFMEMORY;
1187 goto cleanup_szName;
1190 memcpy(&node->
guid, &guidAdapter,
sizeof(GUID));
1198 pAdapterTail->
pNext = node;
1199 pAdapterTail = node;
1203 *ppAdapter = pAdapterTail = node;
1211 CoTaskMemFree(szAdapterId);
1212cleanup_szzDeviceHardwareIDs:
1213 free(szzDeviceHardwareIDs);
1216 dwResult = ERROR_SUCCESS;
1218 CoTaskMemFree(szDevClassNetId);
1219cleanup_hDevInfoList:
1220 SetupDiDestroyDeviceInfoList(hDevInfoList);
1229 while (pAdapterList)
1232 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 ExecCommand(const WCHAR *cmdline)
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[]
#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.