Ejemplo n.º 1
0
INT
CAppOptGeneralPage::OnApply()
{
	BOOL fSuccess = FALSE;

	ATLTRACE("CAppOptGeneral::OnApply\n");

	BOOL fUseDisconnectAlert = (BST_CHECKED == m_wndAlertDisconnect.GetCheck());
	BOOL fUseReconnectAlert = (BST_CHECKED == m_wndAlertReconnect.GetCheck());

	pSetAppConfigValue(_T("UseDisconnectAlert"), fUseDisconnectAlert);
	pSetAppConfigValue(_T("UseReconnectAlert"), fUseReconnectAlert);

	if (m_disableAutoPlay != TriStateUnknown)
	{
		TRI_STATE newState = (BST_CHECKED == m_wndDisableAutoPlay.GetCheck()) ?
			TriStateYes : TriStateNo;
		if (m_disableAutoPlay != newState)
		{
			CComPtr<IAutoPlayConfig> pAutoPlayConfig;
			HRESULT hr = CoCreateInstanceAsAdmin(m_hWnd, 
				CLSID_CAutoPlayConfig,
				IID_IAutoPlayConfig,
				(void**) &pAutoPlayConfig);
			if (FAILED(hr))
			{
				ATLTRACE("CoCreateInstanceAsAdmin failed, hr=0x%X\n", hr);
			}
			else
			{
				hr = pAutoPlayConfig->SetNoDriveTypeAutoRun(
					reinterpret_cast<ULONG_PTR>(HKEY_CURRENT_USER),
					AutorunFixedDrive,
					newState == TriStateYes ? AutorunFixedDrive : 0);
				if (FAILED(hr))
				{
					ATLTRACE("IID_IAutoPlayConfig.SetNoDriveTypeAutoRun failed, hr=0x%X\n", hr);
				}
			}
		}
	}

	INT nSelItem = m_wndUILangList.GetCurSel();
	DWORD_PTR dwSelLangID = m_wndUILangList.GetItemData(nSelItem);

	if (m_wConfigLangID != (LANGID) dwSelLangID) 
	{
		pSetAppConfigValue(_T("Language"), (DWORD)dwSelLangID);

		AtlMessageBox(
			m_hWnd, 
			IDS_LANGUAGE_CHANGE, 
			IDS_MAIN_TITLE,
			MB_OK | MB_ICONINFORMATION);
	}

	return PSNRET_NOERROR;
}
//
//  FUNCTION: private RegisterAsDll(const TCHAR *, HWND, BOOL)
//
//  PURPOSE: Creates an instance of the specified IID in an elevated process.
//
//  COMMENTS:
//		tszFileName	- The filename to be registered
//		hwndMain	- The handle to the main window.
//		fRegister	- TRUE: register server.
//					- FALSE: unregister server.
//		
//		Uses CoCreateInstanceAsAdmin to load the IDllRegister Interface in an elevated process.
//		
//		Succeeds if registration is successful, fails otherwise.
//		Over The Shoulder (OTS) elevation will succeed in CoCreateInstanceAsAdmin with the correct credentials, but fail
//		with E_ACCESSDENIED if the registry key 'AppId/{CLSID}/AccessPermission' is not correctly set to allow the 
//		Interactive user. (See Register.cpp function SetOTSRegValue)
//		
HRESULT ElevationManager::RegisterAsDll(const TCHAR * tszFileName, HWND hwndMain, BOOL fRegister){
	
	HRESULT hr;
	IDllRegister * pDllRegister = NULL;
	TCHAR *tszFullFileName = NULL;
	BSTR bstrFileName = NULL;
	int bufLen = GetFullPathName(tszFileName, 0, NULL, NULL);

	tszFullFileName = (TCHAR *)malloc(sizeof(TCHAR) * bufLen);
	if(!tszFullFileName){
		hr = E_OUTOFMEMORY;
		goto cleanup;
	}

	if(!GetFullPathName(tszFileName, bufLen, tszFullFileName, NULL)){
		hr = HRESULT_FROM_WIN32(GetLastError());
		goto cleanup;
	}
	
	hr = CoCreateInstanceAsAdmin(hwndMain, CLSID_RegistrationClass, IID_IDllRegister, (void **) &pDllRegister);
	if(FAILED(hr)){
		goto cleanup;
	}

	bstrFileName = SysAllocString(tszFullFileName);
	
	if(!bstrFileName){
		hr = E_OUTOFMEMORY;
		goto cleanup;
	}

	if(fRegister)
		hr = pDllRegister->RegisterDll(bstrFileName);
	else
		hr = pDllRegister->UnRegisterDll(bstrFileName);
	

cleanup:	
	free(tszFullFileName);
	SysFreeString(bstrFileName);
	if(pDllRegister)
		pDllRegister->Release();
	pDllRegister=NULL;
	
	return hr;
}
Ejemplo n.º 3
0
HRESULT WindowsFirewallInitialize(OUT INetFwProfile** fwProfile, BOOL bInvokeUAE)
{
    HRESULT hr = S_OK;
    INetFwMgr* fwMgr = NULL;
    INetFwPolicy* fwPolicy = NULL;

    assert(fwProfile != NULL);

    *fwProfile = NULL;

    if(bInvokeUAE)
        hr = CoCreateInstanceAsAdmin(NULL, __uuidof(NetFwMgr), 
        __uuidof(INetFwMgr), (void**)&fwMgr);
    else
    {
        // Create an instance of the firewall settings manager.
        hr = CoCreateInstance(
            __uuidof(NetFwMgr),
            NULL,
            CLSCTX_INPROC_SERVER,
            __uuidof(INetFwMgr),
            (void**)&fwMgr
            );
    }
    if (FAILED(hr))
    {
        MYTRACE(ACE_TEXT("CoCreateInstance failed: 0x%08lx\n"), hr);
        goto error;
    }

    // Retrieve the local firewall policy.
    hr = fwMgr->get_LocalPolicy(&fwPolicy);
    if (FAILED(hr))
    {
        MYTRACE(ACE_TEXT("get_LocalPolicy failed: 0x%08lx\n"), hr);
        goto error;
    }

    // Retrieve the firewall profile currently in effect.
    hr = fwPolicy->get_CurrentProfile(fwProfile);
    if (FAILED(hr))
    {
        MYTRACE(ACE_TEXT("get_CurrentProfile failed: 0x%08lx\n"), hr);
        goto error;
    }

error:

    // Release the local firewall policy.
    if (fwPolicy != NULL)
    {
        fwPolicy->Release();
    }

    // Release the firewall settings manager.
    if (fwMgr != NULL)
    {
        fwMgr->Release();
    }

    return hr;
}