Funzione IsProcessInIsolatedWindowsEnvironment (isolatedwindowsenvironmentutils.h)

Determina in quale ambiente di esecuzione l'applicazione è in esecuzione, ovvero un host o un ambiente isolato.

Sintassi

HRESULT IsProcessInIsolatedWindowsEnvironment(
  BOOL *isProcessInIsolatedWindowsEnvironment
);

Parametri

isProcessInIsolatedWindowsEnvironment

[out]

Puntatore a un valore booleano che riceve il risultato dell'API. Questo parametro sarà true se il processo si trova in un ambiente Windows isolato, false in caso contrario.

Valore restituito

Restituisce S_OK se la funzione ha esito positivo. Se ha esito negativo, viene restituito un codice di errore HRESULT.

Commenti

Qualsiasi applicazione che usa Microsoft Defender Application Guard (MDAG) richiederà la possibilità di trovare l'ambiente di esecuzione in cui è in esecuzione. Questa operazione è necessaria in modo che l'app possa comportarsi in modo appropriato per proteggere i dati utente/aziendali, l'identità utente e gli interessi aziendali dell'app.

Esempio

Nell'esempio seguente viene illustrato come usare l'API IsProcessInIsolatedWindowsEnvironment per determinare l'ambiente di esecuzione dell'app.

#define PrintInfo wprintf

typedef HRESULT (*pIsProcessInIsolatedWindowsEnvironment)
                  (_Out_ BOOL *isProcessInIsolatedWindowsEnvironment);

int PrintError(unsigned int line, HRESULT hr)
{
  wprintf_s(L"ERROR: Line:%d HRESULT: 0x%X\n", line, hr);
  return hr;
}

HRESULT TakeActionAsPerExecutionEnvironment()
{
  //For instance the action could be saving changes to user settings for the app.
  //Lets assume the app has made a design decision to save change to user settings if
  //the app is running on the host, and discard the changes to user settings if they were
  //changed in an Isolated Environment.

  HMODULE dllInstance (LoadLibrary(L"IsolatedWindowsEnvironmentUtils.dll"));

  if (nullptr == dllInstance)
  {
    PrintInfo(L" Cannot load the library IsolatedWindowsEnvironmentUtils.dll \n");
    return E_FAIL;
  }

  auto pfn = reinterpret_cast<pIsProcessInIsolatedWindowsEnvironment>

  (GetProcAddress(dllInstance, "IsProcessInIsolatedWindowsEnvironment"));

  if (nullptr == pfn)
  {
    PrintInfo(L"Function definition IsProcessInIsolatedWindowsEnvironment() is not found.\n");
    FreeLibrary(dllInstance);
    return E_FAIL;
  }

  BOOL isInIsolatedWindowsEnvironment = FALSE;

  HRESULT hr = pfn(&isInIsolatedWindowsEnvironment);

  if (FAILED(hr))
  {
    FreeLibrary(dllInstance);
    return PrintError(__LINE__, hr);
  }

  if (isInIsolatedWindowsEnvironment == TRUE) //app is running in Isolated Environment
  {
    //do not save changes to the app’s user settings in this case
    PrintInfo(L"Discarding changes to app’s user settings.\n");

    //<TO-DO-Start>
    //Add app specific custom logic here
    //<TO-DO-End>
  }
  else
  {
    //Save changes to the app’s user settings in this case
    PrintInfo(L"Saving changes to app’s user settings.\n");

    //<TO-DO-Start>
    //Add app specific custom logic here
    //<TO-DO-End>
  }

  FreeLibrary(dllInstance);
  return S_OK;
}

Requisiti

Requisito Valore
Intestazione isolatowindowsenvironmentutils.h
DLL isolatedwindowsenvironmentutils.dll

Vedi anche

Panoramica di Microsoft Defender Application Guard

IsolatedWindowsEnvironment

IsolatedWindowsEnvironmentHost