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.

807 lines
23 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. // You will need the NT SUR Beta 2 SDK or VC 4.2 in order to build this
  9. // project. This is because you will need MIDL 3.00.15 or higher and new
  10. // headers and libs. If you have VC 4.2 installed, then everything should
  11. // already be configured correctly.
  12. // Note: Proxy/Stub Information
  13. // To build a separate proxy/stub DLL,
  14. // run nmake -f Snapinps.mak in the project directory.
  15. #include "stdafx.h"
  16. #include "resource.h"
  17. #include "initguid.h"
  18. #include "cookie.h"
  19. #include <scesvc.h>
  20. #include "Snapmgr.h"
  21. #include "wrapper.h"
  22. #include "sceattch.h"
  23. #include "about.h"
  24. CComModule _Module;
  25. BEGIN_OBJECT_MAP(ObjectMap)
  26. OBJECT_ENTRY(CLSID_Snapin, CComponentDataExtensionImpl)
  27. OBJECT_ENTRY(CLSID_SCESnapin, CComponentDataSCEImpl)
  28. OBJECT_ENTRY(CLSID_SAVSnapin, CComponentDataSAVImpl)
  29. OBJECT_ENTRY(CLSID_LSSnapin, CComponentDataLSImpl)
  30. OBJECT_ENTRY(CLSID_RSOPSnapin, CComponentDataRSOPImpl)
  31. OBJECT_ENTRY(CLSID_SCEAbout, CSCEAbout)
  32. OBJECT_ENTRY(CLSID_SCMAbout, CSCMAbout)
  33. OBJECT_ENTRY(CLSID_SSAbout, CSSAbout)
  34. OBJECT_ENTRY(CLSID_LSAbout, CLSAbout)
  35. OBJECT_ENTRY(CLSID_RSOPAbout, CRSOPAbout)
  36. END_OBJECT_MAP()
  37. #ifdef _DEBUG
  38. #define new DEBUG_NEW
  39. #undef THIS_FILE
  40. static char THIS_FILE[] = __FILE__;
  41. #endif
  42. HRESULT RegisterSnapin(const GUID* pSnapinCLSID,
  43. const GUID* pStaticNodeGUID,
  44. const GUID* pSnapinAboutGUID,
  45. const int nNameResource,
  46. // LPCTSTR lpszNameStringNoValueName,
  47. LPCTSTR lpszVersion,
  48. BOOL bExtension);
  49. HRESULT RegisterSnapin(LPCTSTR lpszSnapinClassID,
  50. LPCTSTR lpszStaticNodeGuid,
  51. LPCTSTR lpszSnapingAboutGuid,
  52. const int nNameResource,
  53. LPCTSTR lpszVersion,
  54. BOOL bExtension);
  55. HRESULT UnregisterSnapin(const GUID* pSnapinCLSID);
  56. HRESULT UnregisterSnapin(LPCTSTR lpszSnapinClassID);
  57. HRESULT RegisterNodeType(const GUID* pGuid, LPCTSTR lpszNodeDescription);
  58. HRESULT RegisterNodeType(LPCTSTR lpszNodeGuid, LPCTSTR lpszNodeDescription);
  59. HRESULT RegisterNodeType(LPCTSTR lpszNodeType, const GUID* pGuid, LPCTSTR lpszNodeDescription);
  60. HRESULT RegisterNodeType(LPCTSTR lpszNodeType, LPCTSTR lpszNodeGuid, LPCTSTR lpszNodeDescription);
  61. HRESULT UnregisterNodeType(const GUID* pGuid);
  62. HRESULT UnregisterNodeType(LPCTSTR lpszNodeGuid);
  63. HRESULT UnregisterNodeType(LPCTSTR lpszNodeType, const GUID* pGuid);
  64. HRESULT UnregisterNodeType(LPCTSTR lpszNodeType, LPCTSTR lpszNodeGuid);
  65. HRESULT RegisterDefaultTemplate(LPCTSTR lpszTemplateDir);
  66. HRESULT RegisterEnvVarsToExpand();
  67. class CSnapinApp : public CWinApp
  68. {
  69. public:
  70. virtual BOOL InitInstance();
  71. virtual int ExitInstance();
  72. };
  73. CSnapinApp theApp;
  74. const int iStrGuidLen = 128;
  75. BOOL CSnapinApp::InitInstance()
  76. {
  77. _Module.Init(ObjectMap, m_hInstance);
  78. if (!CComponentDataImpl::LoadResources())
  79. return FALSE;
  80. InitializeCriticalSection(&csOpenDatabase);
  81. SHFusionInitializeFromModuleID (m_hInstance, 2);
  82. return CWinApp::InitInstance();
  83. }
  84. int CSnapinApp::ExitInstance()
  85. {
  86. SHFusionUninitialize();
  87. DeleteCriticalSection(&csOpenDatabase); //Raid #379167, 4/27/2001
  88. _Module.Term();
  89. DEBUG_VERIFY_INSTANCE_COUNT(CSnapin);
  90. DEBUG_VERIFY_INSTANCE_COUNT(CComponentDataImpl);
  91. return CWinApp::ExitInstance();
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // Used to determine whether the DLL can be unloaded by OLE
  95. STDAPI DllCanUnloadNow(void)
  96. {
  97. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  98. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Returns a class factory to create an object of the requested type
  102. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  103. {
  104. return _Module.GetClassObject(rclsid, riid, ppv);
  105. }
  106. STDAPI DllRegisterServer(void)
  107. {
  108. // registers object, but not typelib and all interfaces in typelib
  109. HRESULT hr = _Module.RegisterServer(FALSE);
  110. ASSERT(SUCCEEDED(hr));
  111. if (FAILED(hr))
  112. return hr;
  113. CString str;
  114. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  115. //
  116. // unregister some nodes then re-register
  117. // because some are changed here
  118. //
  119. hr = UnregisterSnapin(&CLSID_Snapin);
  120. // not an extension of computer management
  121. hr = UnregisterNodeType(TEXT(struuidNodetypeSystemTools), &CLSID_Snapin);
  122. //
  123. // register the snapin into the console snapin list as SCE
  124. hr = RegisterSnapin(&CLSID_SCESnapin, &cSCENodeType, &CLSID_SCEAbout,
  125. IDS_TEMPLATE_EDITOR_NAME, _T("1.0"), FALSE);
  126. ASSERT(SUCCEEDED(hr));
  127. if (FAILED(hr))
  128. return hr;
  129. //
  130. // register the snapin into the console snapin list as SAV
  131. hr = RegisterSnapin(&CLSID_SAVSnapin, &cSAVNodeType, &CLSID_SCMAbout,
  132. IDS_ANALYSIS_VIEWER_NAME, _T("1.0"), FALSE);
  133. ASSERT(SUCCEEDED(hr));
  134. if (FAILED(hr))
  135. return hr;
  136. hr = RegisterSnapin(&CLSID_Snapin, &cNodeType, &CLSID_SSAbout,
  137. IDS_EXTENSION_NAME, _T("1.0"), TRUE );
  138. ASSERT(SUCCEEDED(hr));
  139. if (FAILED(hr))
  140. return hr;
  141. hr = RegisterSnapin(&CLSID_RSOPSnapin, &cRSOPNodeType, &CLSID_RSOPAbout,
  142. IDS_EXTENSION_NAME, _T("1.0"), TRUE );
  143. ASSERT(SUCCEEDED(hr));
  144. if (FAILED(hr))
  145. return hr;
  146. #ifdef USE_SEPARATE_LOCALSEC
  147. hr = RegisterSnapin(&CLSID_LSSnapin, &cLSNodeType, &CLSID_LSAbout,
  148. IDS_LOCAL_SECURITY_NAME, _T("1.0"), FALSE );
  149. ASSERT(SUCCEEDED(hr));
  150. if (FAILED(hr))
  151. return hr;
  152. #endif
  153. // no need to register as extension of computer management snapin
  154. // str.LoadString(IDS_ANALYSIS_VIEWER_NAME);
  155. // hr = RegisterNodeType(TEXT(struuidNodetypeSystemTools), &CLSID_Snapin, (LPCTSTR)str);
  156. //
  157. // register GPE extension
  158. // register the snapin as an extension of GPT's Machine node
  159. //
  160. OLECHAR szGuid[iStrGuidLen];
  161. if (0 != ::StringFromGUID2(NODEID_Machine,szGuid,iStrGuidLen))
  162. {
  163. str.LoadString(IDS_EXTENSION_NAME);
  164. hr = RegisterNodeType(szGuid, &CLSID_Snapin, (LPCTSTR)str);
  165. if (FAILED(hr))
  166. return hr;
  167. }
  168. // register the snapin as an extension of GPT's User node
  169. if (0 != ::StringFromGUID2(NODEID_User,szGuid,iStrGuidLen))
  170. {
  171. hr = RegisterNodeType(szGuid, &CLSID_Snapin, (LPCTSTR)str);
  172. if (FAILED(hr))
  173. return hr;
  174. }
  175. if (0 != ::StringFromGUID2(NODEID_RSOPMachine,szGuid,iStrGuidLen))
  176. {
  177. str.LoadString(IDS_EXTENSION_NAME);
  178. hr = RegisterNodeType(szGuid, &CLSID_RSOPSnapin, (LPCTSTR)str);
  179. if (FAILED(hr))
  180. return hr;
  181. }
  182. // register the snapin as an extension of GPT's User node
  183. if (0 != ::StringFromGUID2(NODEID_RSOPUser,szGuid,iStrGuidLen))
  184. {
  185. hr = RegisterNodeType(szGuid, &CLSID_RSOPSnapin, (LPCTSTR)str);
  186. if (FAILED(hr))
  187. return hr;
  188. }
  189. //
  190. // register the default template path
  191. //
  192. CString str2;
  193. LPTSTR sz;
  194. sz = str.GetBuffer(MAX_PATH);
  195. if ( 0 == GetWindowsDirectory(sz,MAX_PATH) ) sz[0] = L'\0';
  196. str.ReleaseBuffer();
  197. str2.LoadString(IDS_DEFAULT_TEMPLATE_DIR);
  198. str += str2;
  199. sz=str.GetBuffer(str.GetLength());
  200. // Can't put '\' in the registry, so convert to '/'
  201. while(sz = wcschr(sz,L'\\')) {
  202. *sz = L'/';
  203. }
  204. str.ReleaseBuffer();
  205. str2.LoadString(IDS_TEMPLATE_LOCATION_KEY);
  206. str2 += L"\\";
  207. str2 += str;
  208. hr = RegisterDefaultTemplate(str2);
  209. if (FAILED(hr)) {
  210. return hr;
  211. }
  212. hr = RegisterEnvVarsToExpand();
  213. return hr;
  214. }
  215. /////////////////////////////////////////////////////////////////////////////
  216. // DllUnregisterServer - Removes entries from the system registry
  217. STDAPI DllUnregisterServer(void)
  218. {
  219. OLECHAR szGuid[iStrGuidLen];
  220. HRESULT hr = _Module.UnregisterServer();
  221. ASSERT(SUCCEEDED(hr));
  222. if (FAILED(hr))
  223. return hr;
  224. // unregister the snapin extension nodes
  225. // un register the snapin
  226. hr = UnregisterSnapin(&CLSID_SCESnapin);
  227. // un register the snapin
  228. hr = UnregisterSnapin(&CLSID_SAVSnapin);
  229. // un register the snapin
  230. hr = UnregisterSnapin(&CLSID_Snapin);
  231. // un register the snapin
  232. hr = UnregisterSnapin(&CLSID_LSSnapin);
  233. // un register the snapin
  234. hr = UnregisterSnapin(&CLSID_RSOPSnapin);
  235. // unregister the SCE snapin nodes
  236. hr = UnregisterNodeType(lstruuidNodetypeSceTemplateServices);
  237. // unregister the SAV snapin nodes
  238. hr = UnregisterNodeType(lstruuidNodetypeSceAnalysisServices);
  239. // unregister the snapin nodes
  240. hr = UnregisterNodeType(lstruuidNodetypeSceTemplate);
  241. // not an extension of computer management
  242. // hr = UnregisterNodeType(TEXT(struuidNodetypeSystemTools), &CLSID_Snapin);
  243. ::StringFromGUID2(NODEID_Machine,szGuid,iStrGuidLen);
  244. hr = UnregisterNodeType(szGuid, &CLSID_Snapin);
  245. ::StringFromGUID2(NODEID_User,szGuid,iStrGuidLen);
  246. hr = UnregisterNodeType(szGuid, &CLSID_Snapin);
  247. ::StringFromGUID2(NODEID_RSOPMachine,szGuid,iStrGuidLen);
  248. hr = UnregisterNodeType(szGuid, &CLSID_RSOPSnapin);
  249. ::StringFromGUID2(NODEID_RSOPUser,szGuid,iStrGuidLen);
  250. hr = UnregisterNodeType(szGuid, &CLSID_RSOPSnapin);
  251. /*
  252. /*
  253. // unregister the SCE snapin nodes
  254. hr = UnregisterNodeType(&cSCENodeType);
  255. ASSERT(SUCCEEDED(hr));
  256. // unregister the SAV snapin nodes
  257. hr = UnregisterNodeType(&cSAVNodeType);
  258. ASSERT(SUCCEEDED(hr));
  259. // unregister the snapin nodes
  260. hr = UnregisterNodeType(&cNodeType);
  261. ASSERT(SUCCEEDED(hr));
  262. */
  263. return S_OK;
  264. }
  265. HRESULT RegisterSnapin(const GUID* pSnapinCLSID, const GUID* pStaticNodeGUID,
  266. const GUID* pSnapinAboutGUID,
  267. const int nNameResource,
  268. // LPCTSTR lpszNameString,
  269. LPCTSTR lpszVersion, BOOL bExtension)
  270. {
  271. USES_CONVERSION;
  272. OLECHAR szSnapinClassID[iStrGuidLen], szStaticNodeGuid[iStrGuidLen], szSnapinAboutGuid[iStrGuidLen];
  273. if (0 != ::StringFromGUID2(*pSnapinCLSID, szSnapinClassID, iStrGuidLen) &&
  274. 0 != ::StringFromGUID2(*pStaticNodeGUID, szStaticNodeGuid, iStrGuidLen) &&
  275. 0 != ::StringFromGUID2(*pSnapinAboutGUID, szSnapinAboutGuid, iStrGuidLen) )
  276. {
  277. return RegisterSnapin(szSnapinClassID,
  278. szStaticNodeGuid,
  279. szSnapinAboutGuid,
  280. nNameResource,
  281. // lpszNameString,
  282. lpszVersion,
  283. bExtension);
  284. }
  285. else
  286. return E_OUTOFMEMORY;
  287. }
  288. ////////////////////////////////////////////////////////////////////////
  289. //
  290. // Registry SCE related reg keys under MMC snapins key
  291. //
  292. //
  293. ////////////////////////////////////////////////////////////////////////
  294. HRESULT
  295. RegisterSnapin(LPCTSTR lpszSnapinClassID,
  296. LPCTSTR lpszStaticNodeGuid,
  297. LPCTSTR lpszSnapinAboutGuid,
  298. const int nNameResource,
  299. LPCTSTR lpszVersion,
  300. BOOL bExtension)
  301. {
  302. //
  303. // open the MMC Snapins root key
  304. //
  305. CRegKey regkeySnapins;
  306. LONG lRes = regkeySnapins.Open(HKEY_LOCAL_MACHINE,
  307. SNAPINS_KEY);
  308. if (lRes != ERROR_SUCCESS) {
  309. return HRESULT_FROM_WIN32(lRes); // failed to open
  310. }
  311. //
  312. // create SCE subkey, if already exist, just open it
  313. //
  314. CRegKey regkeyThisSnapin;
  315. lRes = regkeyThisSnapin.Create(regkeySnapins,
  316. lpszSnapinClassID);
  317. if (lRes == ERROR_SUCCESS) {
  318. //
  319. // set values for SCE root key
  320. //
  321. //
  322. // 97068 MUI:MMC:Security:Security Configuration and Analysis Snap-in store its information in the registry
  323. // 99392 MUI:MMC:Security:Security Templates Snap-in store its information in the registry
  324. // 97167 MUI:GPE:GPE Extension: Group policy Secuirty snap-in ext name string is stored in the registry
  325. //
  326. // MMC now supports NameStringIndirect
  327. //
  328. TCHAR achModuleFileName[MAX_PATH+20];
  329. if (0 < ::GetModuleFileName(
  330. AfxGetInstanceHandle(),
  331. achModuleFileName,
  332. sizeof(achModuleFileName)/sizeof(TCHAR) ))
  333. {
  334. CString strNameIndirect;
  335. strNameIndirect.Format( _T("@%s,-%d"),
  336. achModuleFileName,
  337. nNameResource);
  338. lRes = regkeyThisSnapin.SetValue(strNameIndirect,
  339. TEXT("NameStringIndirect"));
  340. }
  341. lRes = regkeyThisSnapin.SetValue(lpszStaticNodeGuid,
  342. TEXT("NodeType"));
  343. lRes = regkeyThisSnapin.SetValue(lpszSnapinAboutGuid,
  344. TEXT("About"));
  345. lRes = regkeyThisSnapin.SetValue(_T("Microsoft"),
  346. _T("Provider"));
  347. lRes = regkeyThisSnapin.SetValue(lpszVersion,
  348. _T("Version"));
  349. //
  350. // create "NodeTypes" subkey
  351. //
  352. CRegKey regkeyNodeTypes;
  353. lRes = regkeyNodeTypes.Create(regkeyThisSnapin,
  354. TEXT("NodeTypes"));
  355. if (lRes == ERROR_SUCCESS) {
  356. //
  357. // create subkeys for all node types supported by SCE
  358. //
  359. // including: services under configuration,
  360. // services under analysis
  361. // GPT extensions
  362. //
  363. lRes = regkeyNodeTypes.SetKeyValue(lstruuidNodetypeSceTemplateServices,
  364. TEXT("SCE Service Template Extensions"));
  365. if (lRes == ERROR_SUCCESS) {
  366. lRes = regkeyNodeTypes.SetKeyValue(lstruuidNodetypeSceAnalysisServices,
  367. TEXT("SCE Service Inspection Extensions"));
  368. }
  369. if ( bExtension &&
  370. lRes == ERROR_SUCCESS ) {
  371. //
  372. // NOTE: standalone snapin do not support public key extensions
  373. //
  374. // node type for one template in SCE standalone mode,
  375. // or the root node of SCE under GPE
  376. //
  377. CString str;
  378. str.LoadString(IDS_EXTENSION_NAME);
  379. lRes = regkeyNodeTypes.SetKeyValue(lstruuidNodetypeSceTemplate,
  380. (LPCTSTR)str);
  381. if (lRes == ERROR_SUCCESS) {
  382. lRes = RegisterNodeType(lstruuidNodetypeSceTemplate,
  383. (LPCTSTR)str);
  384. }
  385. } else if (lRes == ERROR_SUCCESS) {
  386. //
  387. // create "Standalone" subkey
  388. //
  389. CRegKey regkeyStandalone;
  390. lRes = regkeyStandalone.Create(regkeyThisSnapin,
  391. TEXT("Standalone"));
  392. if ( lRes == ERROR_SUCCESS ) {
  393. regkeyStandalone.Close();
  394. }
  395. }
  396. //
  397. // register supported node types to MMC NodeTypes key
  398. // including all the above node types
  399. //
  400. if ( lRes == ERROR_SUCCESS ) {
  401. lRes = RegisterNodeType(lstruuidNodetypeSceTemplateServices,
  402. TEXT("SCE Service Template Extensions"));
  403. if (lRes == ERROR_SUCCESS) {
  404. lRes = RegisterNodeType(lstruuidNodetypeSceAnalysisServices,
  405. TEXT("SCE Service Analysis Extensions"));
  406. }
  407. }
  408. regkeyNodeTypes.Close();
  409. }
  410. regkeyThisSnapin.Close();
  411. }
  412. regkeySnapins.Close();
  413. return HRESULT_FROM_WIN32(lRes);
  414. }
  415. HRESULT UnregisterSnapin(const GUID* pSnapinCLSID)
  416. {
  417. USES_CONVERSION;
  418. OLECHAR szSnapinClassID[iStrGuidLen];
  419. if (0 != ::StringFromGUID2(*pSnapinCLSID,szSnapinClassID,iStrGuidLen))
  420. return UnregisterSnapin(szSnapinClassID);
  421. else
  422. return E_INVALIDARG;
  423. }
  424. HRESULT UnregisterSnapin(LPCTSTR lpszSnapinClassID)
  425. {
  426. //
  427. // open MMC Snapins key
  428. //
  429. CRegKey regkeySnapins;
  430. LONG lRes = regkeySnapins.Open(HKEY_LOCAL_MACHINE,
  431. SNAPINS_KEY);
  432. if (lRes != ERROR_SUCCESS)
  433. return HRESULT_FROM_WIN32(lRes); // failed to open
  434. //
  435. // delete SCE sub key (and all related subkeys under SCE)
  436. //
  437. lRes = regkeySnapins.RecurseDeleteKey(lpszSnapinClassID);
  438. regkeySnapins.Close();
  439. if ( lRes == ERROR_FILE_NOT_FOUND )
  440. return S_OK;
  441. return HRESULT_FROM_WIN32(lRes);
  442. }
  443. HRESULT RegisterNodeType(const GUID* pGuid, LPCTSTR lpszNodeDescription)
  444. {
  445. USES_CONVERSION;
  446. OLECHAR szGuid[iStrGuidLen];
  447. if (0 != ::StringFromGUID2(*pGuid,szGuid,iStrGuidLen))
  448. return RegisterNodeType(OLE2T(szGuid), lpszNodeDescription);
  449. else
  450. return E_INVALIDARG;
  451. }
  452. HRESULT RegisterNodeType(LPCTSTR lpszNodeGuid, LPCTSTR lpszNodeDescription)
  453. {
  454. CRegKey regkeyNodeTypes;
  455. LONG lRes = regkeyNodeTypes.Open(HKEY_LOCAL_MACHINE, NODE_TYPES_KEY);
  456. ASSERT(lRes == ERROR_SUCCESS);
  457. if (lRes != ERROR_SUCCESS)
  458. return HRESULT_FROM_WIN32(lRes); // failed to open
  459. CRegKey regkeyThisNodeType;
  460. lRes = regkeyThisNodeType.Create(regkeyNodeTypes, lpszNodeGuid);
  461. ASSERT(lRes == ERROR_SUCCESS);
  462. if (lRes == ERROR_SUCCESS) {
  463. lRes = regkeyThisNodeType.SetValue(lpszNodeDescription);
  464. regkeyThisNodeType.Close();
  465. }
  466. return HRESULT_FROM_WIN32(lRes);
  467. }
  468. HRESULT RegisterNodeType(LPCTSTR lpszNodeType, const GUID* pGuid, LPCTSTR lpszNodeDescription)
  469. {
  470. USES_CONVERSION;
  471. OLECHAR szGuid[iStrGuidLen];
  472. if (0 != ::StringFromGUID2(*pGuid,szGuid,iStrGuidLen))
  473. return RegisterNodeType(lpszNodeType, OLE2T(szGuid), lpszNodeDescription);
  474. else
  475. return E_INVALIDARG;
  476. }
  477. HRESULT RegisterNodeType(LPCTSTR lpszNodeType, LPCTSTR lpszNodeGuid, LPCTSTR lpszNodeDescription)
  478. {
  479. CRegKey regkeyNodeTypes;
  480. LONG lRes = regkeyNodeTypes.Open(HKEY_LOCAL_MACHINE, NODE_TYPES_KEY);
  481. if (lRes == ERROR_SUCCESS) {
  482. CRegKey regkeyThisNodeType;
  483. lRes = regkeyThisNodeType.Create(regkeyNodeTypes, lpszNodeType );
  484. if (lRes == ERROR_SUCCESS) {
  485. CRegKey regkeyExtensions;
  486. lRes = regkeyExtensions.Create(regkeyThisNodeType, g_szExtensions);
  487. if ( lRes == ERROR_SUCCESS ) {
  488. CRegKey regkeyNameSpace;
  489. lRes = regkeyNameSpace.Create(regkeyExtensions, g_szNameSpace);
  490. if ( lRes == ERROR_SUCCESS ) {
  491. lRes = regkeyNameSpace.SetValue( lpszNodeDescription, lpszNodeGuid );
  492. regkeyNameSpace.Close();
  493. }
  494. regkeyExtensions.Close();
  495. }
  496. regkeyThisNodeType.Close();
  497. }
  498. regkeyNodeTypes.Close();
  499. }
  500. ASSERT(lRes == ERROR_SUCCESS);
  501. return HRESULT_FROM_WIN32(lRes);
  502. }
  503. HRESULT UnregisterNodeType(const GUID* pGuid)
  504. {
  505. USES_CONVERSION;
  506. OLECHAR szGuid[iStrGuidLen];
  507. if (0 != ::StringFromGUID2(*pGuid,szGuid,iStrGuidLen))
  508. return UnregisterNodeType(OLE2T(szGuid));
  509. else
  510. return E_INVALIDARG;
  511. }
  512. HRESULT UnregisterNodeType(LPCTSTR lpszNodeGuid)
  513. {
  514. CRegKey regkeyNodeTypes;
  515. LONG lRes = regkeyNodeTypes.Open(HKEY_LOCAL_MACHINE, NODE_TYPES_KEY);
  516. if (lRes != ERROR_SUCCESS)
  517. return HRESULT_FROM_WIN32(lRes); // failed to open
  518. lRes = regkeyNodeTypes.RecurseDeleteKey(lpszNodeGuid);
  519. regkeyNodeTypes.Close();
  520. if ( lRes == ERROR_FILE_NOT_FOUND )
  521. return S_OK;
  522. return HRESULT_FROM_WIN32(lRes);
  523. }
  524. HRESULT RegisterDefaultTemplate(LPCTSTR lpszTemplateDir)
  525. {
  526. CRegKey regkeyTemplates;
  527. CString strKey;
  528. LONG lRes;
  529. strKey.LoadString(IDS_TEMPLATE_LOCATION_KEY);
  530. /*
  531. lRes = regkeyTemplates.Open(HKEY_LOCAL_MACHINE, strKey);
  532. ASSERT(lRes == ERROR_SUCCESS);
  533. if (lRes != ERROR_SUCCESS)
  534. return HRESULT_FROM_WIN32(lRes); // failed to open
  535. */
  536. lRes = regkeyTemplates.Create(HKEY_LOCAL_MACHINE,lpszTemplateDir);
  537. ASSERT(lRes == ERROR_SUCCESS);
  538. return HRESULT_FROM_WIN32(lRes);
  539. }
  540. HRESULT UnregisterNodeType(LPCTSTR lpszNodeType, const GUID* pGuid)
  541. {
  542. USES_CONVERSION;
  543. OLECHAR szGuid[iStrGuidLen];
  544. if (0 != ::StringFromGUID2(*pGuid,szGuid,iStrGuidLen))
  545. return UnregisterNodeType(lpszNodeType, OLE2T(szGuid));
  546. else
  547. return E_INVALIDARG;
  548. }
  549. HRESULT UnregisterNodeType(LPCTSTR lpszNodeType, LPCTSTR lpszNodeGuid)
  550. {
  551. CRegKey regkeyNodeTypes;
  552. LONG lRes = regkeyNodeTypes.Open(HKEY_LOCAL_MACHINE, NODE_TYPES_KEY );
  553. if (lRes == ERROR_SUCCESS) {
  554. CRegKey regkeyThisNodeType;
  555. lRes = regkeyThisNodeType.Open(regkeyNodeTypes, lpszNodeType );
  556. if (lRes == ERROR_SUCCESS) {
  557. CRegKey regkeyExtensions;
  558. lRes = regkeyExtensions.Open(regkeyThisNodeType, g_szExtensions);
  559. if ( lRes == ERROR_SUCCESS ) {
  560. CRegKey regkeyNameSpace;
  561. lRes = regkeyNameSpace.Open(regkeyExtensions, g_szNameSpace);
  562. if ( lRes == ERROR_SUCCESS ) {
  563. lRes = regkeyNameSpace.DeleteValue( lpszNodeGuid );
  564. regkeyNameSpace.Close();
  565. }
  566. regkeyExtensions.Close();
  567. }
  568. regkeyThisNodeType.Close();
  569. }
  570. regkeyNodeTypes.Close();
  571. }
  572. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  573. return S_OK;
  574. } else
  575. return HRESULT_FROM_WIN32(lRes);
  576. }
  577. HRESULT
  578. RegisterEnvVarsToExpand() {
  579. CString strKey;
  580. CString strValue;
  581. CString strEnvVars;
  582. TCHAR *pch;
  583. HRESULT hr;
  584. HKEY hKey;
  585. LONG status;
  586. if (!strKey.LoadString(IDS_SECEDIT_KEY)) {
  587. return E_FAIL;
  588. }
  589. if (!strValue.LoadString(IDS_ENV_VARS_REG_VALUE)) {
  590. return E_FAIL;
  591. }
  592. if (!strEnvVars.LoadString(IDS_DEF_ENV_VARS)) {
  593. return E_FAIL;
  594. }
  595. //
  596. // Convert strEnvVars' | to '\0' to be a proper multi-sz
  597. //
  598. for (int i = 0; i < strEnvVars.GetLength(); i++)
  599. {
  600. if (strEnvVars[i] == L'|')
  601. strEnvVars.SetAt(i, L'\0');
  602. }
  603. //
  604. // Open up the key we keep our Environment Variables in
  605. //
  606. status = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  607. strKey,
  608. 0, // Reserved
  609. NULL, // Class
  610. 0, // Options
  611. KEY_WRITE,
  612. NULL, // Security
  613. &hKey,
  614. NULL);
  615. if (ERROR_SUCCESS != status) {
  616. return HRESULT_FROM_WIN32(status);
  617. }
  618. int iLenth = strEnvVars.GetLength();
  619. BYTE* pbBufEnvVars = (BYTE*)(strEnvVars.GetBuffer(iLenth));
  620. status = RegSetValueEx(hKey,
  621. strValue,
  622. NULL,
  623. REG_MULTI_SZ,
  624. pbBufEnvVars,
  625. iLenth * sizeof(WCHAR));
  626. strEnvVars.ReleaseBuffer();
  627. if (ERROR_SUCCESS != status) {
  628. return HRESULT_FROM_WIN32(status);
  629. }
  630. return S_OK;
  631. }