Partager via


IsProcessInIsolatedWindowsEnvironment, fonction (isolatedwindowsenvironmentutils.h)

Détermine dans quel environnement d’exécution l’application est en cours d’exécution : un hôte ou un environnement isolé.

Syntaxe

HRESULT IsProcessInIsolatedWindowsEnvironment(
  BOOL *isProcessInIsolatedWindowsEnvironment
);

Paramètres

isProcessInIsolatedWindowsEnvironment

[out]

Pointeur vers une valeur booléenne qui reçoit le résultat de l’API. Ce paramètre sera true si le processus se trouve dans un environnement Windows isolé, false sinon.

Valeur retournée

Retourne S_OK si la fonction réussit. En cas d’échec, il retourne un code d’erreur HRESULT .

Remarques

Toute application utilisant Microsoft Defender Application Guard (MDAG) nécessite la possibilité de trouver l’environnement d’exécution dans lequel il s’exécute. Cela est nécessaire pour que l’application puisse se comporter de manière appropriée pour protéger les données utilisateur/entreprise, l’identité de l’utilisateur et les intérêts commerciaux de l’application.

Examples

L’exemple suivant montre comment utiliser l’API IsProcessInIsolatedWindowsEnvironment pour déterminer l’environnement d’exécution de l’application.

#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;
}

Spécifications

Requirement Valeur
Header isolatedwindowsenvironmentutils.h
Library IsolatedWindowsEnvironmentUtils.lib
DLL isolatedwindowsenvironmentutils.dll

Voir aussi

Microsoft Defender Application Guard vue d’ensemble

IsolatedWindowsEnvironment

IsolatedWindowsEnvironmentHost