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.

349 lines
7.4 KiB

  1. // autoans.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "t3test.h"
  5. #include "t3testd.h"
  6. #include "ilsdlg.h"
  7. #include "servname.h"
  8. #include "resource.h"
  9. #include "strings.h"
  10. #ifdef _DEBUG
  11. #ifndef _WIN64 // mfc 4.2's heap debugging features generate warnings on win64
  12. #define new DEBUG_NEW
  13. #endif
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. CILSDlg::CILSDlg(CWnd* pParent /*=NULL*/)
  18. : CDialog(CILSDlg::IDD, pParent)
  19. {
  20. }
  21. void CILSDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. }
  25. BOOL CILSDlg::OnInitDialog()
  26. {
  27. CDialog::OnInitDialog();
  28. ListServers();
  29. return TRUE;
  30. }
  31. void CILSDlg::OnOK()
  32. {
  33. SaveServers();
  34. CDialog::OnOK();
  35. }
  36. void CILSDlg::OnDestroy()
  37. {
  38. CleanUp();
  39. CDialog::OnDestroy();
  40. }
  41. void CILSDlg::ListServers()
  42. {
  43. HRESULT hr;
  44. LPWSTR * ppServers;
  45. DWORD dw;
  46. hr = ListILSServers(
  47. &ppServers,
  48. &dw
  49. );
  50. if ( !SUCCEEDED(hr) )
  51. {
  52. return;
  53. }
  54. while (dw)
  55. {
  56. dw--;
  57. SendDlgItemMessage(
  58. IDC_ILSLIST,
  59. LB_ADDSTRING,
  60. 0,
  61. (LPARAM) ppServers[dw]
  62. );
  63. CoTaskMemFree( ppServers[dw] );
  64. }
  65. CoTaskMemFree( ppServers );
  66. }
  67. void CILSDlg::SaveServers()
  68. {
  69. HKEY hKey, hAppKey;
  70. DWORD dw;
  71. if ( RegOpenKeyEx(
  72. HKEY_LOCAL_MACHINE,
  73. PARENTKEY,
  74. 0,
  75. KEY_WRITE,
  76. &hKey
  77. ) != ERROR_SUCCESS )
  78. {
  79. }
  80. if ( RegCreateKeyEx(
  81. hKey,
  82. APPKEY,
  83. 0,
  84. L"",
  85. REG_OPTION_NON_VOLATILE,
  86. KEY_ALL_ACCESS,
  87. NULL,
  88. &hAppKey,
  89. &dw
  90. ) != ERROR_SUCCESS )
  91. {
  92. }
  93. RegCloseKey( hKey );
  94. RegDeleteKey(
  95. hAppKey,
  96. SERVERKEY
  97. );
  98. if ( RegCreateKeyEx(
  99. hAppKey,
  100. SERVERKEY,
  101. 0,
  102. L"",
  103. REG_OPTION_NON_VOLATILE,
  104. KEY_ALL_ACCESS,
  105. NULL,
  106. &hKey,
  107. &dw
  108. ) != ERROR_SUCCESS )
  109. {
  110. }
  111. RegCloseKey (hAppKey );
  112. dw = SendDlgItemMessage(
  113. IDC_ILSLIST,
  114. LB_GETCOUNT,
  115. 0,
  116. 0
  117. );
  118. while ( 0 != dw )
  119. {
  120. WCHAR szServer[256];
  121. WCHAR szBuffer[256];
  122. dw--;
  123. wsprintf(szServer, L"server%d", dw);
  124. SendDlgItemMessage(
  125. IDC_ILSLIST,
  126. LB_GETTEXT,
  127. dw,
  128. (LPARAM)szBuffer
  129. );
  130. RegSetValueEx(
  131. hKey,
  132. szServer,
  133. 0,
  134. REG_SZ,
  135. (BYTE *)szBuffer,
  136. lstrlenW(szBuffer) * sizeof(WCHAR)
  137. );
  138. }
  139. }
  140. void CILSDlg::CleanUp()
  141. {
  142. }
  143. void CILSDlg::OnAdd()
  144. {
  145. CServNameDlg dlg;
  146. if (IDOK == dlg.DoModal())
  147. {
  148. SendDlgItemMessage(
  149. IDC_ILSLIST,
  150. LB_ADDSTRING,
  151. 0,
  152. (LPARAM)(LPCTSTR)(dlg.m_pszServerName)
  153. );
  154. }
  155. }
  156. void CILSDlg::OnRemove()
  157. {
  158. DWORD dw;
  159. dw = SendDlgItemMessage(
  160. IDC_ILSLIST,
  161. LB_GETCURSEL,
  162. 0,
  163. 0
  164. );
  165. if ( dw != LB_ERR )
  166. {
  167. SendDlgItemMessage(
  168. IDC_ILSLIST,
  169. LB_DELETESTRING,
  170. dw,
  171. 0
  172. );
  173. }
  174. }
  175. BEGIN_MESSAGE_MAP(CILSDlg, CDialog)
  176. ON_WM_DESTROY()
  177. ON_BN_CLICKED(IDC_ADD, OnAdd)
  178. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  179. END_MESSAGE_MAP()
  180. HRESULT ListILSServers(
  181. LPWSTR ** pppServers,
  182. DWORD * pdwNumServers
  183. )
  184. {
  185. HKEY hKey, hAppKey;
  186. DWORD dw, dwSize;
  187. //
  188. // look in the directory for the
  189. //
  190. if ( RegOpenKeyEx(
  191. HKEY_LOCAL_MACHINE,
  192. PARENTKEY,
  193. 0,
  194. KEY_WRITE,
  195. &hKey
  196. ) != ERROR_SUCCESS )
  197. {
  198. }
  199. if ( RegOpenKeyEx(
  200. hKey,
  201. APPKEY,
  202. 0,
  203. KEY_ALL_ACCESS,
  204. &hAppKey
  205. ) != ERROR_SUCCESS )
  206. {
  207. RegCloseKey( hKey );
  208. return E_FAIL;
  209. }
  210. RegCloseKey( hKey );
  211. if ( RegOpenKeyEx(
  212. hAppKey,
  213. SERVERKEY,
  214. 0,
  215. KEY_ALL_ACCESS,
  216. &hKey
  217. ) != ERROR_SUCCESS )
  218. {
  219. RegCloseKey(hAppKey);
  220. return E_FAIL;
  221. }
  222. RegCloseKey (hAppKey );
  223. dw = 0;
  224. while (TRUE)
  225. {
  226. WCHAR szBuffer[256];
  227. WCHAR szServer[256];
  228. DWORD dwType;
  229. wsprintf(szBuffer, L"server%d", dw);
  230. if ( RegQueryValueEx(
  231. hKey,
  232. szBuffer,
  233. NULL,
  234. NULL,
  235. NULL,
  236. &dwSize
  237. ) != ERROR_SUCCESS )
  238. {
  239. break;
  240. }
  241. dw++;
  242. }
  243. *pppServers = (LPWSTR *)CoTaskMemAlloc( dw * sizeof (LPWSTR) );
  244. if ( NULL == *pppServers )
  245. {
  246. return E_OUTOFMEMORY;
  247. }
  248. dw = 0;
  249. while (TRUE)
  250. {
  251. WCHAR szBuffer[256];
  252. WCHAR szServer[256];
  253. DWORD dwType;
  254. wsprintf(szBuffer, L"server%d", dw);
  255. dwSize = 256;
  256. if ( RegQueryValueEx(
  257. hKey,
  258. szBuffer,
  259. NULL,
  260. NULL,
  261. (LPBYTE)szServer,
  262. &dwSize
  263. ) != ERROR_SUCCESS )
  264. {
  265. break;
  266. }
  267. (*pppServers)[dw] = (LPWSTR) CoTaskMemAlloc( (lstrlenW(szServer) + 1) * sizeof(WCHAR));
  268. lstrcpy(
  269. (*pppServers)[dw],
  270. szServer
  271. );
  272. dw++;
  273. }
  274. *pdwNumServers = dw;
  275. RegCloseKey( hKey );
  276. return S_OK;
  277. }