예제 #1
0
//+---------------------------------------------------------------------------
//
// Function:  HrUninstallNetComponent
//
// Purpose:   Uninstall the specified component.
//
// Arguments:
//    pnc           [in]  pointer to INetCfg object
//    szComponentId [in]  component to uninstall
//
// Returns:   S_OK or NETCFG_S_REBOOT on success, otherwise an error code
//
// Notes:
//
HRESULT HrUninstallNetComponent(IN INetCfg* pnc, IN PCWSTR szComponentId)
{
    HRESULT hr=S_OK;
    OBO_TOKEN OboToken;
    INetCfgComponent* pncc;
    GUID guidClass;
    INetCfgClass* pncClass;
    INetCfgClassSetup* pncClassSetup;

    // OBO_TOKEN specifies the entity on whose behalf this
    // component is being uninstalld

    // set it to OBO_USER so that szComponentId will be uninstalld
    // On-Behalf-Of "user"
    ZeroMemory (&OboToken, sizeof(OboToken));
    OboToken.Type = OBO_USER;

    // see if the component is really installed
    hr = pnc->FindComponent(szComponentId, &pncc);

    if (S_OK == hr)
    {
        // yes, it is installed. obtain INetCfgClassSetup and DeInstall

        hr = pncc->GetClassGuid(&guidClass);

        if (S_OK == hr)
        {
            hr = pnc->QueryNetCfgClass(&guidClass, IID_INetCfgClass,
                                       (void**)&pncClass);
            if (SUCCEEDED(hr))
            {
                hr = pncClass->QueryInterface(IID_INetCfgClassSetup,
                                              (void**)&pncClassSetup);
                    if (SUCCEEDED(hr))
                    {
                        hr = pncClassSetup->DeInstall (pncc, &OboToken, NULL);

                        ReleaseObj (pncClassSetup);
                    }
                ReleaseObj(pncClass);
            }
        }
        ReleaseObj(pncc);
    }

    return hr;
}
예제 #2
0
파일: ProtInstall.cpp 프로젝트: 52M/npcap
DWORD UninstallDriver()
{
	TRACE_ENTER("UninstallDriver");
	//_tprintf( _T("Uninstalling %s...\n"), NDISPROT_FRIENDLY_NAME );

// 	int nResult = MessageBox(NULL, _T("Uninstalling Driver..."), NDISPROT_FRIENDLY_NAME, MB_OKCANCEL | MB_ICONINFORMATION);
// 
// 	if (nResult != IDOK)
// 	{
// 		return 0;
// 	}

	INetCfg* pnc;
	INetCfgComponent* pncc;
	INetCfgClass* pncClass;
	INetCfgClassSetup* pncClassSetup;
	LPTSTR lpszApp;
	GUID guidClass;
	OBO_TOKEN obo;
	HRESULT hr;

	hr = HrGetINetCfg(TRUE, APP_NAME, &pnc, &lpszApp);

	if (hr == S_OK)
	{
		//
		// Get a reference to the network component to uninstall.
		//
		hr = pnc->FindComponent(NDISLWF_SERVICE_PNP_DEVICE_ID, &pncc);

		if (hr == S_OK)
		{
			//
			// Get the class GUID.
			//
			hr = pncc->GetClassGuid(&guidClass);

			if (hr == S_OK)
			{
				//
				// Get a reference to component's class.
				//

				hr = pnc->QueryNetCfgClass(&guidClass, IID_INetCfgClass, (PVOID *)&pncClass);
				if (hr == S_OK)
				{
					//
					// Get the setup interface.
					//

					hr = pncClass->QueryInterface(IID_INetCfgClassSetup, (LPVOID *)&pncClassSetup);

					if (hr == S_OK)
					{
						//
						// Uninstall the component.
						//

						ZeroMemory(&obo, sizeof(OBO_TOKEN));

						obo.Type = OBO_USER;

						hr = pncClassSetup->DeInstall(pncc, &obo, NULL);
						if ((hr == S_OK) || (hr == NETCFG_S_REBOOT))
						{
							hr = pnc->Apply();

							if ((hr != S_OK) && (hr != NETCFG_S_REBOOT))
							{
								ErrMsg(hr, L"Couldn't apply the changes after"
									L" uninstalling %s.", NDISLWF_SERVICE_PNP_DEVICE_ID);
							}
							else
							{
								TRACE_EXIT("UninstallDriver");
								return 1;
							}
						}
						else
						{
							ErrMsg(hr, L"Failed to uninstall %s.", NDISLWF_SERVICE_PNP_DEVICE_ID);
						}

						ReleaseRef(pncClassSetup);
					}
					else
					{
						ErrMsg(hr, L"Couldn't get an interface to setup class.");
					}

					ReleaseRef(pncClass);
				}
				else
				{
					ErrMsg(hr, L"Couldn't get a pointer to class interface "
						L"of %s.", NDISLWF_SERVICE_PNP_DEVICE_ID);
				}
			}
			else
			{
				ErrMsg(hr, L"Couldn't get the class guid of %s.", NDISLWF_SERVICE_PNP_DEVICE_ID);
			}

			ReleaseRef(pncc);
		}
		else
		{
			ErrMsg(hr, L"Couldn't get an interface pointer to %s.", NDISLWF_SERVICE_PNP_DEVICE_ID);
		}

		HrReleaseINetCfg(pnc, TRUE);
	}
	else
	{
		if ((hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp)
		{
			ErrMsg(hr, L"%s currently holds the lock, try later.", lpszApp);

			CoTaskMemFree(lpszApp);
		}
		else
		{
			ErrMsg(hr, L"Couldn't get the notify object interface.");
		}
	}

	TRACE_EXIT("UninstallDriver");
	return 0;
}
예제 #3
0
파일: netcfgapi.cpp 프로젝트: aczire/metcap
HRESULT HrUninstallNetComponent(
	IN INetCfg* pnc,
	IN LPCTSTR szComponentId
) {
	INetCfgComponent    *pncc = NULL;
	INetCfgClass        *pncClass = NULL;
	INetCfgClassSetup   *pncClassSetup = NULL;
	OBO_TOKEN           OboToken;
	GUID                guidClass;
	HRESULT             hr = S_OK;

	//
	// OBO_TOKEN specifies on whose behalf this
	// component is being installed.
	// Set it to OBO_USER so that szComponentId will be installed
	// on behalf of the user.
	//

	ZeroMemory(&OboToken,
		sizeof(OboToken));
	OboToken.Type = OBO_USER;

	//
	// Get the component's reference.
	//

	hr = pnc->FindComponent(szComponentId,
		&pncc);

	if (S_OK == hr) {

		//
		// Get the component's class GUID.
		//

		hr = pncc->GetClassGuid(&guidClass);

		if (hr == S_OK) {

			//
			// Get component's class reference.
			//

			hr = pnc->QueryNetCfgClass(&guidClass,
				IID_INetCfgClass,
				(void**)&pncClass);
			if (hr == S_OK) {

				//
				// Get Setup reference.
				//

				hr = pncClass->QueryInterface(IID_INetCfgClassSetup,
					(void**)&pncClassSetup);
				if (hr == S_OK) {

					hr = pncClassSetup->DeInstall(pncc,
						&OboToken,
						NULL);
					if (hr == S_OK) {

						//
						// Apply the changes
						//

						hr = pnc->Apply();
					}

					ReleaseRef(pncClassSetup);
				}

				ReleaseRef(pncClass);
			}
		}

		ReleaseRef(pncc);
	}

	return hr;
}