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.

233 lines
6.3 KiB

  1. #include <windows.h>
  2. #include <netcfgx.h>
  3. #include <netcfgn.h>
  4. #include <setupapi.h>
  5. #include <devguid.h>
  6. #include <tchar.h>
  7. #include <stdio.h>
  8. const WCHAR szComponentId[] = L"DSMIGRAT";
  9. const WCHAR szName[] = L"deldsm.exe";
  10. const WCHAR szClient[] = L"ms_nwclient";
  11. const WCHAR szUnknown[] = L"Microsoft";
  12. const WCHAR szDSM[] = L"dsmigrat";
  13. HRESULT
  14. HrFindAndRemoveComponent2(
  15. INetCfg* pnc,
  16. const GUID* pguidClass,
  17. PCWSTR pszComponentId,
  18. OBO_TOKEN* pOboToken)
  19. {
  20. // Get the component class object.
  21. //
  22. INetCfgClass* pncclass;
  23. HRESULT hr = pnc->QueryNetCfgClass (pguidClass, IID_INetCfgClass,
  24. reinterpret_cast<void**>(&pncclass));
  25. if (SUCCEEDED(hr))
  26. {
  27. // Find the component to remove.
  28. //
  29. INetCfgComponent* pnccRemove;
  30. hr = pncclass->FindComponent (pszComponentId, &pnccRemove);
  31. if (S_OK == hr)
  32. {
  33. INetCfgClassSetup* pncclasssetup;
  34. hr = pncclass->QueryInterface (IID_INetCfgClassSetup,
  35. reinterpret_cast<void**>(&pncclasssetup));
  36. if (SUCCEEDED(hr))
  37. {
  38. hr = pncclasssetup->DeInstall (pnccRemove, pOboToken, NULL);
  39. //ReleaseObj (pncclasssetup);
  40. pncclasssetup->Release();
  41. }
  42. //ReleaseObj (pnccRemove);
  43. pnccRemove->Release();
  44. }
  45. else if (S_FALSE == hr)
  46. {
  47. hr = S_OK;
  48. }
  49. //ReleaseObj (pncclass);
  50. pncclass->Release();
  51. }
  52. /*
  53. TraceHr (ttidError, FAL, hr,
  54. (NETCFG_S_REBOOT == hr) || (NETCFG_S_STILL_REFERENCED == hr),
  55. "HrFindAndRemoveComponent");
  56. */
  57. return hr;
  58. }
  59. HRESULT
  60. HrRemoveComponentOboSoftware2 (
  61. INetCfg* pnc,
  62. const GUID& rguidClass,
  63. PCWSTR pszComponentId,
  64. PCWSTR pszManufacturer,
  65. PCWSTR pszProduct,
  66. PCWSTR pszDisplayName)
  67. {
  68. // Make an "on behalf of" token for the software.
  69. //
  70. OBO_TOKEN OboToken;
  71. ZeroMemory (&OboToken, sizeof(OboToken));
  72. OboToken.Type = OBO_SOFTWARE;
  73. OboToken.pszwManufacturer = pszManufacturer;
  74. OboToken.pszwProduct = pszProduct;
  75. OboToken.pszwDisplayName = pszDisplayName;
  76. HRESULT hr = HrFindAndRemoveComponent2(pnc, &rguidClass, pszComponentId,
  77. &OboToken);
  78. return hr;
  79. }
  80. HRESULT
  81. HrCreateAndInitializeINetCfg2 (
  82. BOOL* pfInitCom,
  83. INetCfg** ppnc,
  84. BOOL fGetWriteLock,
  85. DWORD cmsTimeout,
  86. PCWSTR pszClientDesc,
  87. PWSTR* ppszClientDesc)
  88. {
  89. //Assert (ppnc);
  90. // Initialize the output parameters.
  91. *ppnc = NULL;
  92. if (ppszClientDesc)
  93. {
  94. *ppszClientDesc = NULL;
  95. }
  96. // Initialize COM if the caller requested.
  97. HRESULT hr = S_OK;
  98. if (pfInitCom && *pfInitCom)
  99. {
  100. hr = CoInitializeEx( NULL,
  101. COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED );
  102. if (RPC_E_CHANGED_MODE == hr)
  103. {
  104. hr = S_OK;
  105. *pfInitCom = FALSE;
  106. }
  107. }
  108. if (SUCCEEDED(hr))
  109. {
  110. // Create the object implementing INetCfg.
  111. //
  112. INetCfg* pnc;
  113. hr = CoCreateInstance(
  114. CLSID_CNetCfg,
  115. NULL,
  116. CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  117. IID_INetCfg,
  118. reinterpret_cast<void**>(&pnc));
  119. if (SUCCEEDED(hr))
  120. {
  121. INetCfgLock * pnclock = NULL;
  122. if (fGetWriteLock)
  123. {
  124. // Get the locking interface
  125. hr = pnc->QueryInterface(IID_INetCfgLock,
  126. reinterpret_cast<LPVOID *>(&pnclock));
  127. if (SUCCEEDED(hr))
  128. {
  129. // Attempt to lock the INetCfg for read/write
  130. hr = pnclock->AcquireWriteLock(cmsTimeout, pszClientDesc,
  131. ppszClientDesc);
  132. if (S_FALSE == hr)
  133. {
  134. // Couldn't acquire the lock
  135. hr = NETCFG_E_NO_WRITE_LOCK;
  136. }
  137. }
  138. }
  139. if (SUCCEEDED(hr))
  140. {
  141. // Initialize the INetCfg object.
  142. //
  143. hr = pnc->Initialize (NULL);
  144. if (SUCCEEDED(hr))
  145. {
  146. *ppnc = pnc;
  147. //AddRefObj (pnc);
  148. pnc->AddRef();
  149. }
  150. else
  151. {
  152. if (pnclock)
  153. {
  154. pnclock->ReleaseWriteLock();
  155. }
  156. }
  157. // Transfer reference to caller.
  158. }
  159. //ReleaseObj(pnclock);
  160. pnclock->Release();
  161. //ReleaseObj(pnc);
  162. pnc->Release();
  163. }
  164. // If we failed anything above, and we've initialized COM,
  165. // be sure an uninitialize it.
  166. //
  167. if (FAILED(hr) && pfInitCom && *pfInitCom)
  168. {
  169. CoUninitialize ();
  170. }
  171. }
  172. return hr;
  173. }
  174. extern "C" int __cdecl wmain(
  175. IN int argc,
  176. IN PWSTR argv[]
  177. )
  178. {
  179. INetCfg *pnc = NULL;
  180. HRESULT hr = S_OK;
  181. PWSTR pszDesc = NULL;
  182. BOOL fInitCom = TRUE;
  183. BOOL fWriteLock = TRUE;
  184. hr = HrCreateAndInitializeINetCfg2(&fInitCom,
  185. &pnc,
  186. fWriteLock,
  187. 0,
  188. szName,
  189. &pszDesc);
  190. if (FAILED(hr)) {
  191. goto error;
  192. }
  193. hr = HrRemoveComponentOboSoftware2(pnc,
  194. GUID_DEVCLASS_NETCLIENT,
  195. szClient,
  196. szUnknown,
  197. szDSM,
  198. szComponentId);
  199. if (FAILED(hr)) {
  200. goto error;
  201. }
  202. printf("DSMU's dependencies on GSNW and IPX have been removed. To complete the uninstall, please delete the 'DSMigrat' directory under the directory 'Program Files'.\n");
  203. error:
  204. if (FAILED(hr)) {
  205. printf("The uninstallation of Dsmigrat has failed with an error 0x%x\n",hr);
  206. }
  207. if (pnc)
  208. pnc->Release();
  209. return 0;
  210. }