Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.9 KiB

  1. //
  2. // DefConn.cpp
  3. //
  4. #include "stdafx.h"
  5. #include "Registry.h"
  6. #include "DefConn.h"
  7. #include "nconnwrap.h"
  8. static const TCHAR c_szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
  9. static const TCHAR c_szProfile[] = "RemoteAccess\\Profile\\";
  10. static const TCHAR c_szEnableAutodial[] = "EnableAutodial";
  11. static const TCHAR c_szNoNetAutodial[] = "NoNetAutodial";
  12. static const TCHAR c_szRemoteAccess[] = "RemoteAccess";
  13. static const TCHAR c_szInternetProfile[] = "InternetProfile";
  14. static const TCHAR c_szAutoConnect[] = "AutoConnect";
  15. /////////////////////////////////////////////////////////////////////////////
  16. // EnableAutodial
  17. void WINAPI EnableAutodial(BOOL bAutodial, LPCSTR szConnection)
  18. {
  19. if (bAutodial)
  20. {
  21. // Ensure that "1" is written
  22. bAutodial = 1;
  23. }
  24. CRegistry regInternetHKCU(HKEY_CURRENT_USER, c_szInternetSettings, KEY_SET_VALUE);
  25. CRegistry regInternetHKLM(HKEY_LOCAL_MACHINE, c_szInternetSettings, KEY_SET_VALUE);
  26. regInternetHKCU.SetDwordValue(c_szEnableAutodial, bAutodial);
  27. regInternetHKCU.SetDwordValue(c_szNoNetAutodial, bAutodial);
  28. regInternetHKLM.SetBinaryValue(c_szEnableAutodial, (LPBYTE)&bAutodial, sizeof(bAutodial));
  29. if (szConnection != NULL)
  30. {
  31. TCHAR szTemp[MAX_PATH];
  32. lstrcpy(szTemp, c_szProfile);
  33. lstrcat(szTemp, szConnection);
  34. CRegistry regProfile(HKEY_CURRENT_USER, szTemp, KEY_SET_VALUE);
  35. regProfile.SetDwordValue(c_szAutoConnect, bAutodial);
  36. }
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. // BOOL IsAutodialEnabled()
  40. BOOL WINAPI IsAutodialEnabled()
  41. {
  42. CRegistry regInternetHKCU;
  43. return regInternetHKCU.OpenKey(HKEY_CURRENT_USER, c_szInternetSettings, KEY_QUERY_VALUE) &&
  44. regInternetHKCU.QueryDwordValue(c_szEnableAutodial) != 0;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // SetDefaultDialupConnection
  48. //
  49. // Empty (or NULL) string indicates no default connection, or shared connection (if ICS client).
  50. void WINAPI SetDefaultDialupConnection(LPCTSTR pszConnectionName)
  51. {
  52. CRegistry regRAS(HKEY_CURRENT_USER, c_szRemoteAccess, KEY_SET_VALUE);
  53. if (pszConnectionName != NULL && *pszConnectionName != '\0')
  54. {
  55. regRAS.SetStringValue(c_szInternetProfile, pszConnectionName);
  56. // Don't automatically autodial anymore
  57. // EnableAutodial(TRUE);
  58. }
  59. else
  60. {
  61. regRAS.DeleteValue(c_szInternetProfile);
  62. EnableAutodial(FALSE);
  63. }
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // GetDefaultDialupConnection
  67. //
  68. // Empty string returned indicates no default connection, or shared connection (if ICS client).
  69. void WINAPI GetDefaultDialupConnection(LPTSTR pszConnectionName, int cchMax)
  70. {
  71. pszConnectionName[0] = '\0';
  72. CRegistry regRAS(HKEY_CURRENT_USER, c_szRemoteAccess, KEY_QUERY_VALUE);
  73. regRAS.QueryStringValue(c_szInternetProfile, pszConnectionName, cchMax);
  74. }