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.

198 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 2000
  5. //
  6. // File: N E T I N E T . C P P
  7. //
  8. // Contents: Routines supporting RAS interoperability
  9. //
  10. // Notes:
  11. //
  12. // Author: billi 07 03 2001
  13. //
  14. // History:
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "Util.h"
  19. #include "TheApp.h"
  20. #include <lmjoin.h>
  21. #include <devguid.h>
  22. #include "NetUtil.h"
  23. #include "NetInet.h"
  24. #define c_szIConnDwnAgent WIZARDNAME // agent for InternetOpen()
  25. HRESULT GetInternetAutodialMode( DWORD *pdwMode )
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Function: GetInternetAutodialMode
  29. //
  30. // Purpose: Gets the Autodial mode setting in the IE5+ dialer
  31. //
  32. // Arguments: pdwMode AUTODIAL_MODE_NEVER
  33. // AUTODIAL_MODE_ALWAYS
  34. // AUTODIAL_MODE_NO_NETWORK_PRESENT
  35. //
  36. // Returns: HRESULT
  37. //
  38. // Author: billi 22/01/01
  39. //
  40. // Notes:
  41. //
  42. {
  43. HRESULT hr;
  44. ASSERT(NULL != pdwMode);
  45. if ( NULL != pdwMode )
  46. {
  47. HINTERNET hInternet;
  48. hr = S_OK;
  49. *pdwMode = 0;
  50. hInternet = InternetOpen( c_szIConnDwnAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
  51. if ( NULL == hInternet )
  52. {
  53. hr = HrFromLastWin32Error();
  54. }
  55. else
  56. {
  57. DWORD dwLength = sizeof(*pdwMode);
  58. // The flag only exists for IE5, this call
  59. // will have no effect if IE5 is not present.
  60. BOOL bOk = InternetQueryOption( hInternet,
  61. INTERNET_OPTION_AUTODIAL_MODE,
  62. pdwMode,
  63. &dwLength );
  64. if ( !bOk )
  65. {
  66. hr = HrFromLastWin32Error();
  67. }
  68. InternetCloseHandle( hInternet );
  69. }
  70. }
  71. else
  72. {
  73. hr = E_POINTER;
  74. }
  75. return hr;
  76. }
  77. HRESULT HrSetInternetAutodialMode( DWORD dwMode )
  78. //+---------------------------------------------------------------------------
  79. //
  80. // Function: HrSetInternetAutodialMode
  81. //
  82. // Purpose: Sets the Autodial mode setting in the IE5+ dialer
  83. //
  84. // Arguments: dwMode AUTODIAL_MODE_NEVER
  85. // AUTODIAL_MODE_ALWAYS
  86. // AUTODIAL_MODE_NO_NETWORK_PRESENT
  87. //
  88. // Returns: HRESULT
  89. //
  90. // Author: billi 22/01/01
  91. //
  92. // Notes:
  93. //
  94. {
  95. HRESULT hr = S_OK;
  96. HINTERNET hInternet;
  97. hInternet = InternetOpen( c_szIConnDwnAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
  98. if ( NULL != hInternet )
  99. {
  100. // The flag only exists for IE5, this call
  101. // will have no effect if IE5 is not present.
  102. BOOL bOk = InternetSetOption( hInternet,
  103. INTERNET_OPTION_AUTODIAL_MODE,
  104. &dwMode,
  105. sizeof(dwMode) );
  106. if ( !bOk )
  107. {
  108. hr = HrFromLastWin32Error();
  109. }
  110. InternetCloseHandle( hInternet );
  111. }
  112. else
  113. {
  114. hr = HrFromLastWin32Error();
  115. }
  116. return hr;
  117. }
  118. HRESULT HrSetAutodial( DWORD dwMode )
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Function: HrSetAutodial
  122. //
  123. // Purpose: Sets the specified network connection to the specified mode.
  124. //
  125. // Arguments: dwMode AUTODIAL_MODE_NEVER
  126. // AUTODIAL_MODE_ALWAYS
  127. // AUTODIAL_MODE_NO_NETWORK_PRESENT
  128. //
  129. // Returns: HRESULT
  130. //
  131. // Author: billi 22/01/01
  132. //
  133. // Notes:
  134. //
  135. {
  136. #ifdef SETAUTODIALMODEDOWNONLY
  137. DWORD dwCurrentMode;
  138. HRESULT hr;
  139. // If we are trying to set the autodial mode to an extreme then
  140. // we go ahead and set it.
  141. if ( AUTODIAL_MODE_NO_NETWORK_PRESENT != dwMode )
  142. {
  143. hr = HrSetInternetAutodialMode( dwMode );
  144. }
  145. else
  146. {
  147. // If we are trying to set autodial mode to AUTODIAL_MODE_NO_NETWORK_PRESENT
  148. // then we only need to set if the current state is AUTODIAL_MODE_ALWAYS.
  149. hr = GetInternetAutodialMode( &dwCurrentMode );
  150. if ( SUCCEEDED(hr) && ( AUTODIAL_MODE_ALWAYS == dwCurrentMode ) )
  151. {
  152. hr = HrSetInternetAutodialMode( dwMode );
  153. }
  154. }
  155. return hr;
  156. #else
  157. return HrSetInternetAutodialMode( dwMode );
  158. #endif
  159. }