Partager via


Internet Explorer caches settings

In the LoRIE doc for developers, it is mentioned that you can register your application as a broker with Internet Explorer by adding entries to:

    HKLM\SOFTWARE\Microsoft\Internet Explorer\Low Rights\ElevationPolicy

Unfortunately IE doesn't pick those up until IEUser.exe is restarted. You can use RestartManager APIs to cycle both IE and IEUser. Below is a code sample that shows how to accomplish this. Note that for demonstration purposes hardcoded paths are used and error handling is not as robust as it should be.

This will obviously work for other settings that are cached as well.

DWORD dwVal = ERROR_SUCCESS;

DWORD dwSessionHandle = (DWORD)-1;

WCHAR wszSessionKey[CCH_RM_SESSION_KEY+1];

UINT nProcInfo = 100;

UINT nProcInfoNeeded;

DWORD lpdwRebootReason = 0;

 

    //for demo purposes, hardcoded paths are used.

DWORD nFiles = 2;

LPWSTR rgsFiles[] = { L"c:\\program files\\internet explorer\\iexplore.exe",

L"c:\\program files\\internet explorer\\ieuser.exe" };

 

RM_PROCESS_INFO *rgProcs = new RM_PROCESS_INFO[nProcInfo];

if (NULL == rgProcs)

{

dwVal = ERROR_NOT_ENOUGH_MEMORY;

goto RM_END;

}

 

// Starting Session

dwVal = RmStartSession(&dwSessionHandle, 0, wszSessionKey);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Register items

dwVal = RmRegisterResources(dwSessionHandle, nFiles, (LPCWSTR*) rgsFiles,

0, NULL, 0, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Getting affected apps

dwVal = RmGetList(dwSessionHandle, &nProcInfoNeeded, &nProcInfo,

rgProcs, &lpdwRebootReason);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Apply filter to shutdown iexplore processes only

dwVal = RmAddFilter(dwSessionHandle, (LPCWSTR) rgsFiles[1],

NULL, NULL, RmNoShutdown);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Shutdown iexplore processes

dwVal = RmShutdown(dwSessionHandle, 0, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Remove previous filter & apply filter to shutdown ieuser only

dwVal = RmRemoveFilter(dwSessionHandle, (LPCWSTR) rgsFiles[1], NULL, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

dwVal = RmAddFilter(dwSessionHandle, (LPCWSTR) rgsFiles[0],

NULL, NULL, RmNoShutdown);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Shutdown ieuser process

dwVal = RmShutdown(dwSessionHandle, 0, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Remove filter applied to ieuser process

dwVal = RmRemoveFilter(dwSessionHandle, (LPCWSTR) rgsFiles[0], NULL, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Apply filter to restart ieuser process only

dwVal = RmAddFilter(dwSessionHandle, (LPCWSTR) rgsFiles[0],

NULL, NULL, RmNoRestart);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Restart ieuser

dwVal = RmRestart(dwSessionHandle, NULL, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Remove previous filter & add filter to restart iexplore only

dwVal = RmRemoveFilter(dwSessionHandle, (LPCWSTR) rgsFiles[0], NULL, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

dwVal = RmAddFilter(dwSessionHandle, (LPCWSTR) rgsFiles[1],

NULL, NULL, RmNoRestart);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

// Restart iexplore

dwVal = RmRestart(dwSessionHandle, NULL, NULL);

if (ERROR_SUCCESS != dwVal)

goto RM_END;

 

RM_END:

 

if (NULL != rgProcs)

delete [] rgProcs;

 

// Clean up session

if (-1 != dwSessionHandle)

RmEndSession(dwSessionHandle);

 

return dwVal;

Maarten

Comments

  • Anonymous
    February 25, 2007
    IE7の中からのプロセスの作成 その4 - Windows Vista/Internet Explorer 7 - 社本@ワック