mirror of
https://github.com/reactos/reactos.git
synced 2025-04-12 00:29:04 +00:00
[NETSHELL] Move the implementation of the Disable button of the status dialog to CNetConnection::Disconnect
This commit is contained in:
parent
132463abf2
commit
0654d60eef
2 changed files with 131 additions and 131 deletions
|
@ -50,11 +50,137 @@ CNetConnection::Connect()
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
FindNetworkAdapter(HDEVINFO hInfo, SP_DEVINFO_DATA *pDevInfo, LPWSTR pGuid)
|
||||||
|
{
|
||||||
|
DWORD dwIndex, dwSize;
|
||||||
|
HKEY hSubKey;
|
||||||
|
WCHAR szNetCfg[50];
|
||||||
|
WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
|
||||||
|
|
||||||
|
dwIndex = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ZeroMemory(pDevInfo, sizeof(SP_DEVINFO_DATA));
|
||||||
|
pDevInfo->cbSize = sizeof(SP_DEVINFO_DATA);
|
||||||
|
|
||||||
|
/* get device info */
|
||||||
|
if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, pDevInfo))
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* get device software registry path */
|
||||||
|
if (!SetupDiGetDeviceRegistryPropertyW(hInfo, pDevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* open device registry key */
|
||||||
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* query NetCfgInstanceId for current device */
|
||||||
|
dwSize = sizeof(szNetCfg);
|
||||||
|
if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
RegCloseKey(hSubKey);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
RegCloseKey(hSubKey);
|
||||||
|
if (!_wcsicmp(pGuid, szNetCfg))
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
} while (TRUE);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT
|
HRESULT
|
||||||
WINAPI
|
WINAPI
|
||||||
CNetConnection::Disconnect()
|
CNetConnection::Disconnect()
|
||||||
{
|
{
|
||||||
return E_NOTIMPL;
|
HKEY hKey;
|
||||||
|
NETCON_PROPERTIES * pProperties;
|
||||||
|
LPOLESTR pDisplayName;
|
||||||
|
WCHAR szPath[200];
|
||||||
|
DWORD dwSize, dwType;
|
||||||
|
LPWSTR pPnp;
|
||||||
|
HDEVINFO hInfo;
|
||||||
|
SP_DEVINFO_DATA DevInfo;
|
||||||
|
SP_PROPCHANGE_PARAMS PropChangeParams;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
hr = GetProperties(&pProperties);
|
||||||
|
if (FAILED_UNEXPECTEDLY(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
hInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
|
||||||
|
if (!hInfo)
|
||||||
|
{
|
||||||
|
NcFreeNetconProperties(pProperties);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(StringFromCLSID((CLSID)pProperties->guidId, &pDisplayName)))
|
||||||
|
{
|
||||||
|
NcFreeNetconProperties(pProperties);
|
||||||
|
SetupDiDestroyDeviceInfoList(hInfo);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
NcFreeNetconProperties(pProperties);
|
||||||
|
|
||||||
|
if (FindNetworkAdapter(hInfo, &DevInfo, pDisplayName))
|
||||||
|
{
|
||||||
|
PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
|
||||||
|
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; //;
|
||||||
|
PropChangeParams.StateChange = DICS_DISABLE;
|
||||||
|
PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
|
||||||
|
PropChangeParams.HwProfile = 0;
|
||||||
|
|
||||||
|
if (SetupDiSetClassInstallParams(hInfo, &DevInfo, &PropChangeParams.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS)))
|
||||||
|
{
|
||||||
|
SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hInfo, &DevInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetupDiDestroyDeviceInfoList(hInfo);
|
||||||
|
|
||||||
|
swprintf(szPath, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", pDisplayName);
|
||||||
|
CoTaskMemFree(pDisplayName);
|
||||||
|
|
||||||
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
dwSize = 0;
|
||||||
|
if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS || dwType != REG_SZ)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pPnp = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
|
||||||
|
if (!pPnp)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, (LPBYTE)pPnp, &dwSize) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
CoTaskMemFree(pPnp);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
swprintf(szPath, L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Enum\\%s", pPnp);
|
||||||
|
CoTaskMemFree(pPnp);
|
||||||
|
|
||||||
|
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
dwSize = 1; /* enable = 0, disable = 1 */
|
||||||
|
RegSetValueExW(hKey, L"CSConfigFlags", 0, REG_DWORD, (LPBYTE)&dwSize, sizeof(DWORD));
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT
|
HRESULT
|
||||||
|
|
|
@ -544,141 +544,15 @@ LANStatusUiAdvancedDlg(
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
|
||||||
FindNetworkAdapter(HDEVINFO hInfo, SP_DEVINFO_DATA *pDevInfo, LPWSTR pGuid)
|
|
||||||
{
|
|
||||||
DWORD dwIndex, dwSize;
|
|
||||||
HKEY hSubKey;
|
|
||||||
WCHAR szNetCfg[50];
|
|
||||||
WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
|
|
||||||
|
|
||||||
dwIndex = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
ZeroMemory(pDevInfo, sizeof(SP_DEVINFO_DATA));
|
|
||||||
pDevInfo->cbSize = sizeof(SP_DEVINFO_DATA);
|
|
||||||
|
|
||||||
/* get device info */
|
|
||||||
if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, pDevInfo))
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* get device software registry path */
|
|
||||||
if (!SetupDiGetDeviceRegistryPropertyW(hInfo, pDevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* open device registry key */
|
|
||||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* query NetCfgInstanceId for current device */
|
|
||||||
dwSize = sizeof(szNetCfg);
|
|
||||||
if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
RegCloseKey(hSubKey);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
RegCloseKey(hSubKey);
|
|
||||||
if (!_wcsicmp(pGuid, szNetCfg))
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
} while (TRUE);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
DisableNetworkAdapter(INetConnection * pNet, LANSTATUSUI_CONTEXT * pContext, HWND hwndDlg)
|
DisableNetworkAdapter(INetConnection * pNet, LANSTATUSUI_CONTEXT * pContext, HWND hwndDlg)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HRESULT hr = pNet->Disconnect();
|
||||||
NETCON_PROPERTIES * pProperties;
|
if (FAILED_UNEXPECTEDLY(hr))
|
||||||
LPOLESTR pDisplayName;
|
return;
|
||||||
WCHAR szPath[200];
|
|
||||||
DWORD dwSize, dwType;
|
|
||||||
LPWSTR pPnp;
|
|
||||||
HDEVINFO hInfo;
|
|
||||||
SP_DEVINFO_DATA DevInfo;
|
|
||||||
SP_PROPCHANGE_PARAMS PropChangeParams;
|
|
||||||
BOOL bClose = FALSE;
|
|
||||||
NOTIFYICONDATAW nid;
|
NOTIFYICONDATAW nid;
|
||||||
|
|
||||||
if (FAILED(pNet->GetProperties(&pProperties)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
hInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
|
|
||||||
if (!hInfo)
|
|
||||||
{
|
|
||||||
NcFreeNetconProperties(pProperties);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(StringFromCLSID((CLSID)pProperties->guidId, &pDisplayName)))
|
|
||||||
{
|
|
||||||
NcFreeNetconProperties(pProperties);
|
|
||||||
SetupDiDestroyDeviceInfoList(hInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NcFreeNetconProperties(pProperties);
|
|
||||||
|
|
||||||
if (FindNetworkAdapter(hInfo, &DevInfo, pDisplayName))
|
|
||||||
{
|
|
||||||
PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
|
|
||||||
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; //;
|
|
||||||
PropChangeParams.StateChange = DICS_DISABLE;
|
|
||||||
PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
|
|
||||||
PropChangeParams.HwProfile = 0;
|
|
||||||
|
|
||||||
if (SetupDiSetClassInstallParams(hInfo, &DevInfo, &PropChangeParams.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS)))
|
|
||||||
{
|
|
||||||
if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hInfo, &DevInfo))
|
|
||||||
bClose = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SetupDiDestroyDeviceInfoList(hInfo);
|
|
||||||
|
|
||||||
swprintf(szPath, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", pDisplayName);
|
|
||||||
CoTaskMemFree(pDisplayName);
|
|
||||||
|
|
||||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dwSize = 0;
|
|
||||||
if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS || dwType != REG_SZ)
|
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pPnp = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
|
|
||||||
if (!pPnp)
|
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, (LPBYTE)pPnp, &dwSize) != ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
CoTaskMemFree(pPnp);
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
|
|
||||||
swprintf(szPath, L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Enum\\%s", pPnp);
|
|
||||||
CoTaskMemFree(pPnp);
|
|
||||||
|
|
||||||
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dwSize = 1; /* enable = 0, disable = 1 */
|
|
||||||
RegSetValueExW(hKey, L"CSConfigFlags", 0, REG_DWORD, (LPBYTE)&dwSize, sizeof(DWORD));
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
|
|
||||||
if (!bClose)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PropSheet_PressButton(GetParent(hwndDlg), PSBTN_CANCEL);
|
PropSheet_PressButton(GetParent(hwndDlg), PSBTN_CANCEL);
|
||||||
ZeroMemory(&nid, sizeof(nid));
|
ZeroMemory(&nid, sizeof(nid));
|
||||||
nid.cbSize = sizeof(nid);
|
nid.cbSize = sizeof(nid);
|
||||||
|
|
Loading…
Reference in a new issue