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.

294 lines
7.6 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #include "precomp.h"
  3. #include "..\Common\ServiceThread.h"
  4. #ifdef EXT_DEBUG
  5. #undef THIS_FILE
  6. static char THIS_FILE[] = __FILE__;
  7. #endif
  8. #include "resource.h"
  9. #include "..\common\util.h"
  10. #include "NetIDPage.h"
  11. #include "NetHelpIDs.h"
  12. #include "iddlg.h"
  13. #include "NetUtility.h"
  14. #include <dsrole.h>
  15. #define MAX_ID_LENGTH 256
  16. //---------------------------------------------------------------------
  17. NetworkIDPage::NetworkIDPage(WbemServiceThread *serviceThread,
  18. LONG_PTR lNotifyHandle,
  19. bool bDeleteHandle,
  20. TCHAR* pTitle)
  21. : WBEMPageHelper(serviceThread),
  22. CSnapInPropertyPageImpl<NetworkIDPage> (pTitle),
  23. m_lNotifyHandle(lNotifyHandle),
  24. m_bDeleteHandle(bDeleteHandle) // Should be true for only page.
  25. {
  26. }
  27. //-------------------------------------------------------------
  28. NetworkIDPage::~NetworkIDPage()
  29. {
  30. }
  31. //-------------------------------------------------------------
  32. bool NetworkIDPage::CimomIsReady()
  33. {
  34. m_hDlg = m_hWnd;
  35. bool retval = ServiceIsReady(NO_UI, 0, 0);
  36. if(retval)
  37. {
  38. // This where it should be marshalling into THIS thread.
  39. m_WbemServices = m_serviceThread->m_WbemServices;
  40. IWbemClassObject *pInst = NULL;
  41. if((pInst = FirstInstanceOf("Win32_ComputerSystem")) != NULL)
  42. {
  43. m_computer = pInst;
  44. }
  45. if((pInst = FirstInstanceOf((bstr_t)"Win32_OperatingSystem")) != NULL)
  46. {
  47. m_OS = pInst;
  48. }
  49. if((pInst = FirstInstanceOf((bstr_t)"Win32_NetworkAdaptorConfiguration")) != NULL)
  50. {
  51. m_DNS = pInst;
  52. }
  53. m_state.Init(m_computer, m_OS, m_DNS);
  54. }
  55. return retval;
  56. }
  57. //-------------------------------------------------------
  58. LRESULT NetworkIDPage::OnChangeBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  59. {
  60. /* IDChangesDialog dlg(g_serviceThread, m_state);
  61. dlg.DoModal();
  62. if(m_state.MustReboot())
  63. {
  64. PropSheet_RebootSystem(GetParent());
  65. }
  66. m_state.Refresh();
  67. refresh();*/
  68. return S_OK;
  69. }
  70. //----------------------------------------------------------
  71. TCHAR szCommentReg[] = TEXT( "System\\ControlSet001\\Services\\LanmanServer\\Parameters" );
  72. void NetworkIDPage::refresh()
  73. {
  74. DWORD role = (DWORD)m_computer.GetLong("DomainRole");
  75. bool memberOfWorkgroup = ((role == DsRole_RoleStandaloneWorkstation) ||
  76. (role == DsRole_RoleStandaloneServer));
  77. //If we have the DNSName property, use it, otherwise use the NetBios name like we used to...
  78. _bstr_t bstrComputer = m_computer.GetString("DNSHostName");
  79. if (bstrComputer.length() == 0)
  80. bstrComputer = m_computer.GetString("Name");
  81. _bstr_t bstrDomain = m_computer.GetString("Domain");
  82. if( !memberOfWorkgroup ) {
  83. bstrComputer += _T(".");
  84. bstrComputer += bstrDomain;
  85. }
  86. _tcslwr(bstrComputer);
  87. SetDlgItemText(IDC_COMPUTER, bstrComputer);
  88. SetDlgItemText(IDC_DOMAIN, bstrDomain);
  89. SetDlgItemText(IDC_NETID_COMMENT,
  90. m_OS.GetString("Description"));
  91. BOOL enable = FALSE;
  92. HWND hwnd = ::GetDlgItem(m_hWnd, IDC_NETID_COMMENT);
  93. RemoteRegWriteable(szCommentReg, enable);
  94. ::EnableWindow(hwnd, enable);
  95. ::SendMessage(hwnd, EM_LIMITTEXT, MAX_ID_LENGTH, 0);
  96. //#ifdef NO_SYSTEM_CPL_EQUIVALENT_BEHAVIOR
  97. TCHAR temp[50] = {0};
  98. ::LoadString(HINST_THISDLL,
  99. (memberOfWorkgroup ?
  100. IDS_MEMBER_OF_WORKGROUP :
  101. IDS_MEMBER_OF_DOMAIN),
  102. temp, 50);
  103. SetDlgItemText(IDC_MEMBER_OF, temp);
  104. //#endif // NO_SYSTEM_CPL_EQUIVALENT_BEHAVIOR
  105. //bool show_change = IsCurrentUserAdministrator()
  106. // && !m_state.IsMachineDC()
  107. // && (m_state.IsNetworkingInstalled() ||
  108. // m_state.IsMemberOfWorkgroup());
  109. //::EnableWindow(GetDlgItem(IDC_CHANGE), show_change);
  110. ::ShowWindow(GetDlgItem(IDC_SAVING_MESSAGE),
  111. m_state.NeedsReboot() ? SW_SHOW : SW_HIDE);
  112. }
  113. //----------------------------------------------------------
  114. LRESULT NetworkIDPage::OnInit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  115. {
  116. if(CimomIsReady())
  117. {
  118. refresh();
  119. }
  120. else
  121. {
  122. if(m_serviceThread)
  123. {
  124. m_serviceThread->SendPtr(m_hWnd);
  125. }
  126. // no connection yet.
  127. TCHAR msg[50] = {0};
  128. ::LoadString(HINST_THISDLL, IDS_UNAVAILABLE, msg, 50);
  129. SetDlgItemText(IDC_COMPUTER, msg);
  130. SetDlgItemText(IDC_DOMAIN, msg);
  131. SetDlgItemText(IDC_NETID_COMMENT, msg);
  132. HWND hwnd = ::GetDlgItem(m_hWnd, IDC_NETID_COMMENT);
  133. ::EnableWindow(hwnd, FALSE);
  134. ::SendMessage(hwnd, EM_LIMITTEXT, 48, 0);
  135. ::EnableWindow(GetDlgItem(IDC_CHANGE), FALSE);
  136. ::ShowWindow(GetDlgItem(IDC_SAVING_MESSAGE), SW_HIDE);
  137. }
  138. return S_OK;
  139. }
  140. //----------------------------------------------------------
  141. LRESULT NetworkIDPage::OnConnected(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  142. {
  143. if(lParam)
  144. {
  145. IStream *pStream = (IStream *)lParam;
  146. IWbemServices *pServices = 0;
  147. HRESULT hr = CoGetInterfaceAndReleaseStream(pStream,
  148. IID_IWbemServices,
  149. (void**)&pServices);
  150. if(SUCCEEDED(hr))
  151. {
  152. SetWbemService(pServices);
  153. pServices->Release();
  154. if(CimomIsReady())
  155. {
  156. refresh();
  157. }
  158. }
  159. }
  160. else
  161. {
  162. ::EnableWindow(GetDlgItem(IDC_NETID_COMMENT), FALSE);
  163. }
  164. return S_OK;
  165. }
  166. //--------------------------------------------------------------
  167. LRESULT NetworkIDPage::OnComment(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  168. {
  169. // activate Apply for the comment change
  170. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0L);
  171. return S_OK;
  172. }
  173. //--------------------------------------------------------------
  174. static const DWORD _help_map[] =
  175. {
  176. IDC_COMPUTER, IDH_IDENT_FULL_NAME,
  177. IDC_FULL_NAME, IDH_IDENT_FULL_NAME,
  178. IDC_MEMBER_OF, IDH_IDENT_MEMBER_OF,
  179. IDC_DOMAIN, IDH_IDENT_MEMBER_OF,
  180. IDC_CHANGE, IDH_IDENT_CHANGE_BUTTON,
  181. IDC_COMMENT, IDH_COMPUTER_DESCRIPTION, //was IDH_WBEM_NETID_COMPUTER_DESCRIPTION
  182. IDC_NETID_COMMENT, IDH_COMPUTER_DESCRIPTION, //was IDH_WBEM_NETID_COMPUTER_DESCRIPTION
  183. IDC_NETID_SELECT_ICON, -1,
  184. IDC_PARA, IDH_NO_HELP,
  185. 0, 0
  186. };
  187. LRESULT NetworkIDPage::OnF1Help(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  188. {
  189. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  190. L"sysdm.hlp",
  191. HELP_WM_HELP,
  192. (ULONG_PTR)(LPSTR)_help_map);
  193. return S_OK;
  194. }
  195. //--------------------------------------------------------------
  196. LRESULT NetworkIDPage::OnContextHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  197. {
  198. ::WinHelp((HWND)wParam,
  199. L"sysdm.hlp",
  200. HELP_CONTEXTMENU,
  201. (ULONG_PTR)(LPSTR)_help_map);
  202. return S_OK;
  203. }
  204. //--------------------------------------------------------------
  205. BOOL NetworkIDPage::OnApply()
  206. {
  207. WCHAR szMsg[MAX_ID_LENGTH +2] = {0};
  208. HRESULT hr = 0;
  209. CWindow msgHWND(GetDlgItem(IDC_NETID_COMMENT));
  210. BOOL modified = (BOOL)msgHWND.SendMessage(EM_GETMODIFY);
  211. if((bool)m_WbemServices && modified)
  212. {
  213. ::GetWindowText(msgHWND, szMsg, ARRAYSIZE(szMsg) -1);
  214. //Now create a new Instance and populate only the properties which are modified
  215. CWbemClassObject newinst = m_OS.SpawnInstance();
  216. hr = newinst.Put("Description", (bstr_t)szMsg);
  217. _bstr_t name;
  218. hr = m_OS.Get("Name",name);
  219. hr = newinst.Put("Name",name);
  220. hr = m_WbemServices.PutInstance(newinst);
  221. if(FAILED(hr))
  222. {
  223. TCHAR caption[50] = {0}, text[500] = {0};
  224. ::LoadString(HINST_THISDLL,
  225. IDS_DISPLAY_NAME,
  226. caption, 50);
  227. ::LoadString(HINST_THISDLL,
  228. IDS_CANT_WRITE_COMMENT,
  229. text, 500);
  230. ::MessageBox(NULL, text, caption,
  231. MB_OK | MB_ICONHAND);
  232. }
  233. }
  234. return TRUE;
  235. }