Source code of Windows XP (NT5)
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.

789 lines
28 KiB

  1. /*++
  2. Copyright (C) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. smlogcfg.cpp
  5. Abstract:
  6. Implementation of DLL exports.
  7. --*/
  8. // Note: Proxy/Stub Information
  9. // To build a separate proxy/stub DLL,
  10. // run nmake -f Smlogcfgps.mk in the project directory.
  11. #include "StdAfx.h"
  12. #include "InitGuid.h"
  13. #include "compdata.h"
  14. #include "smabout.h"
  15. #include "smlogcfg.h" // For CLSID_ComponentData
  16. #include "Smlogcfg_i.c" // For CLSID_ComponentData
  17. #include <ntverp.h>
  18. USE_HANDLE_MACROS("SMLOGCFG(smlogcfg.cpp)")
  19. CComModule _Module;
  20. BEGIN_OBJECT_MAP(ObjectMap)
  21. OBJECT_ENTRY(CLSID_ComponentData, CSmLogSnapin)
  22. OBJECT_ENTRY(CLSID_ExtensionSnapin, CSmLogExtension)
  23. OBJECT_ENTRY(CLSID_PerformanceAbout, CSmLogAbout)
  24. END_OBJECT_MAP()
  25. LPCTSTR g_cszBasePath = _T("Software\\Microsoft\\MMC\\SnapIns");
  26. LPCTSTR g_cszBaseNodeTypes = _T("Software\\Microsoft\\MMC\\NodeTypes");
  27. LPCTSTR g_cszNameString = _T("NameString");
  28. LPCTSTR g_cszNameStringIndirect = _T("NameStringIndirect");
  29. LPCTSTR g_cszProvider = _T("Provider");
  30. LPCTSTR g_cszVersion = _T("Version");
  31. LPCTSTR g_cszAbout = _T("About");
  32. LPCTSTR g_cszStandAlone = _T("StandAlone");
  33. LPCTSTR g_cszNodeType = _T("NodeType");
  34. LPCTSTR g_cszNodeTypes = _T("NodeTypes");
  35. LPCTSTR g_cszExtensions = _T("Extensions");
  36. LPCTSTR g_cszNameSpace = _T("NameSpace");
  37. LPCTSTR g_cszRootNode = _T("Root Node");
  38. LPCTSTR g_cszCounterLogsChild = _T("Performance Data Logs Child Under Root Node");
  39. LPCTSTR g_cszTraceLogsChild = _T("System Trace Logs Child Under Root Node");
  40. LPCTSTR g_cszAlertsChild = _T("Alerts Child Under Root Node");
  41. class CSmLogCfgApp : public CWinApp
  42. {
  43. public:
  44. virtual BOOL InitInstance();
  45. virtual int ExitInstance();
  46. };
  47. CSmLogCfgApp theApp;
  48. BOOL CSmLogCfgApp::InitInstance()
  49. {
  50. g_hinst = m_hInstance; // Store global instance handle
  51. _Module.Init(ObjectMap, m_hInstance);
  52. SHFusionInitializeFromModuleID (m_hInstance, 2);
  53. InitializeCriticalSection ( &g_critsectInstallDefaultQueries );
  54. return CWinApp::InitInstance();
  55. }
  56. int CSmLogCfgApp::ExitInstance()
  57. {
  58. DeleteCriticalSection ( &g_critsectInstallDefaultQueries );
  59. SHFusionUninitialize();
  60. _Module.Term();
  61. return CWinApp::ExitInstance();
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Used to determine whether the DLL can be unloaded by OLE
  65. STDAPI DllCanUnloadNow(void)
  66. {
  67. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  68. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // Returns a class factory to create an object of the requested type
  72. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  73. {
  74. // test for snap-in or extension snap-in guid and differentiate the
  75. // returned object here before returning (not implemented yet...)
  76. return _Module.GetClassObject(rclsid, riid, ppv);
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // DllRegisterServer - Adds entries to the system registry
  80. //
  81. STDAPI DllRegisterServer(void)
  82. {
  83. HKEY hMmcSnapinsKey = NULL;
  84. HKEY hMmcNodeTypesKey = NULL;
  85. HKEY hSmLogMgrParentKey = NULL;
  86. HKEY hStandAloneKey = NULL;
  87. HKEY hNodeTypesKey = NULL;
  88. HKEY hTempNodeKey = NULL;
  89. HKEY hNameSpaceKey = NULL;
  90. LONG nErr = 0;
  91. TCHAR pBuffer[_MAX_PATH+1]; // NOTE: Use for Provider, Version and module name strings
  92. size_t nLen;
  93. CString strName;
  94. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  95. //DebugBreak(); // Uncomment this to step through registration
  96. // Open the MMC Parent keys
  97. nErr = RegOpenKey( HKEY_LOCAL_MACHINE,
  98. g_cszBasePath,
  99. &hMmcSnapinsKey
  100. );
  101. if( ERROR_SUCCESS != nErr )
  102. DisplayError( GetLastError(), L"Open MMC Snapins Key Failed" );
  103. // Create the ID for our ICompnentData Interface
  104. // The ID was generated for us, because we used a Wizard to create the app.
  105. // Take the ID for CComponentData in the IDL file.
  106. //
  107. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  108. // Make sure you change this if you use this code as a starting point!
  109. // Change other IDs as well below!
  110. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  111. if (hMmcSnapinsKey) {
  112. nErr = RegCreateKey(
  113. hMmcSnapinsKey,
  114. GUIDSTR_ComponentData,
  115. &hSmLogMgrParentKey
  116. );
  117. if( ERROR_SUCCESS != nErr )
  118. DisplayError( GetLastError(), L"CComponentData Key Failed" );
  119. if (hSmLogMgrParentKey) {
  120. STANDARD_TRY
  121. strName.LoadString ( IDS_MMC_DEFAULT_NAME );
  122. MFC_CATCH_MINIMUM
  123. if ( strName.IsEmpty() ) {
  124. DisplayError ( ERROR_OUTOFMEMORY,
  125. _T("Unable to load snap-in name string.") );
  126. }
  127. // This is the name we see when we add the Snap-In to the console
  128. nErr = RegSetValueEx( hSmLogMgrParentKey,
  129. g_cszNameString,
  130. 0,
  131. REG_SZ,
  132. (LPBYTE)strName.GetBufferSetLength( strName.GetLength() ),
  133. strName.GetLength() * (DWORD)sizeof(TCHAR)
  134. );
  135. if( ERROR_SUCCESS != nErr )
  136. DisplayError( GetLastError(), L"Set NameString Failed" );
  137. // This is the indirect name we see when we add the Snap-In to the console.
  138. // Added for MUI support. Use the same name string as for NameString.
  139. STANDARD_TRY
  140. ::GetModuleFileName(AfxGetInstanceHandle(), pBuffer, _MAX_PATH);
  141. strName.Format (_T("@%s,-%d"), pBuffer, IDS_MMC_DEFAULT_NAME );
  142. MFC_CATCH_MINIMUM
  143. if ( strName.IsEmpty() ) {
  144. DisplayError ( ERROR_OUTOFMEMORY,
  145. _T("Unable to load snap-in indirect name string.") );
  146. }
  147. nErr = RegSetValueEx( hSmLogMgrParentKey,
  148. g_cszNameStringIndirect,
  149. 0,
  150. REG_SZ,
  151. (LPBYTE)strName.GetBufferSetLength( strName.GetLength() ),
  152. strName.GetLength() * (DWORD)sizeof(TCHAR)
  153. );
  154. if( ERROR_SUCCESS != nErr )
  155. DisplayError( GetLastError(), L"Set NameStringIndirect Failed" );
  156. // This is the primary node, or class which implements CComponentData
  157. nErr = RegSetValueEx( hSmLogMgrParentKey,
  158. g_cszNodeType,
  159. 0,
  160. REG_SZ,
  161. (LPBYTE)GUIDSTR_RootNode,
  162. ((lstrlen(GUIDSTR_RootNode)+1) * (DWORD)sizeof(TCHAR))
  163. );
  164. if( ERROR_SUCCESS != nErr )
  165. DisplayError( GetLastError(), L"Set NodeType Failed" );
  166. // This is the About box information
  167. nErr = RegSetValueEx( hSmLogMgrParentKey,
  168. g_cszAbout,
  169. 0,
  170. REG_SZ,
  171. (LPBYTE)GUIDSTR_PerformanceAbout,
  172. ((lstrlen(GUIDSTR_PerformanceAbout)+1) * (DWORD)sizeof(TCHAR))
  173. );
  174. if( ERROR_SUCCESS != nErr )
  175. DisplayError( GetLastError(), L"Set About Failed" );
  176. nLen = strlen(VER_COMPANYNAME_STR);
  177. #ifdef UNICODE
  178. nLen = mbstowcs(pBuffer, VER_COMPANYNAME_STR, nLen);
  179. pBuffer[nLen] = UNICODE_NULL;
  180. #else
  181. strcpy(pBuffer, VER_COMPANYNAME_STR);
  182. pBuffer[nLen] = ANSI_NULL;
  183. #endif
  184. nErr = RegSetValueEx( hSmLogMgrParentKey,
  185. g_cszProvider,
  186. 0,
  187. REG_SZ,
  188. (LPBYTE)pBuffer,
  189. (DWORD)((nLen+1) * sizeof(TCHAR))
  190. );
  191. if( ERROR_SUCCESS != nErr )
  192. DisplayError( GetLastError(), L"Set Provider Failed" );
  193. nLen = strlen(VER_PRODUCTVERSION_STR);
  194. #ifdef UNICODE
  195. nLen = mbstowcs(pBuffer, VER_PRODUCTVERSION_STR, nLen);
  196. pBuffer[nLen] = UNICODE_NULL;
  197. #else
  198. strcpy(pBuffer, VER_PRODUCTVERSION_STR);
  199. pBuffer[nLen] = ANSI_NULL;
  200. #endif
  201. nErr = RegSetValueEx( hSmLogMgrParentKey,
  202. g_cszVersion,
  203. 0,
  204. REG_SZ,
  205. (LPBYTE)pBuffer,
  206. (DWORD)((nLen+1) * sizeof(TCHAR))
  207. );
  208. if( ERROR_SUCCESS != nErr )
  209. DisplayError( GetLastError(), L"Set Version Failed" );
  210. // We are a stand alone snapin, so set the key for this
  211. nErr = RegCreateKey(
  212. hSmLogMgrParentKey,
  213. g_cszStandAlone,
  214. &hStandAloneKey);
  215. if( ERROR_SUCCESS != nErr )
  216. DisplayError( GetLastError(), L"Create StandAlone Key Failed" );
  217. if (hStandAloneKey) {
  218. // StandAlone has no children, so close it
  219. nErr = RegCloseKey( hStandAloneKey );
  220. if( ERROR_SUCCESS != nErr )
  221. DisplayError( GetLastError(), L"Close StandAlone Failed" );
  222. }
  223. // Set the node types that appear in our snapin
  224. nErr = RegCreateKey (
  225. hSmLogMgrParentKey,
  226. g_cszNodeTypes,
  227. &hNodeTypesKey );
  228. if( ERROR_SUCCESS != nErr )
  229. DisplayError( GetLastError(), L"Create NodeTypes Key Failed" );
  230. if (hNodeTypesKey) {
  231. // Here is our root node. Used uuidgen to get it
  232. nErr = RegCreateKey( hNodeTypesKey,
  233. GUIDSTR_RootNode,
  234. &hTempNodeKey
  235. );
  236. if( ERROR_SUCCESS != nErr )
  237. DisplayError( GetLastError(), L"Create RootNode Key Failed" );
  238. if (hTempNodeKey) {
  239. nErr = RegSetValueEx( hTempNodeKey,
  240. NULL,
  241. 0,
  242. REG_SZ,
  243. (LPBYTE)g_cszRootNode,
  244. (DWORD)sizeof(g_cszRootNode)
  245. );
  246. if( ERROR_SUCCESS != nErr )
  247. DisplayError( GetLastError(), L"Set Root Node String Failed" );
  248. nErr = RegCloseKey( hTempNodeKey ); // Close it for handle reuse
  249. if( ERROR_SUCCESS != nErr )
  250. DisplayError( GetLastError(), L"Close RootNode Failed" );
  251. }
  252. // Here are our child nodes under the root node. Used uuidgen
  253. // to get them for Counter Logs
  254. hTempNodeKey = NULL;
  255. nErr = RegCreateKey( hNodeTypesKey,
  256. GUIDSTR_CounterMainNode,
  257. &hTempNodeKey
  258. );
  259. if( ERROR_SUCCESS != nErr )
  260. DisplayError( GetLastError(),
  261. L"Create Child Performance Data Logs Node Key Failed" );
  262. if (hTempNodeKey) {
  263. nErr = RegSetValueEx( hTempNodeKey,
  264. NULL,
  265. 0,
  266. REG_SZ,
  267. (LPBYTE)g_cszCounterLogsChild,
  268. (DWORD)sizeof(g_cszCounterLogsChild)
  269. );
  270. if( ERROR_SUCCESS != nErr )
  271. DisplayError( GetLastError(),
  272. L"Set Performance Data Logs Child Node String Failed" );
  273. nErr = RegCloseKey( hTempNodeKey ); // Close it for handle reuse
  274. if( ERROR_SUCCESS != nErr )
  275. DisplayError( GetLastError(),
  276. L"Close Performance Data Logs Child Node Key Failed" );
  277. }
  278. // System Trace Logs
  279. hTempNodeKey = NULL;
  280. nErr = RegCreateKey( hNodeTypesKey,
  281. GUIDSTR_TraceMainNode,
  282. &hTempNodeKey
  283. );
  284. if( ERROR_SUCCESS != nErr )
  285. DisplayError( GetLastError(),
  286. L"Create Child System Trace Logs Node Key Failed" );
  287. if (hTempNodeKey) {
  288. nErr = RegSetValueEx( hTempNodeKey,
  289. NULL,
  290. 0,
  291. REG_SZ,
  292. (LPBYTE)g_cszTraceLogsChild,
  293. (DWORD)sizeof(g_cszTraceLogsChild)
  294. );
  295. if( ERROR_SUCCESS != nErr )
  296. DisplayError( GetLastError(),
  297. L"Set System Trace Logs Child Node String Failed" );
  298. nErr = RegCloseKey( hTempNodeKey ); // Close it for handle reuse
  299. if( ERROR_SUCCESS != nErr )
  300. DisplayError( GetLastError(),
  301. L"Close System Trace Logs Child Node Key Failed" );
  302. }
  303. // Alerts
  304. hTempNodeKey = NULL;
  305. nErr = RegCreateKey(hNodeTypesKey,
  306. GUIDSTR_AlertMainNode,
  307. &hTempNodeKey
  308. );
  309. if( ERROR_SUCCESS != nErr )
  310. DisplayError( GetLastError(),
  311. L"Create Child Alerts Node Key Failed" );
  312. if (hTempNodeKey) {
  313. nErr = RegSetValueEx( hTempNodeKey,
  314. NULL,
  315. 0,
  316. REG_SZ,
  317. (LPBYTE)g_cszAlertsChild,
  318. (DWORD)sizeof(g_cszAlertsChild)
  319. );
  320. if( ERROR_SUCCESS != nErr )
  321. DisplayError( GetLastError(),
  322. L"Set Alerts Child Node String Failed" );
  323. nErr = RegCloseKey( hTempNodeKey );
  324. if( ERROR_SUCCESS != nErr )
  325. DisplayError( GetLastError(),
  326. L"Close Alerts Child Node Key Failed" );
  327. }
  328. nErr = RegCloseKey( hNodeTypesKey );
  329. if( ERROR_SUCCESS != nErr )
  330. DisplayError( GetLastError(), L"Close Node Types Key Failed" );
  331. }
  332. // close the standalone snapin GUID key
  333. nErr = RegCloseKey( hSmLogMgrParentKey );
  334. if( ERROR_SUCCESS != nErr )
  335. DisplayError( GetLastError(), L"Close SmLogManager GUID Key Failed" );
  336. }
  337. // register the extension snap-in with the MMC
  338. hSmLogMgrParentKey = NULL;
  339. nErr = RegCreateKey( hMmcSnapinsKey,
  340. GUIDSTR_SnapInExt,
  341. &hSmLogMgrParentKey
  342. );
  343. if( ERROR_SUCCESS != nErr )
  344. DisplayError( GetLastError(), L"Snapin Extension Key creation Failed" );
  345. STANDARD_TRY
  346. strName.LoadString ( IDS_MMC_DEFAULT_EXT_NAME );
  347. MFC_CATCH_MINIMUM
  348. if ( strName.IsEmpty() ) {
  349. DisplayError ( ERROR_OUTOFMEMORY,
  350. _T("Unable to load snap-in extension name string.") );
  351. }
  352. if (hSmLogMgrParentKey) {
  353. // This is the name we see when we add the snap-in extension
  354. nErr = RegSetValueEx( hSmLogMgrParentKey,
  355. g_cszNameString,
  356. 0,
  357. REG_SZ,
  358. (LPBYTE)strName.GetBufferSetLength( strName.GetLength() ),
  359. strName.GetLength() * (DWORD)sizeof(TCHAR)
  360. );
  361. strName.ReleaseBuffer();
  362. if( ERROR_SUCCESS != nErr )
  363. DisplayError( GetLastError(), L"Set Extension NameString Failed" );
  364. // This is the name we see when we add the snap-in extension. MUI support.
  365. // Use the same name string as for NameString;
  366. STANDARD_TRY
  367. ::GetModuleFileName(AfxGetInstanceHandle(), pBuffer, _MAX_PATH);
  368. strName.Format (_T("@%s,-%d"), pBuffer, IDS_MMC_DEFAULT_EXT_NAME );
  369. MFC_CATCH_MINIMUM
  370. if ( strName.IsEmpty() ) {
  371. DisplayError ( ERROR_OUTOFMEMORY,
  372. _T("Unable to load extension indirect name string.") );
  373. }
  374. nErr = RegSetValueEx( hSmLogMgrParentKey,
  375. g_cszNameStringIndirect,
  376. 0,
  377. REG_SZ,
  378. (LPBYTE)strName.GetBufferSetLength( strName.GetLength() ),
  379. strName.GetLength() * (DWORD)sizeof(TCHAR)
  380. );
  381. strName.ReleaseBuffer();
  382. if( ERROR_SUCCESS != nErr )
  383. DisplayError( GetLastError(), L"Set Extension NameStringIndirect Failed" );
  384. // This is the Extension About box information
  385. nErr = RegSetValueEx(
  386. hSmLogMgrParentKey,
  387. g_cszAbout,
  388. 0,
  389. REG_SZ,
  390. (LPBYTE)GUIDSTR_PerformanceAbout,
  391. ((lstrlen(GUIDSTR_PerformanceAbout)+1) * (DWORD)sizeof(TCHAR))
  392. );
  393. if( ERROR_SUCCESS != nErr )
  394. DisplayError( GetLastError(), L"Set Extension About Failed" );
  395. nLen = strlen(VER_COMPANYNAME_STR);
  396. #ifdef UNICODE
  397. nLen = mbstowcs(pBuffer, VER_COMPANYNAME_STR, nLen);
  398. pBuffer[nLen] = UNICODE_NULL;
  399. #else
  400. strcpy(pBuffer, VER_COMPANYNAME_STR);
  401. pBuffer[nLen] = ANSI_NULL;
  402. #endif
  403. nErr = RegSetValueEx( hSmLogMgrParentKey,
  404. g_cszProvider,
  405. 0,
  406. REG_SZ,
  407. (LPBYTE)pBuffer,
  408. (DWORD)((nLen+1) * sizeof(TCHAR))
  409. );
  410. if( ERROR_SUCCESS != nErr )
  411. DisplayError( GetLastError(), L"Set Provider Failed" );
  412. nLen = strlen(VER_PRODUCTVERSION_STR);
  413. #ifdef UNICODE
  414. nLen = mbstowcs(pBuffer, VER_PRODUCTVERSION_STR, nLen);
  415. pBuffer[nLen] = UNICODE_NULL;
  416. #else
  417. strcpy(pBuffer, VER_PRODUCTVERSION_STR);
  418. pBuffer[nLen] = ANSI_NULL;
  419. #endif
  420. nErr = RegSetValueEx( hSmLogMgrParentKey,
  421. g_cszVersion,
  422. 0,
  423. REG_SZ,
  424. (LPBYTE)pBuffer,
  425. (DWORD)((nLen+1) * sizeof(TCHAR))
  426. );
  427. if( ERROR_SUCCESS != nErr )
  428. DisplayError( GetLastError(), L"Set Version Failed" );
  429. // close the main keys
  430. nErr = RegCloseKey( hSmLogMgrParentKey );
  431. if( ERROR_SUCCESS != nErr )
  432. DisplayError( GetLastError(), L"Close Snapin Extension Key Failed");
  433. }
  434. // register this as a "My Computer"-"System Tools" snapin extension
  435. nErr = RegOpenKey( HKEY_LOCAL_MACHINE,
  436. g_cszBaseNodeTypes,
  437. &hMmcNodeTypesKey
  438. );
  439. if( ERROR_SUCCESS != nErr )
  440. DisplayError( GetLastError(), L"Open MMC NodeTypes Key Failed" );
  441. // create/open the GUID of the System Tools Node of the My Computer snap-in
  442. if (hMmcNodeTypesKey) {
  443. nErr = RegCreateKey ( hMmcNodeTypesKey,
  444. lstruuidNodetypeSystemTools,
  445. &hNodeTypesKey
  446. );
  447. if( ERROR_SUCCESS != nErr )
  448. DisplayError( GetLastError(),
  449. L"Create/open System Tools GUID Key Failed" );
  450. if (hNodeTypesKey) {
  451. hTempNodeKey = NULL;
  452. nErr = RegCreateKey ( hNodeTypesKey,
  453. g_cszExtensions,
  454. &hTempNodeKey
  455. );
  456. if( ERROR_SUCCESS != nErr )
  457. DisplayError(
  458. GetLastError(),
  459. L"Create/open System Tools Extensions Key Failed" );
  460. if (hTempNodeKey) {
  461. nErr = RegCreateKey (
  462. hTempNodeKey,
  463. g_cszNameSpace,
  464. &hNameSpaceKey
  465. );
  466. if( ERROR_SUCCESS != nErr )
  467. DisplayError( GetLastError(),
  468. L"Create/open System Tools NameSpace Key Failed" );
  469. if (hNameSpaceKey) {
  470. nErr = RegSetValueEx( hNameSpaceKey,
  471. GUIDSTR_SnapInExt,
  472. 0,
  473. REG_SZ,
  474. (LPBYTE)strName.GetBufferSetLength( strName.GetLength() ),
  475. strName.GetLength() * (DWORD)sizeof(TCHAR)
  476. );
  477. strName.ReleaseBuffer();
  478. if( ERROR_SUCCESS != nErr ) {
  479. DisplayError( GetLastError(),
  480. L"Set Extension NameString Failed" );
  481. DisplayError( GetLastError(),
  482. L"Set Snapin Extension NameString Failed" );
  483. }
  484. nErr = RegCloseKey( hNameSpaceKey );
  485. if( ERROR_SUCCESS != nErr )
  486. DisplayError( GetLastError(),
  487. L"Close NameSpace Key Failed" );
  488. }
  489. nErr = RegCloseKey( hTempNodeKey );
  490. if( ERROR_SUCCESS != nErr )
  491. DisplayError( GetLastError(), L"Close Extension Key Failed" );
  492. }
  493. nErr = RegCloseKey( hNodeTypesKey );
  494. if( ERROR_SUCCESS != nErr )
  495. DisplayError( GetLastError(),
  496. L"Close My Computer System GUID Key Failed" );
  497. }
  498. nErr = RegCloseKey( hMmcNodeTypesKey );
  499. if( ERROR_SUCCESS != nErr )
  500. DisplayError( GetLastError(), L"Close MMC NodeTypes Key Failed" );
  501. }
  502. nErr = RegCloseKey( hMmcSnapinsKey );
  503. if( ERROR_SUCCESS != nErr )
  504. DisplayError( GetLastError(), L"Close MMC Snapins Key Failed" );
  505. }
  506. // Register extension Snap in
  507. nErr = _Module.UpdateRegistryFromResource(IDR_EXTENSION, TRUE);
  508. // Registers object, typelib and all interfaces in typelib
  509. return _Module.RegisterServer(TRUE);
  510. }
  511. /////////////////////////////////////////////////////////////////////////////
  512. // DllUnregisterServer - Removes entries from the system registry
  513. STDAPI DllUnregisterServer(void)
  514. {
  515. HKEY hMmcSnapinsKey = NULL; // MMC parent key
  516. HKEY hSmLogMgrParentKey = NULL; // Our Snap-In key - has children
  517. HKEY hNodeTypesKey = NULL; // Our NodeType key - has children
  518. HKEY hSysToolsNode = NULL;
  519. HKEY hExtension = NULL;
  520. HKEY hNameSpace = NULL;
  521. LONG nErr = 0;
  522. // DebugBreak(); // Uncomment this to step through UnRegister
  523. // Open the MMC parent key
  524. nErr = RegOpenKey( HKEY_LOCAL_MACHINE,
  525. g_cszBasePath,
  526. &hMmcSnapinsKey
  527. );
  528. if( ERROR_SUCCESS != nErr )
  529. DisplayError( GetLastError(), L"Open MMC Parent Key Failed" );
  530. // Open our Parent key
  531. nErr = RegOpenKey( hMmcSnapinsKey,
  532. GUIDSTR_ComponentData,
  533. &hSmLogMgrParentKey
  534. );
  535. if( ERROR_SUCCESS != nErr )
  536. DisplayError( GetLastError(), L"Open Disk Parent Key Failed" );
  537. // Now open the NodeTypes key
  538. nErr = RegOpenKey( hSmLogMgrParentKey, // Handle of parent key
  539. g_cszNodeTypes, // Name of key to open
  540. &hNodeTypesKey // Handle to newly opened key
  541. );
  542. if( ERROR_SUCCESS != nErr )
  543. DisplayError( GetLastError(), L"Open NodeTypes Key Failed" );
  544. if (hNodeTypesKey) {
  545. // Delete the root node key
  546. nErr = RegDeleteKey( hNodeTypesKey, GUIDSTR_RootNode );
  547. if( ERROR_SUCCESS != nErr )
  548. DisplayError( GetLastError(), L"Delete Root Node Key Failed" );
  549. // Delete the child node key
  550. // *** From Beta 2
  551. nErr = RegDeleteKey( hNodeTypesKey, GUIDSTR_MainNode );
  552. // Delete the child node keys
  553. // Counter logs
  554. nErr = RegDeleteKey( hNodeTypesKey, GUIDSTR_CounterMainNode );
  555. if( ERROR_SUCCESS != nErr )
  556. DisplayError( GetLastError(), L"Delete Performance Logs and Alerts Child Node Key Failed" );
  557. // System Trace Logs
  558. nErr = RegDeleteKey( hNodeTypesKey, GUIDSTR_TraceMainNode );
  559. if( ERROR_SUCCESS != nErr )
  560. DisplayError( GetLastError(), L"Delete System Trace Logs Child Node Key Failed" );
  561. // Alerts
  562. nErr = RegDeleteKey( hNodeTypesKey, GUIDSTR_AlertMainNode );
  563. if( ERROR_SUCCESS != nErr )
  564. DisplayError( GetLastError(), L"Delete Alerts Child Node Key Failed" );
  565. // Close the node type key so we can delete it
  566. nErr = RegCloseKey( hNodeTypesKey );
  567. if( ERROR_SUCCESS != nErr )
  568. DisplayError( GetLastError(), L"Close NodeTypes Key failed" );
  569. }
  570. // Delete the NodeTypes key
  571. if (hSmLogMgrParentKey) {
  572. nErr = RegDeleteKey( hSmLogMgrParentKey, L"NodeTypes" );
  573. if( ERROR_SUCCESS != nErr )
  574. DisplayError( GetLastError(), L"Delete NodeTypes Key failed" );
  575. // StandAlone key has no children so we can delete it now
  576. nErr = RegDeleteKey(
  577. hSmLogMgrParentKey,
  578. g_cszStandAlone );
  579. if( ERROR_SUCCESS != nErr )
  580. DisplayError( GetLastError(), L"Delete StandAlone Key Failed" );
  581. // Close our Parent Key
  582. nErr = RegCloseKey( hSmLogMgrParentKey );
  583. if( ERROR_SUCCESS != nErr )
  584. DisplayError( GetLastError(), L"Close Disk Parent Key Failed" );
  585. }
  586. if (hMmcSnapinsKey) {
  587. // Now we can delete our Snap-In key since the children are gone
  588. nErr = RegDeleteKey( hMmcSnapinsKey, GUIDSTR_ComponentData );
  589. if( ERROR_SUCCESS != nErr )
  590. DisplayError( GetLastError(), L"Delete Performance Logs and Alerts GUID Key Failed" );
  591. // Now we can delete our Snap-In Extension key
  592. nErr = RegDeleteKey( hMmcSnapinsKey, GUIDSTR_SnapInExt);
  593. if( ERROR_SUCCESS != nErr )
  594. DisplayError( GetLastError(), L"Delete Performance Logs and Alerts GUID Key Failed" );
  595. nErr = RegCloseKey( hMmcSnapinsKey );
  596. if( ERROR_SUCCESS != nErr )
  597. DisplayError( GetLastError(), L"Close MMC Parent Key Failed" );
  598. }
  599. // delete snap-in extension entry
  600. hNodeTypesKey = NULL;
  601. // Open the MMC parent key
  602. nErr = RegOpenKey( HKEY_LOCAL_MACHINE,
  603. g_cszBaseNodeTypes,
  604. &hNodeTypesKey
  605. );
  606. if( ERROR_SUCCESS != nErr )
  607. DisplayError( GetLastError(), L"Open of MMC NodeTypes Key Failed" );
  608. if (hNodeTypesKey) {
  609. hSysToolsNode = NULL;
  610. nErr = RegOpenKey (hNodeTypesKey,
  611. lstruuidNodetypeSystemTools,
  612. &hSysToolsNode
  613. );
  614. if( ERROR_SUCCESS != nErr )
  615. DisplayError( GetLastError(),
  616. L"Open of My Computer System Tools Key Failed" );
  617. if (hSysToolsNode) {
  618. hExtension = NULL;
  619. nErr = RegOpenKey (hSysToolsNode,
  620. g_cszExtensions,
  621. &hExtension
  622. );
  623. if( ERROR_SUCCESS != nErr )
  624. DisplayError( GetLastError(), L"Open of Extensions Key Failed" );
  625. if (hExtension) {
  626. hNameSpace = NULL;
  627. nErr = RegOpenKey (hExtension,
  628. g_cszNameSpace,
  629. &hNameSpace
  630. );
  631. if( ERROR_SUCCESS != nErr )
  632. DisplayError( GetLastError(),
  633. L"Open of Name Space Key Failed" );
  634. if (hNameSpace) {
  635. nErr = RegDeleteValue (hNameSpace, GUIDSTR_SnapInExt);
  636. if( ERROR_SUCCESS != nErr )
  637. DisplayError( GetLastError(),
  638. L"Unable to remove the Snap-in Ext. GUID" );
  639. // close keys
  640. nErr = RegCloseKey( hNameSpace );
  641. if( ERROR_SUCCESS != nErr )
  642. DisplayError( GetLastError(),
  643. L"Close NameSpace Key Failed" );
  644. }
  645. nErr = RegCloseKey( hExtension);
  646. if( ERROR_SUCCESS != nErr )
  647. DisplayError(GetLastError(), L"Close Extension Key Failed");
  648. }
  649. nErr = RegCloseKey( hSysToolsNode );
  650. if( ERROR_SUCCESS != nErr )
  651. DisplayError( GetLastError(),
  652. L"Close My Computer System Tools Key Failed" );
  653. }
  654. nErr = RegCloseKey( hNodeTypesKey);
  655. if( ERROR_SUCCESS != nErr )
  656. DisplayError( GetLastError(), L"Close MMC Node Types Key Failed" );
  657. }
  658. _Module.UnregisterServer();
  659. return S_OK;
  660. }