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.

1804 lines
54 KiB

  1. #include "main.h"
  2. #include <initguid.h>
  3. #include "about.h"
  4. #include <gpedit.h>
  5. //
  6. // Global variables for this DLL
  7. //
  8. LONG g_cRefThisDll = 0;
  9. HINSTANCE g_hInstance;
  10. DWORD g_dwNameSpaceItems;
  11. CRITICAL_SECTION g_DCCS;
  12. TCHAR g_szDisplayProperties[150] = {0};
  13. //
  14. // Group Policy Manager's snapin GUID
  15. // {D70A2BEA-A63E-11d1-A7D4-0000F87571E3}
  16. //
  17. DEFINE_GUID(CLSID_GPMSnapIn, 0xd70a2bea, 0xa63e, 0x11d1, 0xa7, 0xd4, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3);
  18. //
  19. // RSOP Context Menu GUID for planning mode
  20. // {63E23168-BFF7-4E87-A246-EF024425E4EC}
  21. //
  22. DEFINE_GUID(CLSID_RSOP_CMenu, 0x63E23168, 0xBFF7, 0x4E87, 0xA2, 0x46, 0xEF, 0x02, 0x44, 0x25, 0xE4, 0xEC);
  23. //
  24. // GPMC Snapin
  25. //
  26. const TCHAR szGPMCSnapIn[] = TEXT("{789D9216-FDF0-476e-9D73-058C6A7375C3}");
  27. //
  28. // DS Admin's snapin ID
  29. //
  30. const TCHAR szDSAdmin[] = TEXT("{E355E538-1C2E-11D0-8C37-00C04FD8FE93}");
  31. //
  32. // Nodes the GPM extends in DS Admin
  33. //
  34. const LPTSTR szDSAdminNodes[] =
  35. {
  36. TEXT("{19195a5b-6da0-11d0-afd3-00c04fd930c9}"), // Domain
  37. TEXT("{bf967aa5-0de6-11d0-a285-00aa003049e2}"), // Organizational unit
  38. };
  39. //
  40. // Site Manager's snapin ID
  41. //
  42. const TCHAR szSiteMgr[] = TEXT("{D967F824-9968-11D0-B936-00C04FD8D5B0}");
  43. //
  44. // Nodes the GPM extends in DS Admin
  45. //
  46. const LPTSTR szSiteMgrNodes[] =
  47. {
  48. TEXT("{bf967ab3-0de6-11d0-a285-00aa003049e2}") // Site
  49. };
  50. const LPTSTR szDSTreeSnapinNodes[] =
  51. {
  52. TEXT("{4c06495e-a241-11d0-b09b-00c04fd8dca6}") // Forest
  53. };
  54. const LPTSTR szDSAdminRsopTargetNodes[] =
  55. {
  56. TEXT("{bf967aba-0de6-11d0-a285-00aa003049e2}"), // user
  57. TEXT("{bf967a86-0de6-11d0-a285-00aa003049e2}") // comp
  58. };
  59. //
  60. // Help topic commands
  61. //
  62. const TCHAR g_szGPERoot[] = TEXT("gpedit.chm::/gpe_default.htm");
  63. const TCHAR g_szUser[] = TEXT("gpedit.chm::/user.htm");
  64. const TCHAR g_szMachine[] = TEXT("gpedit.chm::/machine.htm");
  65. const TCHAR g_szWindows[] = TEXT("gpedit.chm::/windows.htm");
  66. const TCHAR g_szSoftware[] = TEXT("gpedit.chm::/software.htm");
  67. const TCHAR g_szRsopRoot[] = TEXT("rsop.chm::/RSPIntro.htm");
  68. //
  69. // Result pane items for the nodes with no result pane items
  70. //
  71. RESULTITEM g_Undefined[] =
  72. {
  73. { 1, 1, 0, 0, {0} }
  74. };
  75. //
  76. // Namespace (scope) items
  77. //
  78. NAMESPACEITEM g_NameSpace[] =
  79. {
  80. { 0, -1, 2, 2, IDS_SNAPIN_NAME, IDS_SNAPIN_DESCRIPT, 2, {0}, 0, g_Undefined, &NODEID_GPERoot, g_szGPERoot }, // GPE Root
  81. { 1, 0, 4, 4, IDS_MACHINE, IDS_MACHINE_DESC, 2, {0}, 0, g_Undefined, &NODEID_MachineRoot, g_szMachine }, // Computer Configuration
  82. { 2, 0, 5, 5, IDS_USER, IDS_USER_DESC, 2, {0}, 0, g_Undefined, &NODEID_UserRoot, g_szUser }, // User Configuration
  83. { 3, 1, 0, 1, IDS_SWSETTINGS, IDS_C_SWSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_MachineSWSettings, g_szSoftware }, // Computer Configuration\Software Settings
  84. { 4, 1, 0, 1, IDS_WINSETTINGS, IDS_C_WINSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_Machine, g_szWindows }, // Computer Configuration\Windows Settings
  85. { 5, 2, 0, 1, IDS_SWSETTINGS, IDS_U_SWSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_UserSWSettings, g_szSoftware }, // User Configuration\Software Settings
  86. { 6, 2, 0, 1, IDS_WINSETTINGS, IDS_U_WINSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_User, g_szWindows }, // User Configuration\Windows Settings
  87. };
  88. NAMESPACEITEM g_RsopNameSpace[] =
  89. {
  90. { 0, -1, 2, 2, IDS_RSOP_SNAPIN_NAME, IDS_RSOP_SNAPIN_DESCRIPT, 2, {0}, 0, g_Undefined, &NODEID_RSOPRoot, g_szRsopRoot }, // Root of the rsop snapin
  91. { 1, 0, 4, 4, IDS_MACHINE, IDS_MACHINE_DESC, 2, {0}, 0, g_Undefined, &NODEID_RSOPMachineRoot, g_szMachine }, // Computer Configuration
  92. { 2, 0, 5, 5, IDS_USER, IDS_USER_DESC, 2, {0}, 0, g_Undefined, &NODEID_RSOPUserRoot, g_szUser }, // User Configuration
  93. { 3, 1, 0, 1, IDS_SWSETTINGS, IDS_C_SWSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_RSOPMachineSWSettings, g_szSoftware }, // Computer Configuration\Software Settings
  94. { 4, 1, 0, 1, IDS_WINSETTINGS, IDS_C_WINSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_RSOPMachine, g_szWindows }, // Computer Configuration\Windows Settings
  95. { 5, 2, 0, 1, IDS_SWSETTINGS, IDS_U_SWSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_RSOPUserSWSettings, g_szSoftware }, // User Configuration\Software Settings
  96. { 6, 2, 0, 1, IDS_WINSETTINGS, IDS_U_WINSETTINGS_DESC, 0, {0}, 0, g_Undefined, &NODEID_RSOPUser, g_szWindows }, // User Configuration\Windows Settings
  97. };
  98. BOOL InitNameSpace()
  99. {
  100. DWORD dwIndex;
  101. g_dwNameSpaceItems = ARRAYSIZE(g_NameSpace);
  102. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  103. {
  104. if (g_NameSpace[dwIndex].iStringID)
  105. {
  106. LoadString (g_hInstance, g_NameSpace[dwIndex].iStringID,
  107. g_NameSpace[dwIndex].szDisplayName,
  108. MAX_DISPLAYNAME_SIZE);
  109. }
  110. }
  111. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  112. {
  113. if (g_RsopNameSpace[dwIndex].iStringID)
  114. {
  115. LoadString (g_hInstance, g_RsopNameSpace[dwIndex].iStringID,
  116. g_RsopNameSpace[dwIndex].szDisplayName,
  117. MAX_DISPLAYNAME_SIZE);
  118. }
  119. }
  120. return TRUE;
  121. }
  122. /////////////////////////////////////////////////////////////////////////////
  123. // DLL Entry Point
  124. extern "C"
  125. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  126. {
  127. WORD wVersionRequested;
  128. WSADATA wsaData;
  129. if (dwReason == DLL_PROCESS_ATTACH)
  130. {
  131. g_hInstance = hInstance;
  132. DisableThreadLibraryCalls(hInstance);
  133. InitNameSpace();
  134. InitializeCriticalSection(&g_DCCS);
  135. InitDebugSupport();
  136. LoadString (hInstance, IDS_DISPLAYPROPERTIES, g_szDisplayProperties, ARRAYSIZE(g_szDisplayProperties));
  137. wVersionRequested = MAKEWORD( 2, 2 );
  138. // we need to call WSAStartup to do gethostbyname
  139. // Error is handled gracefully. Safe to ignore the error
  140. WSAStartup( wVersionRequested, &wsaData );
  141. }
  142. else if (dwReason == DLL_PROCESS_DETACH)
  143. {
  144. WSACleanup( );
  145. FreeDCSelections();
  146. DeleteCriticalSection(&g_DCCS);
  147. }
  148. return TRUE; // ok
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. // Used to determine whether the DLL can be unloaded by OLE
  152. STDAPI DllCanUnloadNow(void)
  153. {
  154. return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // Returns a class factory to create an object of the requested type
  158. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  159. {
  160. HRESULT hr;
  161. if (IsEqualCLSID (rclsid, CLSID_GPESnapIn)) {
  162. CComponentDataCF *pComponentDataCF = new CComponentDataCF(); // ref == 1
  163. if (!pComponentDataCF)
  164. return E_OUTOFMEMORY;
  165. hr = pComponentDataCF->QueryInterface(riid, ppv);
  166. pComponentDataCF->Release(); // release initial ref
  167. return hr;
  168. }
  169. if (IsEqualCLSID (rclsid, CLSID_GroupPolicyObject)) {
  170. CGroupPolicyObjectCF *pGroupPolicyObjectCF = new CGroupPolicyObjectCF(); // ref == 1
  171. if (!pGroupPolicyObjectCF)
  172. return E_OUTOFMEMORY;
  173. hr = pGroupPolicyObjectCF->QueryInterface(riid, ppv);
  174. pGroupPolicyObjectCF->Release(); // release initial ref
  175. return hr;
  176. }
  177. if (IsEqualCLSID (rclsid, CLSID_GPMSnapIn)) {
  178. CGroupPolicyMgrCF *pGroupPolicyMgrCF = new CGroupPolicyMgrCF(); // ref == 1
  179. if (!pGroupPolicyMgrCF)
  180. return E_OUTOFMEMORY;
  181. hr = pGroupPolicyMgrCF->QueryInterface(riid, ppv);
  182. pGroupPolicyMgrCF->Release(); // release initial ref
  183. return hr;
  184. }
  185. if (IsEqualCLSID (rclsid, CLSID_RSOPSnapIn)) {
  186. CRSOPComponentDataCF *pRSOPComponentDataCF = new CRSOPComponentDataCF(); // ref == 1
  187. if (!pRSOPComponentDataCF)
  188. return E_OUTOFMEMORY;
  189. hr = pRSOPComponentDataCF->QueryInterface(riid, ppv);
  190. pRSOPComponentDataCF->Release(); // release initial ref
  191. return hr;
  192. }
  193. if (IsEqualCLSID (rclsid, CLSID_AboutGPE)) {
  194. CAboutGPECF *pAboutGPECF = new CAboutGPECF(); // ref == 1
  195. if (!pAboutGPECF)
  196. return E_OUTOFMEMORY;
  197. hr = pAboutGPECF->QueryInterface(riid, ppv);
  198. pAboutGPECF->Release(); // release initial ref
  199. return hr;
  200. }
  201. if (IsEqualCLSID (rclsid, CLSID_RSOPAboutGPE)) {
  202. CAboutGPECF *pAboutGPECF = new CAboutGPECF(TRUE); // ref == 1
  203. if (!pAboutGPECF)
  204. return E_OUTOFMEMORY;
  205. hr = pAboutGPECF->QueryInterface(riid, ppv);
  206. pAboutGPECF->Release(); // release initial ref
  207. return hr;
  208. }
  209. if (IsEqualCLSID (rclsid, CLSID_RSOP_CMenu)) {
  210. CRSOPCMenuCF *pRSOPCMenuCF = new CRSOPCMenuCF(); // ref == 1
  211. if (!pRSOPCMenuCF)
  212. return E_OUTOFMEMORY;
  213. hr = pRSOPCMenuCF->QueryInterface(riid, ppv);
  214. pRSOPCMenuCF->Release(); // release initial ref
  215. return hr;
  216. }
  217. return CLASS_E_CLASSNOTAVAILABLE;
  218. }
  219. /////////////////////////////////////////////////////////////////////////////
  220. // DllRegisterServer - Adds entries to the system registry
  221. const TCHAR szDLLLocation[] = TEXT("%SystemRoot%\\System32\\GPEdit.dll");
  222. const TCHAR szThreadingModel[] = TEXT("Apartment");
  223. const TCHAR szSnapInNameIndirect[] = TEXT("@gpedit.dll,-1");
  224. const TCHAR szRsopSnapInNameIndirect[] = TEXT("@gpedit.dll,-4");
  225. const TCHAR szViewDescript [] = TEXT("MMCViewExt 1.0 Object");
  226. const TCHAR szViewGUID [] = TEXT("{B708457E-DB61-4C55-A92F-0D4B5E9B1224}");
  227. const TCHAR szDefRsopMscLocation [] = TEXT("%systemroot%\\system32\\rsop.msc");
  228. STDAPI DllRegisterServer(void)
  229. {
  230. TCHAR szSubKey[200];
  231. TCHAR szSnapInName[100];
  232. TCHAR szSnapInKey[50];
  233. TCHAR szRsopSnapInKey[50];
  234. TCHAR szRsopSnapInName[100];
  235. TCHAR szRsopName[100];
  236. TCHAR szRsopGUID[50];
  237. TCHAR szName[100];
  238. TCHAR szGUID[50];
  239. DWORD dwDisp, dwIndex;
  240. LONG lResult;
  241. HKEY hKey;
  242. INT i;
  243. HKEY hGPMCKey;
  244. DWORD dwError;
  245. HRESULT hr;
  246. //
  247. // Register GPE SnapIn in HKEY_CLASSES_ROOT
  248. //
  249. StringFromGUID2 (CLSID_GPESnapIn, szSnapInKey, 50);
  250. LoadString (g_hInstance, IDS_SNAPIN_NAME, szSnapInName, 100);
  251. hr = StringCchPrintf (szSubKey,
  252. ARRAYSIZE(szSubKey),
  253. TEXT("CLSID\\%s"),
  254. szSnapInKey);
  255. if (FAILED(hr))
  256. {
  257. return hr;
  258. }
  259. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  260. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  261. &hKey, &dwDisp);
  262. if (lResult != ERROR_SUCCESS) {
  263. return SELFREG_E_CLASS;
  264. }
  265. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szSnapInName,
  266. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  267. RegCloseKey (hKey);
  268. hr = StringCchPrintf (szSubKey,
  269. ARRAYSIZE(szSubKey),
  270. TEXT("CLSID\\%s\\InProcServer32"),
  271. szSnapInKey);
  272. if (FAILED(hr))
  273. {
  274. return hr;
  275. }
  276. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  277. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  278. &hKey, &dwDisp);
  279. if (lResult != ERROR_SUCCESS) {
  280. return SELFREG_E_CLASS;
  281. }
  282. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  283. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  284. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  285. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  286. RegCloseKey (hKey);
  287. //
  288. // Register RSOP SnapIn in HKEY_CLASSES_ROOT
  289. //
  290. StringFromGUID2 (CLSID_RSOPSnapIn, szRsopSnapInKey, 50);
  291. LoadString (g_hInstance, IDS_RSOP_SNAPIN_NAME, szRsopSnapInName, 100);
  292. hr = StringCchPrintf (szSubKey,
  293. ARRAYSIZE(szSubKey),
  294. TEXT("CLSID\\%s"),
  295. szRsopSnapInKey);
  296. if (FAILED(hr))
  297. {
  298. return hr;
  299. }
  300. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  301. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  302. &hKey, &dwDisp);
  303. if (lResult != ERROR_SUCCESS) {
  304. return SELFREG_E_CLASS;
  305. }
  306. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szRsopSnapInName,
  307. (lstrlen(szRsopSnapInName) + 1) * sizeof(TCHAR));
  308. RegCloseKey (hKey);
  309. hr = StringCchPrintf (szSubKey,
  310. ARRAYSIZE(szSubKey),
  311. TEXT("CLSID\\%s\\InProcServer32"),
  312. szRsopSnapInKey);
  313. if (FAILED(hr))
  314. {
  315. return hr;
  316. }
  317. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  318. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  319. &hKey, &dwDisp);
  320. if (lResult != ERROR_SUCCESS) {
  321. return SELFREG_E_CLASS;
  322. }
  323. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  324. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  325. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  326. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  327. RegCloseKey (hKey);
  328. //
  329. // Register GPO in HKEY_CLASSES_ROOT
  330. //
  331. StringFromGUID2 (CLSID_GroupPolicyObject, szGUID, 50);
  332. LoadString (g_hInstance, IDS_GPO_NAME, szName, 100);
  333. hr = StringCchPrintf (szSubKey,
  334. ARRAYSIZE(szSubKey),
  335. TEXT("CLSID\\%s"),
  336. szGUID);
  337. if (FAILED(hr))
  338. {
  339. return hr;
  340. }
  341. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  342. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  343. &hKey, &dwDisp);
  344. if (lResult != ERROR_SUCCESS) {
  345. return SELFREG_E_CLASS;
  346. }
  347. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szName,
  348. (lstrlen(szName) + 1) * sizeof(TCHAR));
  349. RegCloseKey (hKey);
  350. hr = StringCchPrintf (szSubKey,
  351. ARRAYSIZE(szSubKey),
  352. TEXT("CLSID\\%s\\InProcServer32"),
  353. szGUID);
  354. if (FAILED(hr))
  355. {
  356. return hr;
  357. }
  358. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  359. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  360. &hKey, &dwDisp);
  361. if (lResult != ERROR_SUCCESS) {
  362. return SELFREG_E_CLASS;
  363. }
  364. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  365. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  366. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  367. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  368. RegCloseKey (hKey);
  369. //
  370. // Register AboutGPE in HKEY_CLASSES_ROOT
  371. //
  372. StringFromGUID2 (CLSID_AboutGPE, szGUID, 50);
  373. LoadString (g_hInstance, IDS_ABOUT_NAME, szName, 100);
  374. hr = StringCchPrintf (szSubKey,
  375. ARRAYSIZE(szSubKey),
  376. TEXT("CLSID\\%s"),
  377. szGUID);
  378. if (FAILED(hr))
  379. {
  380. return hr;
  381. }
  382. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  383. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  384. &hKey, &dwDisp);
  385. if (lResult != ERROR_SUCCESS) {
  386. return SELFREG_E_CLASS;
  387. }
  388. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szName,
  389. (lstrlen(szName) + 1) * sizeof(TCHAR));
  390. RegCloseKey (hKey);
  391. hr = StringCchPrintf (szSubKey,
  392. ARRAYSIZE(szSubKey),
  393. TEXT("CLSID\\%s\\InProcServer32"),
  394. szGUID);
  395. if (FAILED(hr))
  396. {
  397. return hr;
  398. }
  399. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  400. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  401. &hKey, &dwDisp);
  402. if (lResult != ERROR_SUCCESS) {
  403. return SELFREG_E_CLASS;
  404. }
  405. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  406. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  407. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  408. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  409. RegCloseKey (hKey);
  410. //
  411. // Register RSOPAboutGPE in HKEY_CLASSES_ROOT
  412. //
  413. StringFromGUID2 (CLSID_RSOPAboutGPE, szGUID, 50);
  414. LoadString (g_hInstance, IDS_ABOUT_NAME, szName, 100);
  415. hr = StringCchPrintf (szSubKey,
  416. ARRAYSIZE(szSubKey),
  417. TEXT("CLSID\\%s"),
  418. szGUID);
  419. if (FAILED(hr))
  420. {
  421. return hr;
  422. }
  423. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  424. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  425. &hKey, &dwDisp);
  426. if (lResult != ERROR_SUCCESS) {
  427. return SELFREG_E_CLASS;
  428. }
  429. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szName,
  430. (lstrlen(szName) + 1) * sizeof(TCHAR));
  431. RegCloseKey (hKey);
  432. hr = StringCchPrintf (szSubKey,
  433. ARRAYSIZE(szSubKey),
  434. TEXT("CLSID\\%s\\InProcServer32"),
  435. szGUID);
  436. if (FAILED(hr))
  437. {
  438. return hr;
  439. }
  440. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  441. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  442. &hKey, &dwDisp);
  443. if (lResult != ERROR_SUCCESS) {
  444. return SELFREG_E_CLASS;
  445. }
  446. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  447. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  448. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  449. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  450. RegCloseKey (hKey);
  451. //
  452. // Register GPE SnapIn with MMC
  453. //
  454. StringFromGUID2 (CLSID_GPESnapIn, szSnapInKey, 50);
  455. LoadString (g_hInstance, IDS_SNAPIN_NAME, szSnapInName, 100);
  456. hr = StringCchPrintf (szSubKey,
  457. ARRAYSIZE(szSubKey),
  458. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  459. szSnapInKey);
  460. if (FAILED(hr))
  461. {
  462. return hr;
  463. }
  464. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  465. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  466. &hKey, &dwDisp);
  467. if (lResult != ERROR_SUCCESS) {
  468. return SELFREG_E_CLASS;
  469. }
  470. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szSnapInName,
  471. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  472. RegSetValueEx (hKey, TEXT("NameStringIndirect"), 0, REG_SZ, (LPBYTE)szSnapInNameIndirect,
  473. (lstrlen(szSnapInNameIndirect) + 1) * sizeof(TCHAR));
  474. StringFromGUID2 (CLSID_AboutGPE, szGUID, 50);
  475. RegSetValueEx (hKey, TEXT("About"), 0, REG_SZ, (LPBYTE) szGUID,
  476. (lstrlen(szGUID) + 1) * sizeof(TCHAR));
  477. RegCloseKey (hKey);
  478. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  479. {
  480. StringFromGUID2 (*g_NameSpace[dwIndex].pNodeID, szGUID, 50);
  481. hr = StringCchPrintf (szSubKey,
  482. ARRAYSIZE(szSubKey),
  483. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  484. szSnapInKey,
  485. szGUID);
  486. if (FAILED(hr))
  487. {
  488. return hr;
  489. }
  490. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  491. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  492. &hKey, &dwDisp);
  493. if (lResult != ERROR_SUCCESS) {
  494. return SELFREG_E_CLASS;
  495. }
  496. RegCloseKey (hKey);
  497. }
  498. hr = StringCchPrintf (szSubKey,
  499. ARRAYSIZE(szSubKey),
  500. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\StandAlone"),
  501. szSnapInKey);
  502. if (FAILED(hr))
  503. {
  504. return hr;
  505. }
  506. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  507. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  508. &hKey, &dwDisp);
  509. if (lResult != ERROR_SUCCESS) {
  510. return SELFREG_E_CLASS;
  511. }
  512. RegCloseKey (hKey);
  513. //
  514. // Register RSOP SnapIn with MMC
  515. //
  516. StringFromGUID2 (CLSID_RSOPSnapIn, szRsopSnapInKey, 50);
  517. LoadString (g_hInstance, IDS_RSOP_SNAPIN_NAME, szRsopSnapInName, 100);
  518. hr = StringCchPrintf (szSubKey,
  519. ARRAYSIZE(szSubKey),
  520. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  521. szRsopSnapInKey);
  522. if (FAILED(hr))
  523. {
  524. return hr;
  525. }
  526. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  527. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  528. &hKey, &dwDisp);
  529. if (lResult != ERROR_SUCCESS) {
  530. return SELFREG_E_CLASS;
  531. }
  532. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szRsopSnapInName,
  533. (lstrlen(szRsopSnapInName) + 1) * sizeof(TCHAR));
  534. RegSetValueEx (hKey, TEXT("NameStringIndirect"), 0, REG_SZ, (LPBYTE)szRsopSnapInNameIndirect,
  535. (lstrlen(szRsopSnapInNameIndirect) + 1) * sizeof(TCHAR));
  536. StringFromGUID2 (CLSID_RSOPAboutGPE, szGUID, 50);
  537. RegSetValueEx (hKey, TEXT("About"), 0, REG_SZ, (LPBYTE) szGUID,
  538. (lstrlen(szGUID) + 1) * sizeof(TCHAR));
  539. RegCloseKey (hKey);
  540. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  541. {
  542. StringFromGUID2 (*g_RsopNameSpace[dwIndex].pNodeID, szGUID, 50);
  543. hr = StringCchPrintf (szSubKey,
  544. ARRAYSIZE(szSubKey),
  545. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  546. szRsopSnapInKey,
  547. szGUID);
  548. if (FAILED(hr))
  549. {
  550. return hr;
  551. }
  552. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  553. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  554. &hKey, &dwDisp);
  555. if (lResult != ERROR_SUCCESS) {
  556. return SELFREG_E_CLASS;
  557. }
  558. RegCloseKey (hKey);
  559. }
  560. hr = StringCchPrintf (szSubKey,
  561. ARRAYSIZE(szSubKey),
  562. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\StandAlone"),
  563. szRsopSnapInKey);
  564. if (FAILED(hr))
  565. {
  566. return hr;
  567. }
  568. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  569. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  570. &hKey, &dwDisp);
  571. if (lResult != ERROR_SUCCESS) {
  572. return SELFREG_E_CLASS;
  573. }
  574. RegCloseKey (hKey);
  575. //
  576. // Register in the NodeTypes key and register for the view extension
  577. //
  578. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  579. {
  580. StringFromGUID2 (*g_NameSpace[dwIndex].pNodeID, szGUID, 50);
  581. hr = StringCchPrintf (szSubKey,
  582. ARRAYSIZE(szSubKey),
  583. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\View"),
  584. szGUID);
  585. if (FAILED(hr))
  586. {
  587. return hr;
  588. }
  589. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  590. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  591. &hKey, &dwDisp);
  592. if (lResult != ERROR_SUCCESS) {
  593. return SELFREG_E_CLASS;
  594. }
  595. RegSetValueEx (hKey, szViewGUID, 0, REG_SZ, (LPBYTE)szViewDescript,
  596. (lstrlen(szViewDescript) + 1) * sizeof(TCHAR));
  597. RegCloseKey (hKey);
  598. StringFromGUID2 (*g_RsopNameSpace[dwIndex].pNodeID, szGUID, 50);
  599. hr = StringCchPrintf (szSubKey,
  600. ARRAYSIZE(szSubKey),
  601. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\View"),
  602. szGUID);
  603. if (FAILED(hr))
  604. {
  605. return hr;
  606. }
  607. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  608. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  609. &hKey, &dwDisp);
  610. if (lResult != ERROR_SUCCESS) {
  611. return SELFREG_E_CLASS;
  612. }
  613. RegSetValueEx (hKey, szViewGUID, 0, REG_SZ, (LPBYTE)szViewDescript,
  614. (lstrlen(szViewDescript) + 1) * sizeof(TCHAR));
  615. RegCloseKey (hKey);
  616. }
  617. //
  618. // Register GPM SnapIn in HKEY_CLASSES_ROOT
  619. //
  620. StringFromGUID2 (CLSID_GPMSnapIn, szSnapInKey, 50);
  621. LoadString (g_hInstance, IDS_GPM_SNAPIN_NAME, szSnapInName, 100);
  622. hr = StringCchPrintf (szSubKey,
  623. ARRAYSIZE(szSubKey),
  624. TEXT("CLSID\\%s"),
  625. szSnapInKey);
  626. if (FAILED(hr))
  627. {
  628. return hr;
  629. }
  630. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  631. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  632. &hKey, &dwDisp);
  633. if (lResult != ERROR_SUCCESS) {
  634. return SELFREG_E_CLASS;
  635. }
  636. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szSnapInName,
  637. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  638. RegCloseKey (hKey);
  639. hr = StringCchPrintf (szSubKey,
  640. ARRAYSIZE(szSubKey),
  641. TEXT("CLSID\\%s\\InProcServer32"),
  642. szSnapInKey);
  643. if (FAILED(hr))
  644. {
  645. return hr;
  646. }
  647. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  648. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  649. &hKey, &dwDisp);
  650. if (lResult != ERROR_SUCCESS) {
  651. return SELFREG_E_CLASS;
  652. }
  653. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  654. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  655. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  656. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  657. RegCloseKey (hKey);
  658. //
  659. // Register GPMSnapIn with MMC
  660. //
  661. hr = StringCchPrintf (szSubKey,
  662. ARRAYSIZE(szSubKey),
  663. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  664. szSnapInKey);
  665. if (FAILED(hr))
  666. {
  667. return hr;
  668. }
  669. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  670. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  671. &hKey, &dwDisp);
  672. if (lResult != ERROR_SUCCESS) {
  673. return SELFREG_E_CLASS;
  674. }
  675. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szSnapInName,
  676. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  677. RegSetValueEx (hKey, TEXT("NameStringIndirect"), 0, REG_SZ, (LPBYTE)szSnapInNameIndirect,
  678. (lstrlen(szSnapInNameIndirect) + 1) * sizeof(TCHAR));
  679. RegCloseKey (hKey);
  680. //
  681. // Check if GPMC is running already
  682. // If so, register CLSID of GPMC Snapin
  683. //
  684. dwError = RegOpenKeyEx ( HKEY_LOCAL_MACHINE,
  685. L"Software\\Microsoft\\Group Policy Management Console",
  686. 0,
  687. KEY_QUERY_VALUE,
  688. &hGPMCKey );
  689. if (ERROR_SUCCESS == dwError)
  690. {
  691. RegCloseKey(hGPMCKey);
  692. hr = StringCchCopy (szSnapInKey,ARRAYSIZE(szSnapInKey), szGPMCSnapIn);
  693. if (FAILED(hr))
  694. {
  695. return hr;
  696. }
  697. }
  698. //
  699. // Register as a DS admin property sheet extension
  700. //
  701. for (i=0; i < ARRAYSIZE(szDSAdminNodes); i++)
  702. {
  703. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSAdminNodes[i]);
  704. if (FAILED(hr))
  705. {
  706. return hr;
  707. }
  708. hr = StringCchPrintf (szSubKey,
  709. ARRAYSIZE(szSubKey),
  710. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  711. szDSAdmin,
  712. szGUID);
  713. if (FAILED(hr))
  714. {
  715. return hr;
  716. }
  717. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  718. szSubKey,
  719. 0, NULL,
  720. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  721. &hKey, &dwDisp);
  722. if (lResult != ERROR_SUCCESS) {
  723. return SELFREG_E_CLASS;
  724. }
  725. RegCloseKey (hKey);
  726. hr = StringCchPrintf (szSubKey,
  727. ARRAYSIZE(szSubKey),
  728. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  729. szGUID);
  730. if (FAILED(hr))
  731. {
  732. return hr;
  733. }
  734. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  735. szSubKey,
  736. 0, NULL,
  737. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  738. &hKey, &dwDisp);
  739. if (lResult != ERROR_SUCCESS) {
  740. return SELFREG_E_CLASS;
  741. }
  742. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  743. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  744. RegCloseKey (hKey);
  745. }
  746. //
  747. // Register as a site mgr property sheet extension
  748. //
  749. for (i=0; i < ARRAYSIZE(szSiteMgrNodes); i++)
  750. {
  751. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szSiteMgrNodes[i]);
  752. if (FAILED(hr))
  753. {
  754. return hr;
  755. }
  756. hr = StringCchPrintf (szSubKey,
  757. ARRAYSIZE(szSubKey),
  758. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  759. szSiteMgr,
  760. szGUID);
  761. if (FAILED(hr))
  762. {
  763. return hr;
  764. }
  765. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  766. szSubKey,
  767. 0, NULL,
  768. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  769. &hKey, &dwDisp);
  770. if (lResult != ERROR_SUCCESS) {
  771. return SELFREG_E_CLASS;
  772. }
  773. RegCloseKey (hKey);
  774. hr = StringCchPrintf (szSubKey,
  775. ARRAYSIZE(szSubKey),
  776. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  777. szGUID);
  778. if (FAILED(hr))
  779. {
  780. return hr;
  781. }
  782. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  783. szSubKey,
  784. 0, NULL,
  785. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  786. &hKey, &dwDisp);
  787. if (lResult != ERROR_SUCCESS) {
  788. return SELFREG_E_CLASS;
  789. }
  790. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  791. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  792. RegCloseKey (hKey);
  793. }
  794. //
  795. // Register RSOP Context Menu in HKEY_CLASSES_ROOT
  796. //
  797. StringFromGUID2 (CLSID_RSOP_CMenu, szSnapInKey, 50);
  798. LoadString (g_hInstance, IDS_RSOP_CMENU_NAME, szSnapInName, 100);
  799. hr = StringCchPrintf (szSubKey,
  800. ARRAYSIZE(szSubKey),
  801. TEXT("CLSID\\%s"),
  802. szSnapInKey);
  803. if (FAILED(hr))
  804. {
  805. return hr;
  806. }
  807. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  808. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  809. &hKey, &dwDisp);
  810. if (lResult != ERROR_SUCCESS) {
  811. return SELFREG_E_CLASS;
  812. }
  813. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szSnapInName,
  814. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  815. RegCloseKey (hKey);
  816. hr = StringCchPrintf (szSubKey,
  817. ARRAYSIZE(szSubKey),
  818. TEXT("CLSID\\%s\\InProcServer32"),
  819. szSnapInKey);
  820. if (FAILED(hr))
  821. {
  822. return hr;
  823. }
  824. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  825. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  826. &hKey, &dwDisp);
  827. if (lResult != ERROR_SUCCESS) {
  828. return SELFREG_E_CLASS;
  829. }
  830. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szDLLLocation,
  831. (lstrlen(szDLLLocation) + 1) * sizeof(TCHAR));
  832. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)szThreadingModel,
  833. (lstrlen(szThreadingModel) + 1) * sizeof(TCHAR));
  834. RegCloseKey (hKey);
  835. //
  836. // Register RSOP Context Menu with MMC.
  837. // !!!!! Check whether this is necessary
  838. //
  839. hr = StringCchPrintf (szSubKey,
  840. ARRAYSIZE(szSubKey),
  841. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  842. szSnapInKey);
  843. if (FAILED(hr))
  844. {
  845. return hr;
  846. }
  847. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  848. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  849. &hKey, &dwDisp);
  850. if (lResult != ERROR_SUCCESS) {
  851. return SELFREG_E_CLASS;
  852. }
  853. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szSnapInName,
  854. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  855. RegSetValueEx (hKey, TEXT("NameStringIndirect"), 0, REG_SZ, (LPBYTE)szSnapInNameIndirect,
  856. (lstrlen(szSnapInNameIndirect) + 1) * sizeof(TCHAR));
  857. RegCloseKey (hKey);
  858. //
  859. // Register as a DS admin task menu extension
  860. //
  861. for (i=0; i < ARRAYSIZE(szDSAdminNodes); i++)
  862. {
  863. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSAdminNodes[i]);
  864. if (FAILED(hr))
  865. {
  866. return hr;
  867. }
  868. hr = StringCchPrintf (szSubKey,
  869. ARRAYSIZE(szSubKey),
  870. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  871. szDSAdmin,
  872. szGUID);
  873. if (FAILED(hr))
  874. {
  875. return hr;
  876. }
  877. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  878. szSubKey,
  879. 0, NULL,
  880. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  881. &hKey, &dwDisp);
  882. if (lResult != ERROR_SUCCESS) {
  883. return SELFREG_E_CLASS;
  884. }
  885. RegCloseKey (hKey);
  886. hr = StringCchPrintf (szSubKey,
  887. ARRAYSIZE(szSubKey),
  888. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  889. szGUID);
  890. if (FAILED(hr))
  891. {
  892. return hr;
  893. }
  894. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  895. szSubKey,
  896. 0, NULL,
  897. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  898. &hKey, &dwDisp);
  899. if (lResult != ERROR_SUCCESS) {
  900. return SELFREG_E_CLASS;
  901. }
  902. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  903. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  904. RegCloseKey (hKey);
  905. }
  906. //
  907. // Register as a DS admin rsop target task menu extension
  908. //
  909. for (i=0; i < ARRAYSIZE(szDSAdminRsopTargetNodes); i++)
  910. {
  911. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSAdminRsopTargetNodes[i]);
  912. if (FAILED(hr))
  913. {
  914. return hr;
  915. }
  916. hr = StringCchPrintf (szSubKey,
  917. ARRAYSIZE(szSubKey),
  918. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  919. szDSAdmin,
  920. szGUID);
  921. if (FAILED(hr))
  922. {
  923. return hr;
  924. }
  925. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  926. szSubKey,
  927. 0, NULL,
  928. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  929. &hKey, &dwDisp);
  930. if (lResult != ERROR_SUCCESS) {
  931. return SELFREG_E_CLASS;
  932. }
  933. RegCloseKey (hKey);
  934. hr = StringCchPrintf (szSubKey,
  935. ARRAYSIZE(szSubKey),
  936. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  937. szGUID);
  938. if (FAILED(hr))
  939. {
  940. return hr;
  941. }
  942. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  943. szSubKey,
  944. 0, NULL,
  945. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  946. &hKey, &dwDisp);
  947. if (lResult != ERROR_SUCCESS) {
  948. return SELFREG_E_CLASS;
  949. }
  950. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  951. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  952. RegCloseKey (hKey);
  953. }
  954. //
  955. // Register as a site mgr task menu extension
  956. //
  957. for (i=0; i < ARRAYSIZE(szSiteMgrNodes); i++)
  958. {
  959. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szSiteMgrNodes[i]);
  960. if (FAILED(hr))
  961. {
  962. return hr;
  963. }
  964. hr = StringCchPrintf (szSubKey,
  965. ARRAYSIZE(szSubKey),
  966. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  967. szSiteMgr,
  968. szGUID);
  969. if (FAILED(hr))
  970. {
  971. return hr;
  972. }
  973. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  974. szSubKey,
  975. 0, NULL,
  976. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  977. &hKey, &dwDisp);
  978. if (lResult != ERROR_SUCCESS) {
  979. return SELFREG_E_CLASS;
  980. }
  981. RegCloseKey (hKey);
  982. hr = StringCchPrintf (szSubKey,
  983. ARRAYSIZE(szSubKey),
  984. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  985. szGUID);
  986. if (FAILED(hr))
  987. {
  988. return hr;
  989. }
  990. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  991. szSubKey,
  992. 0, NULL,
  993. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  994. &hKey, &dwDisp);
  995. if (lResult != ERROR_SUCCESS) {
  996. return SELFREG_E_CLASS;
  997. }
  998. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  999. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  1000. RegCloseKey (hKey);
  1001. }
  1002. //
  1003. // Mark the authormode rsop.msc as read only
  1004. //
  1005. TCHAR szRsopMscFileName[MAX_PATH+1];
  1006. if (ExpandEnvironmentStrings(szDefRsopMscLocation, szRsopMscFileName, MAX_PATH+1)) {
  1007. SetFileAttributes(szRsopMscFileName, FILE_ATTRIBUTE_READONLY);
  1008. }
  1009. else {
  1010. DebugMsg((DM_WARNING, TEXT("DllRegisterServer: ExpandEnvironmentStrings failed with error %d"), GetLastError()));
  1011. }
  1012. #if FGPO_SUPPORT
  1013. // register as a DSTree snapin property sheet extension
  1014. for (i=0; i < ARRAYSIZE(szDSTreeSnapinNodes); i++)
  1015. {
  1016. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSTreeSnapinNodes[i]);
  1017. if (FAILED(hr))
  1018. {
  1019. return hr;
  1020. }
  1021. hr = StringCchPrintf (szSubKey,
  1022. ARRAYSIZE(szSubKey),
  1023. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  1024. szSiteMgr,
  1025. szGUID);
  1026. if (FAILED(hr))
  1027. {
  1028. return hr;
  1029. }
  1030. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  1031. szSubKey,
  1032. 0, NULL,
  1033. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  1034. &hKey, &dwDisp);
  1035. if (lResult != ERROR_SUCCESS) {
  1036. return SELFREG_E_CLASS;
  1037. }
  1038. RegCloseKey (hKey);
  1039. hr = StringCchPrintf (szSubKey,
  1040. ARRAYSIZE(szSubKey),
  1041. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  1042. szGUID);
  1043. if (FAILED(hr))
  1044. {
  1045. return hr;
  1046. }
  1047. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  1048. szSubKey,
  1049. 0, NULL,
  1050. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  1051. &hKey, &dwDisp);
  1052. if (lResult != ERROR_SUCCESS) {
  1053. return SELFREG_E_CLASS;
  1054. }
  1055. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  1056. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  1057. RegCloseKey (hKey);
  1058. }
  1059. #else
  1060. for (i=0; i < ARRAYSIZE(szDSTreeSnapinNodes); i++)
  1061. {
  1062. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSTreeSnapinNodes[i]);
  1063. if (FAILED(hr))
  1064. {
  1065. return hr;
  1066. }
  1067. hr = StringCchPrintf (szSubKey,
  1068. ARRAYSIZE(szSubKey),
  1069. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  1070. szGUID);
  1071. if (FAILED(hr))
  1072. {
  1073. return hr;
  1074. }
  1075. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1076. szSubKey,
  1077. 0,
  1078. KEY_WRITE, &hKey);
  1079. if (lResult == ERROR_SUCCESS) {
  1080. RegDeleteValue (hKey, szSnapInKey);
  1081. RegCloseKey (hKey);
  1082. }
  1083. }
  1084. #endif
  1085. return S_OK;
  1086. }
  1087. /////////////////////////////////////////////////////////////////////////////
  1088. // DllUnregisterServer - Removes entries from the system registry
  1089. STDAPI DllUnregisterServer(void)
  1090. {
  1091. TCHAR szSubKey[200];
  1092. TCHAR szGUID[50];
  1093. TCHAR szSnapInKey[50];
  1094. DWORD dwIndex;
  1095. LONG lResult;
  1096. INT i;
  1097. HKEY hKey;
  1098. HRESULT hr;
  1099. //
  1100. // Unregister GPE
  1101. //
  1102. StringFromGUID2 (CLSID_GPESnapIn, szSnapInKey, 50);
  1103. hr = StringCchPrintf (szSubKey,
  1104. ARRAYSIZE(szSubKey),
  1105. TEXT("CLSID\\%s"),
  1106. szSnapInKey);
  1107. if (SUCCEEDED(hr))
  1108. {
  1109. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1110. }
  1111. hr = StringCchPrintf (szSubKey,
  1112. ARRAYSIZE(szSubKey),
  1113. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  1114. szSnapInKey);
  1115. if (SUCCEEDED(hr))
  1116. {
  1117. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  1118. }
  1119. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  1120. {
  1121. StringFromGUID2 (*g_NameSpace[dwIndex].pNodeID, szSnapInKey, 50);
  1122. hr = StringCchPrintf (szSubKey,
  1123. ARRAYSIZE(szSubKey),
  1124. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s"),
  1125. szSnapInKey);
  1126. if (SUCCEEDED(hr))
  1127. {
  1128. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  1129. }
  1130. }
  1131. //
  1132. // Unregister RSOP
  1133. //
  1134. StringFromGUID2 (CLSID_RSOPSnapIn, szSnapInKey, 50);
  1135. hr = StringCchPrintf (szSubKey,
  1136. ARRAYSIZE(szSubKey),
  1137. TEXT("CLSID\\%s"),
  1138. szSnapInKey);
  1139. if (SUCCEEDED(hr))
  1140. {
  1141. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1142. }
  1143. hr = StringCchPrintf (szSubKey,
  1144. ARRAYSIZE(szSubKey),
  1145. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  1146. szSnapInKey);
  1147. if (SUCCEEDED(hr))
  1148. {
  1149. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  1150. }
  1151. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  1152. {
  1153. StringFromGUID2 (*g_RsopNameSpace[dwIndex].pNodeID, szSnapInKey, 50); // undone
  1154. hr = StringCchPrintf (szSubKey,
  1155. ARRAYSIZE(szSubKey),
  1156. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s"),
  1157. szSnapInKey);
  1158. if (SUCCEEDED(hr))
  1159. {
  1160. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  1161. }
  1162. }
  1163. //
  1164. // Unregister GPO
  1165. //
  1166. StringFromGUID2 (CLSID_GroupPolicyObject, szSnapInKey, 50);
  1167. hr = StringCchPrintf (szSubKey,
  1168. ARRAYSIZE(szSubKey),
  1169. TEXT("CLSID\\%s"),
  1170. szSnapInKey);
  1171. if (SUCCEEDED(hr))
  1172. {
  1173. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1174. }
  1175. //
  1176. // Unregister AboutGPE
  1177. //
  1178. StringFromGUID2 (CLSID_AboutGPE, szSnapInKey, 50);
  1179. hr = StringCchPrintf (szSubKey,
  1180. ARRAYSIZE(szSubKey),
  1181. TEXT("CLSID\\%s"),
  1182. szSnapInKey);
  1183. if (SUCCEEDED(hr))
  1184. {
  1185. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1186. }
  1187. //
  1188. // Unregister RSOPAboutGPE
  1189. //
  1190. StringFromGUID2 (CLSID_RSOPAboutGPE, szSnapInKey, 50);
  1191. hr = StringCchPrintf (szSubKey,
  1192. ARRAYSIZE(szSubKey),
  1193. TEXT("CLSID\\%s"),
  1194. szSnapInKey);
  1195. if (SUCCEEDED(hr))
  1196. {
  1197. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1198. }
  1199. //
  1200. // Unregister GPM
  1201. //
  1202. StringFromGUID2 (CLSID_GPMSnapIn, szSnapInKey, 50);
  1203. hr = StringCchPrintf (szSubKey,
  1204. ARRAYSIZE(szSubKey),
  1205. TEXT("CLSID\\%s"),
  1206. szSnapInKey);
  1207. if (SUCCEEDED(hr))
  1208. {
  1209. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1210. }
  1211. hr = StringCchPrintf (szSubKey,
  1212. ARRAYSIZE(szSubKey),
  1213. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  1214. szSnapInKey);
  1215. if (SUCCEEDED(hr))
  1216. {
  1217. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  1218. }
  1219. for (i=0; i < ARRAYSIZE(szDSAdminNodes); i++)
  1220. {
  1221. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSAdminNodes[i]);
  1222. if (SUCCEEDED(hr))
  1223. {
  1224. hr = StringCchPrintf (szSubKey,
  1225. ARRAYSIZE(szSubKey),
  1226. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  1227. szGUID);
  1228. }
  1229. if (SUCCEEDED(hr))
  1230. {
  1231. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1232. szSubKey,
  1233. 0,
  1234. KEY_WRITE, &hKey);
  1235. if (lResult == ERROR_SUCCESS) {
  1236. RegDeleteValue (hKey, szSnapInKey);
  1237. RegCloseKey (hKey);
  1238. }
  1239. }
  1240. }
  1241. for (i=0; i < ARRAYSIZE(szSiteMgrNodes); i++)
  1242. {
  1243. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szSiteMgrNodes[i]);
  1244. if (SUCCEEDED(hr))
  1245. {
  1246. hr = StringCchPrintf (szSubKey,
  1247. ARRAYSIZE(szSubKey),
  1248. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  1249. szGUID);
  1250. }
  1251. if (SUCCEEDED(hr))
  1252. {
  1253. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1254. szSubKey,
  1255. 0,
  1256. KEY_WRITE, &hKey);
  1257. if (lResult == ERROR_SUCCESS) {
  1258. RegDeleteValue (hKey, szSnapInKey);
  1259. RegCloseKey (hKey);
  1260. }
  1261. }
  1262. }
  1263. //
  1264. // Unregister rsop context menu
  1265. //
  1266. StringFromGUID2 (CLSID_RSOP_CMenu, szSnapInKey, 50);
  1267. hr = StringCchPrintf (szSubKey,
  1268. ARRAYSIZE(szSubKey),
  1269. TEXT("CLSID\\%s"),
  1270. szSnapInKey);
  1271. if (SUCCEEDED(hr))
  1272. {
  1273. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  1274. }
  1275. hr = StringCchPrintf (szSubKey,
  1276. ARRAYSIZE(szSubKey),
  1277. TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"),
  1278. szSnapInKey);
  1279. if (SUCCEEDED(hr))
  1280. {
  1281. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  1282. }
  1283. //
  1284. // from ds admin nodes
  1285. //
  1286. for (i=0; i < ARRAYSIZE(szDSAdminNodes); i++)
  1287. {
  1288. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSAdminNodes[i]);
  1289. if (SUCCEEDED(hr))
  1290. {
  1291. hr = StringCchPrintf (szSubKey,
  1292. ARRAYSIZE(szSubKey),
  1293. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  1294. szGUID);
  1295. }
  1296. if (SUCCEEDED(hr))
  1297. {
  1298. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1299. szSubKey,
  1300. 0,
  1301. KEY_WRITE, &hKey);
  1302. if (lResult == ERROR_SUCCESS) {
  1303. RegDeleteValue (hKey, szSnapInKey);
  1304. RegCloseKey (hKey);
  1305. }
  1306. }
  1307. }
  1308. for (i=0; i < ARRAYSIZE(szDSAdminRsopTargetNodes); i++)
  1309. {
  1310. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSAdminRsopTargetNodes[i]);
  1311. if (SUCCEEDED(hr))
  1312. {
  1313. hr = StringCchPrintf (szSubKey,
  1314. ARRAYSIZE(szSubKey),
  1315. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  1316. szGUID);
  1317. }
  1318. if (SUCCEEDED(hr))
  1319. {
  1320. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1321. szSubKey,
  1322. 0,
  1323. KEY_WRITE, &hKey);
  1324. if (lResult == ERROR_SUCCESS) {
  1325. RegDeleteValue (hKey, szSnapInKey);
  1326. RegCloseKey (hKey);
  1327. }
  1328. }
  1329. }
  1330. //
  1331. // from sites node
  1332. //
  1333. for (i=0; i < ARRAYSIZE(szSiteMgrNodes); i++)
  1334. {
  1335. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szSiteMgrNodes[i]);
  1336. if (SUCCEEDED(hr))
  1337. {
  1338. hr = StringCchPrintf (szSubKey,
  1339. ARRAYSIZE(szSubKey),
  1340. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  1341. szGUID);
  1342. }
  1343. if (SUCCEEDED(hr))
  1344. {
  1345. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1346. szSubKey,
  1347. 0,
  1348. KEY_WRITE, &hKey);
  1349. if (lResult == ERROR_SUCCESS) {
  1350. RegDeleteValue (hKey, szSnapInKey);
  1351. RegCloseKey (hKey);
  1352. }
  1353. }
  1354. }
  1355. for (i=0; i < ARRAYSIZE(szDSTreeSnapinNodes); i++)
  1356. {
  1357. hr = StringCchCopy (szGUID, ARRAYSIZE(szGUID), szDSTreeSnapinNodes[i]);
  1358. if (SUCCEEDED(hr))
  1359. {
  1360. hr = StringCchPrintf (szSubKey,
  1361. ARRAYSIZE(szSubKey),
  1362. TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\PropertySheet"),
  1363. szGUID);
  1364. }
  1365. if (SUCCEEDED(hr))
  1366. {
  1367. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1368. szSubKey,
  1369. 0,
  1370. KEY_WRITE, &hKey);
  1371. if (lResult == ERROR_SUCCESS) {
  1372. RegDeleteValue (hKey, szSnapInKey);
  1373. RegCloseKey (hKey);
  1374. }
  1375. }
  1376. }
  1377. return S_OK;
  1378. }