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.

356 lines
12 KiB

  1. // filemgmt.cpp : Implementation of DLL Exports.
  2. // To fully complete this project follow these steps
  3. // You will need the new MIDL compiler to build this project. Additionally,
  4. // if you are building the proxy stub DLL, you will need new headers and libs.
  5. // 1) Add a custom build step to filemgmt.idl
  6. // You can select all of the .IDL files by holding Ctrl and clicking on
  7. // each of them.
  8. //
  9. // Description
  10. // Running MIDL
  11. // Build Command(s)
  12. // midl filemgmt.idl
  13. // Outputs
  14. // filemgmt.tlb
  15. // filemgmt.h
  16. // mmcfmgm_i.c
  17. //
  18. // NOTE: You must use the MIDL compiler from NT 4.0,
  19. // preferably 3.00.15 or greater
  20. // 2) Add a custom build step to the project to register the DLL
  21. // For this, you can select all projects at once
  22. // Description
  23. // Registering OLE Server...
  24. // Build Command(s)
  25. // regsvr32 /s /c "$(TargetPath)"
  26. // echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
  27. // Outputs
  28. // $(OutDir)\regsvr32.trg
  29. // 3) To add UNICODE support, follow these steps
  30. // Select Build|Configurations...
  31. // Press Add...
  32. // Change the configuration name to Unicode Release
  33. // Change the "Copy Settings From" combo to filemgmt - Win32 Release
  34. // Press OK
  35. // Press Add...
  36. // Change the configuration name to Unicode Debug
  37. // Change the "Copy Settings From" combo to filemgmt - Win32 Debug
  38. // Press OK
  39. // Press "Close"
  40. // Select Build|Settings...
  41. // Select the two UNICODE projects and press the C++ tab.
  42. // Select the "General" category
  43. // Add _UNICODE to the Preprocessor definitions
  44. // Select the Unicode Debug project
  45. // Press the "General" tab
  46. // Specify DebugU for the intermediate and output directories
  47. // Select the Unicode Release project
  48. // Press the "General" tab
  49. // Specify ReleaseU for the intermediate and output directories
  50. // 4) Proxy stub DLL
  51. // To build a separate proxy/stub DLL,
  52. // run nmake -f ps.mak in the project directory.
  53. #include "stdafx.h"
  54. #include "initguid.h"
  55. #include "filemgmt.h"
  56. #include "cmponent.h"
  57. #include "compdata.h"
  58. #include "macros.h" // MFC_TRY/MFC_CATCH
  59. #include "regkey.h" // AMC::CRegKey
  60. #include "strings.h" // SNAPINS_KEY etc.
  61. #include "guidhelp.h" // GuidToCString
  62. #include <compuuid.h> // UUIDs for Computer Management
  63. #include "about.h"
  64. #include "snapreg.h" // RegisterSnapin
  65. USE_HANDLE_MACROS("FILEMGMT(filemgmt.cpp)") \
  66. const CLSID CLSID_FileServiceManagement = {0x58221C65,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  67. const CLSID CLSID_SystemServiceManagement = {0x58221C66,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  68. const CLSID CLSID_FileServiceManagementExt = {0x58221C69,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  69. const CLSID CLSID_SystemServiceManagementExt = {0x58221C6a,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  70. const CLSID CLSID_FileServiceManagementAbout = {0xDB5D1FF4,0x09D7,0x11D1,{0xBB,0x10,0x00,0xC0,0x4F,0xC9,0xA3,0xA3}};
  71. const CLSID CLSID_SystemServiceManagementAbout ={0xDB5D1FF5,0x09D7,0x11D1,{0xBB,0x10,0x00,0xC0,0x4F,0xC9,0xA3,0xA3}};
  72. #ifdef SNAPIN_PROTOTYPER
  73. const CLSID CLSID_SnapinPrototyper = {0xab17ce10,0x9b30,0x11d0,{0xb6, 0xa6, 0x00, 0xaa, 0x00, 0x6e, 0xb9, 0x5b}};
  74. #endif
  75. CComModule _Module;
  76. HINSTANCE g_hInstanceSave; // Instance handle of the DLL
  77. BEGIN_OBJECT_MAP(ObjectMap)
  78. OBJECT_ENTRY(CLSID_FileServiceManagement, CFileSvcMgmtSnapin)
  79. OBJECT_ENTRY(CLSID_SystemServiceManagement, CServiceMgmtSnapin)
  80. OBJECT_ENTRY(CLSID_FileServiceManagementExt, CFileSvcMgmtExtension)
  81. OBJECT_ENTRY(CLSID_SystemServiceManagementExt, CServiceMgmtExtension)
  82. OBJECT_ENTRY(CLSID_FileServiceManagementAbout, CFileSvcMgmtAbout)
  83. OBJECT_ENTRY(CLSID_SystemServiceManagementAbout, CServiceMgmtAbout)
  84. OBJECT_ENTRY(CLSID_SvcMgmt, CStartStopHelper)
  85. #ifdef SNAPIN_PROTOTYPER
  86. OBJECT_ENTRY(CLSID_SnapinPrototyper, CServiceMgmtSnapin)
  87. #endif
  88. END_OBJECT_MAP()
  89. class CFileServiceMgmtApp : public CWinApp
  90. {
  91. public:
  92. virtual BOOL InitInstance();
  93. virtual int ExitInstance();
  94. };
  95. CFileServiceMgmtApp theApp;
  96. BOOL CFileServiceMgmtApp::InitInstance()
  97. {
  98. _Module.Init(ObjectMap, m_hInstance);
  99. SHFusionInitializeFromModuleID (m_hInstance, 2);
  100. VERIFY( SUCCEEDED(CFileMgmtComponent::LoadStrings()) );
  101. g_hInstanceSave = AfxGetInstanceHandle();
  102. return CWinApp::InitInstance();
  103. }
  104. int CFileServiceMgmtApp::ExitInstance()
  105. {
  106. SHFusionUninitialize();
  107. _Module.Term();
  108. return CWinApp::ExitInstance();
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // Used to determine whether the DLL can be unloaded by OLE
  112. STDAPI DllCanUnloadNow(void)
  113. {
  114. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  115. return (AfxDllCanUnloadNow() && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // Returns a class factory to create an object of the requested type
  119. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  120. {
  121. return _Module.GetClassObject(rclsid, riid, ppv);
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // DllRegisterServer - Adds entries to the system registry
  125. STDAPI DllRegisterServer(void)
  126. {
  127. MFC_TRY;
  128. HRESULT hr = S_OK;
  129. // registers object, there is no typelib
  130. hr = _Module.RegisterServer(FALSE);
  131. if ( FAILED(hr) )
  132. {
  133. ASSERT(FALSE && "_Module.RegisterServer(TRUE) failure.");
  134. return SELFREG_E_CLASS;
  135. }
  136. CString strFileMgmtCLSID, strSvcMgmtCLSID;
  137. CString strFileMgmtExtCLSID, strSvcMgmtExtCLSID;
  138. CString strFileMgmtAboutCLSID, strSvcMgmtAboutCLSID;
  139. if ( FAILED(hr = GuidToCString( &strFileMgmtCLSID, CLSID_FileServiceManagement ))
  140. || FAILED(hr = GuidToCString( &strSvcMgmtCLSID, CLSID_SystemServiceManagement ))
  141. || FAILED(hr = GuidToCString( &strFileMgmtExtCLSID, CLSID_FileServiceManagementExt ))
  142. || FAILED(hr = GuidToCString( &strSvcMgmtExtCLSID, CLSID_SystemServiceManagementExt ))
  143. || FAILED(hr = GuidToCString( &strFileMgmtAboutCLSID, CLSID_FileServiceManagementAbout ))
  144. || FAILED(hr = GuidToCString( &strSvcMgmtAboutCLSID, CLSID_SystemServiceManagementAbout ))
  145. )
  146. {
  147. ASSERT(FALSE && "GuidToCString() failure");
  148. return SELFREG_E_CLASS;
  149. }
  150. try
  151. {
  152. AMC::CRegKey regkeySnapins;
  153. BOOL fFound = regkeySnapins.OpenKeyEx( HKEY_LOCAL_MACHINE, SNAPINS_KEY );
  154. if ( !fFound )
  155. {
  156. ASSERT(FALSE && "DllRegisterServer() - Unable to open key from registry.");
  157. return SELFREG_E_CLASS;
  158. }
  159. static int filemgmt_types[7] =
  160. { FILEMGMT_ROOT,
  161. FILEMGMT_SHARES,
  162. FILEMGMT_SESSIONS,
  163. FILEMGMT_RESOURCES,
  164. FILEMGMT_SHARE,
  165. FILEMGMT_SESSION,
  166. FILEMGMT_RESOURCE };
  167. hr = RegisterSnapin( regkeySnapins,
  168. strFileMgmtCLSID,
  169. g_aNodetypeGuids[FILEMGMT_ROOT].bstr,
  170. IDS_REGISTER_FILEMGMT,
  171. IDS_SNAPINABOUT_PROVIDER,
  172. IDS_SNAPINABOUT_VERSION,
  173. true,
  174. strFileMgmtAboutCLSID,
  175. filemgmt_types,
  176. 7 );
  177. if ( FAILED(hr) )
  178. {
  179. ASSERT(FALSE);
  180. return SELFREG_E_CLASS;
  181. }
  182. static int svcmgmt_types[2] =
  183. { FILEMGMT_SERVICES,
  184. FILEMGMT_SERVICE };
  185. hr = RegisterSnapin( regkeySnapins,
  186. strSvcMgmtCLSID,
  187. g_aNodetypeGuids[FILEMGMT_SERVICES].bstr,
  188. IDS_REGISTER_SVCMGMT,
  189. IDS_SNAPINABOUT_PROVIDER,
  190. IDS_SNAPINABOUT_VERSION,
  191. true,
  192. strSvcMgmtAboutCLSID,
  193. svcmgmt_types,
  194. 2 );
  195. if ( FAILED(hr) )
  196. {
  197. ASSERT(FALSE);
  198. return SELFREG_E_CLASS;
  199. }
  200. static int filemgmtext_types[7] =
  201. { FILEMGMT_ROOT,
  202. FILEMGMT_SHARES,
  203. FILEMGMT_SESSIONS,
  204. FILEMGMT_RESOURCES,
  205. FILEMGMT_SHARE,
  206. FILEMGMT_SESSION,
  207. FILEMGMT_RESOURCE };
  208. hr = RegisterSnapin( regkeySnapins,
  209. strFileMgmtExtCLSID,
  210. NULL, // no primary nodetype
  211. IDS_REGISTER_FILEMGMT_EXT,
  212. IDS_SNAPINABOUT_PROVIDER,
  213. IDS_SNAPINABOUT_VERSION,
  214. false,
  215. // JonN 11/11/98 changed to use same About handler
  216. strFileMgmtAboutCLSID,
  217. filemgmtext_types,
  218. 7 );
  219. if ( FAILED(hr) )
  220. {
  221. ASSERT(FALSE);
  222. return SELFREG_E_CLASS;
  223. }
  224. static int svcmgmtext_types[2] =
  225. { FILEMGMT_SERVICES,
  226. FILEMGMT_SERVICE };
  227. hr = RegisterSnapin( regkeySnapins,
  228. strSvcMgmtExtCLSID,
  229. NULL, // no primary nodetype
  230. IDS_REGISTER_SVCMGMT_EXT,
  231. IDS_SNAPINABOUT_PROVIDER,
  232. IDS_SNAPINABOUT_VERSION,
  233. false,
  234. // JonN 11/11/98 changed to use same About handler
  235. strSvcMgmtAboutCLSID,
  236. svcmgmtext_types,
  237. 2 );
  238. if ( FAILED(hr) )
  239. {
  240. ASSERT(FALSE);
  241. return SELFREG_E_CLASS;
  242. }
  243. CString strFileExt, strSystemExt, strDefaultViewExt;
  244. if ( !strFileExt.LoadString(IDS_REGISTER_FILEMGMT_EXT)
  245. || !strSystemExt.LoadString(IDS_REGISTER_SVCMGMT_EXT)
  246. || !strDefaultViewExt.LoadString(IDS_REGISTER_DEFAULT_VIEW_EXT)
  247. )
  248. {
  249. ASSERT(FALSE);
  250. return SELFREG_E_CLASS;
  251. }
  252. AMC::CRegKey regkeyNodeTypes;
  253. fFound = regkeyNodeTypes.OpenKeyEx( HKEY_LOCAL_MACHINE, NODE_TYPES_KEY );
  254. if ( !fFound )
  255. {
  256. ASSERT(FALSE);
  257. return SELFREG_E_CLASS;
  258. }
  259. AMC::CRegKey regkeyNodeType;
  260. for (int i = FILEMGMT_ROOT; i < FILEMGMT_NUMTYPES; i++)
  261. {
  262. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, g_aNodetypeGuids[i].bstr );
  263. regkeyNodeType.CloseKey();
  264. }
  265. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, TEXT(struuidNodetypeSystemTools) );
  266. {
  267. AMC::CRegKey regkeyExtensions;
  268. regkeyExtensions.CreateKeyEx( regkeyNodeType, g_szExtensions );
  269. AMC::CRegKey regkeyNameSpace;
  270. regkeyNameSpace.CreateKeyEx( regkeyExtensions, g_szNameSpace );
  271. regkeyNameSpace.SetString( strFileMgmtExtCLSID, strFileExt );
  272. // JonN 5/27/99 deregister as extension of System Tools
  273. // ignore errors
  274. (void)::RegDeleteValue(regkeyNameSpace, strSvcMgmtExtCLSID);
  275. }
  276. regkeyNodeType.CloseKey();
  277. // JonN 5/27/99 register as extension of Server Apps
  278. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, TEXT(struuidNodetypeServerApps) );
  279. {
  280. AMC::CRegKey regkeyExtensions;
  281. regkeyExtensions.CreateKeyEx( regkeyNodeType, g_szExtensions );
  282. AMC::CRegKey regkeyNameSpace;
  283. regkeyNameSpace.CreateKeyEx( regkeyExtensions, g_szNameSpace );
  284. (void)::RegDeleteValue(regkeyNameSpace, strFileMgmtExtCLSID);
  285. regkeyNameSpace.SetString( strSvcMgmtExtCLSID, strSystemExt );
  286. }
  287. regkeyNodeType.CloseKey();
  288. // JonN 5/16/00 register Default View Extension under Services node
  289. regkeyNodeType.CreateKeyEx( regkeyNodeTypes, TEXT(struuidNodetypeServices) );
  290. {
  291. AMC::CRegKey regkeyExtensions;
  292. regkeyExtensions.CreateKeyEx( regkeyNodeType, g_szExtensions );
  293. AMC::CRegKey regkeyView;
  294. regkeyView.CreateKeyEx( regkeyExtensions, L"View" );
  295. regkeyView.SetString( L"{B708457E-DB61-4C55-A92F-0D4B5E9B1224}",
  296. strDefaultViewExt );
  297. }
  298. regkeyNodeType.CloseKey();
  299. }
  300. catch (COleException* e)
  301. {
  302. ASSERT(FALSE);
  303. e->Delete();
  304. return SELFREG_E_CLASS;
  305. }
  306. return hr;
  307. MFC_CATCH;
  308. }
  309. /////////////////////////////////////////////////////////////////////////////
  310. // DllUnregisterServer - Adds entries to the system registry
  311. STDAPI DllUnregisterServer(void)
  312. {
  313. HRESULT hRes = S_OK;
  314. _Module.UnregisterServer();
  315. // CODEWORK need to unregister properly
  316. return hRes;
  317. }