Freigeben über


IsProcessInIsolatedWindowsEnvironment-Funktion (isolatedwindowsenvironmentutils.h)

Bestimmt, in welcher Ausführungsumgebung die Anwendung ausgeführt wird – ein Host oder eine isolierte Umgebung.

Syntax

HRESULT IsProcessInIsolatedWindowsEnvironment(
  BOOL *isProcessInIsolatedWindowsEnvironment
);

Parameter

isProcessInIsolatedWindowsEnvironment

[out]

Ein Zeiger auf einen booleschen Wert, der das Ergebnis der API empfängt. Dieser Parameter ist true , wenn sich der Prozess in einer isolierten Windows-Umgebung befindet, false andernfalls.

Rückgabewert

Gibt zurück S_OK , wenn die Funktion erfolgreich ist. Bei einem Fehler wird ein HRESULT-Fehlercode zurückgegeben.

Hinweise

Jede Anwendung, die Microsoft Defender Application Guard (MDAG) verwendet, erfordert die Möglichkeit, die Ausführungsumgebung zu ermitteln, in der sie ausgeführt wird. Dies ist erforderlich, damit sich die App angemessen verhalten kann, um Benutzer-/Unternehmensdaten, Benutzeridentität und die Geschäftsinteressen der App zu schützen.

Beispiele

Das folgende Beispiel zeigt, wie Sie die IsProcessInIsolatedWindowsEnvironment API verwenden, um die Ausführungsumgebung der App zu bestimmen.

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

Anforderungen

Anforderung Wert
Header isolatedwindowsenvironmentutils.h
DLL isolatedwindowsenvironmentutils.dll

Weitere Informationen

Übersicht über Microsoft Defender Application Guard

IsolatedWindowsEnvironment

IsolatedWindowsEnvironmentHost