Пример #1
0
HRESULT CMuxVirtualMiniport::DeInstall (VOID)
{
    INetCfgClass       *pncClass;
    INetCfgClassSetup  *pncClassSetup;
    INetCfgComponent   *pnccMiniport;
    HRESULT            hr;
    LPWSTR  *pmszwRefs=NULL;
    OBO_TOKEN  *pOboToken=NULL;

    TraceMsg( L"-->CMuxVirtualMiniport::DeInstall.\n" );

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

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

            hr = HrFindInstance( m_pnc,
                                 m_guidMiniport,
                                 &pnccMiniport );

            if ( hr == S_OK ) {

                TraceMsg( L"   Found the miniport instance to uninstall.\n" );
                
                hr = pncClassSetup->DeInstall( pnccMiniport,
                                               pOboToken,
                                               pmszwRefs );
                ReleaseObj( pnccMiniport );
            }
            else {
                TraceMsg( L"   Didn't find the miniport instance to uninstall.\n" );
            }

            ReleaseObj( pncClassSetup );
        }
        else {

            TraceMsg( L"   QueryInterface failed.\n" );
        }

        ReleaseObj( pncClass );
    }
    else {

        TraceMsg( L"   QueryNetCfgClass failed.\n" );
    }

    TraceMsg( L"<--CMuxVirtualMiniport::DeInstall(HRESULT = %x).\n",
              hr );

    return hr;
}
Пример #2
0
HRESULT HrInstallComponent(
	IN INetCfg* pnc,
	IN LPCTSTR szComponentId,
	IN const GUID* pguidClass
) {
	INetCfgClassSetup   *pncClassSetup = NULL;
	INetCfgComponent    *pncc = NULL;
	OBO_TOKEN           OboToken;
	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 component's setup class reference.
	//
	hr = pnc->QueryNetCfgClass(pguidClass,
		IID_INetCfgClassSetup,
		(void**)&pncClassSetup);

	if (hr == S_OK) {
		hr = pncClassSetup->Install(szComponentId,
			&OboToken,
			0,
			0,       // Upgrade from build number.
			NULL,    // Answerfile name
			NULL,    // Answerfile section name
			&pncc); // Reference after the component
		if (S_OK == hr) {                   // is installed.

											//
											// we don't need to use pncc (INetCfgComponent), release it
											//

			ReleaseRef(pncc);
		}

		ReleaseRef(pncClassSetup);
	}

	return hr;
}
Пример #3
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;
}
Пример #4
0
//+---------------------------------------------------------------------------
//
// Function:  HrInstallNetComponent
//
// Purpose:   Install the specified net component
//
// Arguments:
//    pnc           [in]  pointer to INetCfg object
//    szComponentId [in]  component to install
//    pguidClass    [in]  class guid of the component
//
// Returns:   S_OK or NETCFG_S_REBOOT on success, otherwise an error code
//
// Notes:
//
HRESULT HrInstallNetComponent(IN INetCfg* pnc,
                              IN PCWSTR szComponentId,
                              IN const GUID* pguidClass)
{
    HRESULT hr=S_OK;
    OBO_TOKEN OboToken;
    INetCfgClassSetup* pncClassSetup;
    INetCfgComponent* pncc;

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

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

    hr = pnc->QueryNetCfgClass (pguidClass, IID_INetCfgClassSetup,
                                (void**)&pncClassSetup);
    if (SUCCEEDED(hr))
    {
        hr = pncClassSetup->Install(szComponentId,
                                    &OboToken,
                                    NSF_POSTSYSINSTALL,
                                    0,       // <upgrade-from-build-num>
                                    NULL,    // answerfile name
                                    NULL,    // answerfile section name
                                    &pncc);
        if (S_OK == hr)
        {
            // we dont want to use pncc (INetCfgComponent), release it
            ReleaseObj(pncc);
        }

        ReleaseObj(pncClassSetup);
    }

    return hr;
}
Пример #5
0
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;
}
Пример #6
0
//+---------------------------------------------------------------------------
//
// Function:  HrInstallNetComponent
//
// Purpose:   Install the specified net component
//
// Arguments:
//    pnc           [in]  pointer to INetCfg object
//    szComponentId [in]  component to install
//    pguidClass    [in]  class guid of the component
//
// Returns:   S_OK or NETCFG_S_REBOOT on success, otherwise an error code
//
// Notes:
//
HRESULT HrInstallNetComponent(IN INetCfg* pnc,
                              IN PCTSTR szComponentId,
                              IN const GUID* pguidClass)
{
    HRESULT hr=S_OK;
    OBO_TOKEN OboToken;
    INetCfgClassSetup* pncClassSetup;
    INetCfgComponent* pncc;
	WCHAR szComponentIdW[256] ;
	int cnt ;


#ifdef _MBCS

	// @hootch@
	// 
	//
	size_t cchLen;
	StringCchLength(szComponentId, 256, &cchLen);
	cnt = MultiByteToWideChar(
		CP_ACP,						// code page
		0,							// character-type options
		szComponentId,				// string to map
		cchLen, // number of bytes in string
		szComponentIdW,				// wide-character buffer
		256							// size of buffer
	);
	if(cnt == 0) {
		// error
		return S_FALSE ;
	}

#endif

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

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

    hr = pnc->QueryNetCfgClass (pguidClass, IID_INetCfgClassSetup,
                                (void**)&pncClassSetup);
    if (SUCCEEDED(hr))
    {

		LogPrintf(_T("QueryNetCfg succeeded.\n"));

#ifdef _MBCS
        hr = pncClassSetup->Install(szComponentIdW,
                                    &OboToken,
                                    NSF_POSTSYSINSTALL,
                                    0,       // <upgrade-from-build-num>
                                    NULL,    // answerfile name
                                    NULL,    // answerfile section name
                                    &pncc);
#else
        hr = pncClassSetup->Install(szComponentId,
                                    &OboToken,
                                    NSF_POSTSYSINSTALL,
                                    0,       // <upgrade-from-build-num>
                                    NULL,    // answerfile name
                                    NULL,    // answerfile section name
                                    &pncc);
#endif
        if (S_OK == hr)
        {

			LogPrintf(_T("ClassSetup Install succeeded.\n"));

            // we dont want to use pncc (INetCfgComponent), release it
            ReleaseObj(pncc);
        } else {

			LogPrintf(_T("ClassSetup Install failed.\n"));

        }

        ReleaseObj(pncClassSetup);
    } else {
		LogPrintf(_T("QueryNetCfg failed.\n"));
    }

    return hr;
}
Пример #7
0
// Install the NDIS protocol driver
bool InstallNdisProtocolDriver(wchar_t *inf_path, wchar_t *id, UINT lock_timeout)
{
	bool ret = false;
	HRESULT hr;
	INetCfg *pNetCfg;
	HINSTANCE hSetupApiDll = NULL;
	BOOL (WINAPI *_SetupCopyOEMInfW)(PCWSTR, PCWSTR, DWORD, DWORD, PWSTR, DWORD, PDWORD, PWSTR *) = NULL;
	BOOL (WINAPI *_SetupUninstallOEMInfW)(PCWSTR, DWORD, PVOID) = NULL;
	// Validate arguments
	if (inf_path == NULL || id == NULL)
	{
		return false;
	}

	hSetupApiDll = LoadLibraryA("setupapi.dll");
	if (hSetupApiDll == NULL)
	{
		WHERE;
		goto LABEL_CLEANUP;
	}

	_SetupCopyOEMInfW =
		(UINT (__stdcall *)(PCWSTR,PCWSTR,DWORD,DWORD,PWSTR,DWORD,PDWORD,PWSTR *))
		GetProcAddress(hSetupApiDll, "SetupCopyOEMInfW");

	_SetupUninstallOEMInfW =
		(UINT (__stdcall *)(PCWSTR,DWORD,PVOID))
		GetProcAddress(hSetupApiDll, "SetupUninstallOEMInfW");

	if (_SetupCopyOEMInfW == NULL || _SetupUninstallOEMInfW == NULL)
	{
		WHERE;
		goto LABEL_CLEANUP;
	}

	hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (void **)&pNetCfg);

	if (SUCCEEDED(hr))
	{
		INetCfgLock *pLock;

		hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);

		if (SUCCEEDED(hr))
		{
			LPWSTR locked_by;

			hr = pLock->AcquireWriteLock(lock_timeout, L"SoftEther VPN", &locked_by);

			if (SUCCEEDED(hr))
			{
				hr = pNetCfg->Initialize(NULL);

				if (SUCCEEDED(hr))
				{
					wchar_t inf_dir[MAX_PATH];

					GetDirNameFromFilePathW(inf_dir, sizeof(inf_dir), inf_path);

					if (_SetupCopyOEMInfW(inf_path, inf_dir, SPOST_PATH, 0, NULL, 0, NULL, 0))
					{
						INetCfgClassSetup *pSetup;

						hr = pNetCfg->QueryNetCfgClass(&GUID_DEVCLASS_NETTRANS, IID_INetCfgClassSetup, (void **)&pSetup);

						if (SUCCEEDED(hr))
						{
							OBO_TOKEN token;
							INetCfgComponent *pComponent;

							Zero(&token, sizeof(token));

							token.Type = OBO_USER;

							hr = pSetup->Install(id, &token, 0, 0, NULL, NULL, &pComponent);

							if (SUCCEEDED(hr))
							{
								pNetCfg->Apply();

								ret = true;
							}
							else
							{
								WHERE;
								Debug("0x%x\n", hr);
							}

							pSetup->Release();
						}
						else
						{
							WHERE;
						}

						if (ret == false)
						{
							wchar_t dst_inf_name[MAX_PATH];
							DWORD dst_inf_name_size = MAX_PATH;

							if (_SetupCopyOEMInfW(inf_path, inf_dir, SPOST_PATH, SP_COPY_REPLACEONLY,
								dst_inf_name, dst_inf_name_size, &dst_inf_name_size, NULL) == false &&
								GetLastError() == ERROR_FILE_EXISTS)
							{
								_SetupUninstallOEMInfW(dst_inf_name, 0, NULL);
							}
						}
					}
					else
					{
						WHERE;
					}
				}
				else
				{
					WHERE;
				}

				pLock->ReleaseWriteLock();
			}
			else
			{
				WHERE;
			}

			pLock->Release();
		}

		pNetCfg->Release();
	}
	else
	{
		WHERE;
	}

LABEL_CLEANUP:

	if (hSetupApiDll != NULL)
	{
		FreeLibrary(hSetupApiDll);
	}

	return ret;
}
Пример #8
0
// Install the NDIS protocol driver
bool UninstallNdisProtocolDriver(wchar_t *id, UINT lock_timeout)
{
	bool ret = false;
	HRESULT hr;
	INetCfg *pNetCfg;
	// Validate arguments
	if (id == NULL)
	{
		return false;
	}

	hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (void **)&pNetCfg);

	if (SUCCEEDED(hr))
	{
		INetCfgLock *pLock;

		hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);

		if (SUCCEEDED(hr))
		{
			LPWSTR locked_by;

			hr = pLock->AcquireWriteLock(lock_timeout, L"SoftEther VPN", &locked_by);

			if (SUCCEEDED(hr))
			{
				hr = pNetCfg->Initialize(NULL);

				if (SUCCEEDED(hr))
				{
					INetCfgComponent *pncc = NULL;

					hr = pNetCfg->FindComponent(id, &pncc);

					if (pncc == NULL || hr == S_FALSE)
					{
						hr = E_FAIL;
					}

					if (SUCCEEDED(hr))
					{
						INetCfgClass *pncClass;

						hr = pNetCfg->QueryNetCfgClass(&GUID_DEVCLASS_NETTRANS, IID_INetCfgClass, (void **)&pncClass);
						if (SUCCEEDED(hr))
						{
							INetCfgClassSetup *pncClassSetup;

							hr = pncClass->QueryInterface(IID_INetCfgClassSetup, (void **)&pncClassSetup);
							if (SUCCEEDED(hr))
							{
								OBO_TOKEN obo;
								wchar_t *c = NULL;

								Zero(&obo, sizeof(obo));

								obo.Type = OBO_USER;

								hr = pncClassSetup->DeInstall(pncc, &obo, &c);

								if (SUCCEEDED(hr))
								{
									hr = pNetCfg->Apply();

									if (SUCCEEDED(hr))
									{
										ret = true;
									}
									else
									{
										WHERE;
										Debug("0x%x\n", hr);
									}
								}
								else
								{
									WHERE;
									Debug("0x%x\n", hr);
								}

								pncClassSetup->Release();
							}
							else
							{
								WHERE;
							}

							pncClass->Release();
						}
						else
						{
							WHERE;
						}

						pncc->Release();
					}
					else
					{
						WHERE;
					}
				}
				else
				{
					WHERE;
				}

				pLock->ReleaseWriteLock();
			}
			else
			{
				WHERE;
			}

			pLock->Release();
		}

		pNetCfg->Release();
	}
	else
	{
		WHERE;
	}

	return ret;
}
Пример #9
0
HRESULT CMuxVirtualMiniport::Install (VOID)
{
    INetCfgClass       *pncClass;
    INetCfgClassSetup  *pncClassSetup;
    INetCfgComponent   *pnccMiniport;
    HRESULT            hr;
    LPWSTR  *pmszwRefs=NULL;
    OBO_TOKEN  *pOboToken=NULL;    
    DWORD  dwSetupFlags=0;
    LPCWSTR  pszwAnswerFile=NULL;
    LPCWSTR  pszwAnswerSections=NULL; 


    TraceMsg( L"-->CMuxVirtualMiniport::Install.\n" );

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

        hr = pncClass->QueryInterface( IID_INetCfgClassSetup,
                                       (void **)&pncClassSetup );
        if ( hr == S_OK ) {
            
            hr = pncClassSetup->Install( c_szMuxMiniport,
                                         pOboToken,
                                         dwSetupFlags,
                                         0,
                                         pszwAnswerFile,
                                         pszwAnswerSections,
                                         &pnccMiniport );
            if ( hr == S_OK ) {

                hr = pnccMiniport->GetInstanceGuid( &m_guidMiniport );

                if ( hr != S_OK ) {

                    TraceMsg( L"   Failed to get the instance guid, uninstalling "
                              L" the miniport.\n" );
                    
                    pncClassSetup->DeInstall( pnccMiniport,
                                              pOboToken,
                                              pmszwRefs );
                }

                ReleaseObj( pnccMiniport );
            }
            else {

                TraceMsg( L"   Failed to install the miniport.\n" );
            }

            ReleaseObj( pncClassSetup );
        }
        else {

            TraceMsg( L"   QueryInterface failed.\n" );
        }

        ReleaseObj( pncClass );
    }
    else {

     TraceMsg( L"   QueryNetCfgClass failed.\n" );
    }

    TraceMsg( L"<--CMuxVirtualMiniport::Install(HRESULT = %x).\n",
            hr );

    return hr;
}
Пример #10
0
bool UninstallNdisProtocolDriver(wchar_t *id, UINT lock_timeout)
{
	bool ret = false;
	HRESULT hr;
	INetCfg *pNetCfg;
	// Validate arguments
	if (id == NULL)
	{
		return false;
	}
	hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (void **)&pNetCfg);

	if (SUCCEEDED(hr))
	{
		INetCfgLock *pLock;

		hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);

		if (SUCCEEDED(hr))
		{
			LPWSTR locked_by;

			hr = pLock->AcquireWriteLock(lock_timeout, L"SoftEther VPN", &locked_by);

			if (SUCCEEDED(hr))
			{
				hr = pNetCfg->Initialize(NULL);

				if (SUCCEEDED(hr))
				{
					INetCfgComponent *pComponent;
					hr = pNetCfg->FindComponent(id, &pComponent);

					if (SUCCEEDED(hr))
					{
						INetCfgClassSetup *pSetup;

						hr = pNetCfg->QueryNetCfgClass(&GUID_DEVCLASS_NETTRANS, IID_INetCfgClassSetup, (void **)&pSetup);

						if (SUCCEEDED(hr))
						{
							OBO_TOKEN token;

							SeZero(&token, sizeof(token));

							token.Type = OBO_USER;

							hr = pSetup->DeInstall(pComponent, &token, NULL);

							if (SUCCEEDED(hr))
							{
								pNetCfg->Apply();

								ret = true;
							}

							pSetup->Release();
						}
					}
				}

				pLock->ReleaseWriteLock();
			}

			pLock->Release();
		}

		pNetCfg->Release();
	}

	return ret;
}
Пример #11
0
bool InstallNdisProtocolDriver(char *inf_path, wchar_t *id, UINT lock_timeout)
{
	bool ret = false;
	HRESULT hr;
	INetCfg *pNetCfg;
	// Validate arguments
	if (inf_path == NULL || id == NULL)
	{
		return false;
	}
	hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (void **)&pNetCfg);

	if (SUCCEEDED(hr))
	{
		INetCfgLock *pLock;

		hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);

		if (SUCCEEDED(hr))
		{
			LPWSTR locked_by;

			hr = pLock->AcquireWriteLock(lock_timeout, L"SoftEther VPN", &locked_by);

			if (SUCCEEDED(hr))
			{
				hr = pNetCfg->Initialize(NULL);

				if (SUCCEEDED(hr))
				{
					char inf_dir[MAX_PATH];

					SeGetDirNameFromFilePath(inf_dir, sizeof(inf_dir), inf_path);

					if (SetupCopyOEMInfA(inf_path, inf_dir, SPOST_PATH, 0, NULL, 0, NULL, 0))
					{
						INetCfgClassSetup *pSetup;

						hr = pNetCfg->QueryNetCfgClass(&GUID_DEVCLASS_NETTRANS, IID_INetCfgClassSetup, (void **)&pSetup);

						if (SUCCEEDED(hr))
						{
							OBO_TOKEN token;
							INetCfgComponent *pComponent;

							SeZero(&token, sizeof(token));

							token.Type = OBO_USER;

							hr = pSetup->Install(id, &token, 0, 0, NULL, NULL, &pComponent);

							if (SUCCEEDED(hr))
							{
								pNetCfg->Apply();

								ret = true;
							}

							pSetup->Release();
						}

						if (ret == false)
						{
							char dst_inf_name[MAX_PATH];
							DWORD dst_inf_name_size = MAX_PATH;

							if (SetupCopyOEMInfA(inf_path, inf_dir, SPOST_PATH, SP_COPY_REPLACEONLY,
								dst_inf_name, dst_inf_name_size, &dst_inf_name_size, NULL) == false &&
								GetLastError() == ERROR_FILE_EXISTS)
							{
								SetupUninstallOEMInfA(dst_inf_name, 0, NULL);
							}
						}
					}
				}

				pLock->ReleaseWriteLock();
			}

			pLock->Release();
		}

		pNetCfg->Release();
	}

	return ret;
}
Пример #12
0
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;
}