// Get the name of the default dial entry. nsresult nsAutodial::GetDefaultEntryName(wchar_t* entryName, int bufferSize) { // No RAS dialup entries. if (mNumRASConnectionEntries <= 0) { return NS_ERROR_FAILURE; } // Single RAS dialup entry. Use it as the default to autodial. if (mNumRASConnectionEntries == 1) { return GetFirstEntryName(entryName, bufferSize); } // Multiple RAS dialup entries. If a default configured in the registry, // use it. // // For Windows XP: HKCU/Software/Microsoft/RAS Autodial/Default/DefaultInternet. // or HKLM/Software/Microsoft/RAS Autodial/Default/DefaultInternet. const wchar_t* key = L"Software\\Microsoft\\RAS Autodial\\Default"; const wchar_t* val = L"DefaultInternet"; HKEY hKey = 0; LONG result = 0; // Try HKCU first. result = ::RegOpenKeyExW( HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey); if (result != ERROR_SUCCESS) { // If not present, try HKLM. result = ::RegOpenKeyExW( HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey); if (result != ERROR_SUCCESS) { return NS_ERROR_FAILURE; } } DWORD entryType = 0; DWORD buffSize = bufferSize; result = ::RegQueryValueExW(hKey, val, nullptr, &entryType, (LPBYTE)entryName, &buffSize); ::RegCloseKey(hKey); if (result != ERROR_SUCCESS) { // Results in a prompt for which to use at dial time. return NS_ERROR_FAILURE; } return NS_OK; }
// Get the name of the default dial entry. nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize) { // No RAS dialup entries. if (mNumRASConnectionEntries <= 0) { return NS_ERROR_FAILURE; } // Single RAS dialup entry. Use it as the default to autodial. if (mNumRASConnectionEntries == 1) { return GetFirstEntryName(entryName, bufferSize); } // Multiple RAS dialup entries. If a default configured in the registry, // use it. // // For Windows XP: HKCU/Software/Microsoft/RAS Autodial/Default/DefaultInternet. // or HKLM/Software/Microsoft/RAS Autodial/Default/DefaultInternet. // For Windows 2K: HKCU/RemoteAccess/InternetProfile. char* key = nsnull; char* val = nsnull; HKEY hKey = 0; LONG result = 0; // Windows NT and 2000 if ((mOSVerInfo.dwMajorVersion == 4) // Windows NT || ((mOSVerInfo.dwMajorVersion == 5) && (mOSVerInfo.dwMinorVersion == 0))) // Windows 2000 { key = "RemoteAccess"; val = "InternetProfile"; result = ::RegOpenKeyEx( HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey); if (result != ERROR_SUCCESS) { return NS_ERROR_FAILURE; } } else // Windows XP { key = "Software\\Microsoft\\RAS Autodial\\Default"; val = "DefaultInternet"; // Try HKCU first. result = ::RegOpenKeyEx( HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey); if (result != ERROR_SUCCESS) { // If not present, try HKLM. result = ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey); if (result != ERROR_SUCCESS) { return NS_ERROR_FAILURE; } } } DWORD entryType = 0; DWORD buffSize = bufferSize; result = ::RegQueryValueEx(hKey, val, nsnull, &entryType, (LPBYTE)entryName, &buffSize); ::RegCloseKey(hKey); if (result != ERROR_SUCCESS) { // Results in a prompt for which to use at dial time. return NS_ERROR_FAILURE; } return NS_OK; }