//+--------------------------------------------------------------------------- // // Function: HrUninstallNetComponent // // Purpose: Initialize INetCfg and uninstall a component // // Arguments: // szComponentId [in] InfId of component to uninstall (e.g. MS_TCPIP) // // Returns: S_OK or NETCFG_S_REBOOT on success, otherwise an error code // // Notes: // HRESULT HrUninstallNetComponent(IN PCWSTR szComponentId) { HRESULT hr=S_OK; INetCfg* pnc = NULL ; LogPrintf(_T("Trying to uninstall '%s'...\n"), szComponentId); // get INetCfg interface hr = HrGetINetCfg(TRUE, &pnc); if (SUCCEEDED(hr)) { // uninstall szComponentId hr = HrUninstallNetComponent(pnc, szComponentId); if (S_OK == hr) { // Apply the changes hr = pnc->Apply(); } else if (S_FALSE == hr) { LogPrintf(_T("'%s' is not installed\n"), szComponentId); } // release INetCfg (void) HrReleaseINetCfg(TRUE, pnc); } // show success/failure message ShowHrMessage(hr); return hr; }
//+--------------------------------------------------------------------------- // // Function: HrUninstallNetComponent // // Purpose: Initialize INetCfg and uninstall a component // // Arguments: // szComponentId [in] InfId of component to uninstall (e.g. MS_TCPIP) // // Returns: S_OK or NETCFG_S_REBOOT on success, otherwise an error code // // Notes: // HRESULT HrUninstallNetComponent(IN PCWSTR szComponentId) { HRESULT hr=S_OK; INetCfg* pnc; // get INetCfg interface hr = HrGetINetCfg(TRUE, &pnc); if (SUCCEEDED(hr)) { // uninstall szComponentId hr = HrUninstallNetComponent(pnc, szComponentId); if (S_OK == hr) { // Apply the changes hr = pnc->Apply(); } // release INetCfg (void) HrReleaseINetCfg(TRUE, pnc); } // show success/failure message ShowHrMessage(hr); return hr; }
//+--------------------------------------------------------------------------- // // Function: HrInstallNetComponent // // Purpose: Install the specified net component // // Arguments: // szComponentId [in] component to install // nc [in] class of the component // szInfFullPath [in] full path to primary INF file // required if the primary INF and other // associated files are not pre-copied to // the right destination dirs. // Not required when installing MS components // since the files are pre-copied by // Windows NT Setup. // // Returns: S_OK or NETCFG_S_REBOOT on success, otherwise an error code // // Notes: // HRESULT HrInstallNetComponent(IN PCTSTR szComponentId, IN enum NetClass nc, IN PCTSTR szInfFullPath) { HRESULT hr=S_OK; INetCfg* pnc; // cannot install net adapters this way. they have to be // enumerated/detected and installed by PnP if ((nc == NC_NetProtocol) || (nc == NC_NetService) || (nc == NC_NetClient)) { LogPrintf(_T("Trying to install '%s'...\n"), szComponentId); // if full path to INF has been specified, the INF // needs to be copied using Setup API to ensure that any other files // that the primary INF copies will be correctly found by Setup API // size_t cchPath; StringCchLength(szInfFullPath, MAX_PATH, &cchPath); if (szInfFullPath && cchPath) { TCHAR szInfNameAfterCopy[MAX_PATH+1]; if (SetupCopyOEMInf( szInfFullPath, NULL, // other files are in the // same dir. as primary INF SPOST_PATH, // first param. contains path to INF 0, // default copy style szInfNameAfterCopy, // receives the name of the INF // after it is copied to %windir%\inf MAX_PATH, // max buf. size for the above NULL, // receives required size if non-null NULL)) // optionally retrieves filename // component of szInfNameAfterCopy { LogPrintf(_T("...%s was copied to %s\n"), szInfFullPath, szInfNameAfterCopy); } else { DWORD dwError = GetLastError(); LogPrintf(_T("Error on SetupCopyOEMInf, error %d"), dwError); hr = HRESULT_FROM_WIN32(dwError); } } if (S_OK == hr) { // get INetCfg interface hr = HrGetINetCfg(TRUE, &pnc); if (SUCCEEDED(hr)) { // install szComponentId LogPrintf(_T("Installing %s\n"), szComponentId); hr = HrInstallNetComponent(pnc, szComponentId, c_aguidClass[nc]); if (SUCCEEDED(hr)) { LogPrintf(_T("Installed successfully\n")); // Apply the changes LogPrintf(_T("Applying changes\n")); hr = pnc->Apply(); LogPrintf(_T("Applied successfully\n")); } else { LogPrintf(_T("%s installation failed.\n")); } // release INetCfg (void) HrReleaseINetCfg(TRUE, pnc); } } // show success/failure message ShowHrMessage(hr); } return hr; }