Share via


IsProcessInIsolatedWindowsEnvironment 함수(isolatedwindowsenvironmentutils.h)

애플리케이션이 실행 중인 실행 환경(호스트 또는 격리된 환경)을 결정합니다.

구문

HRESULT IsProcessInIsolatedWindowsEnvironment(
  BOOL *isProcessInIsolatedWindowsEnvironment
);

매개 변수

isProcessInIsolatedWindowsEnvironment

[out]

API의 결과를 수신하는 부울 값에 대한 포인터입니다. 이 매개 변수는 true 프로세스가 격리된 Windows 환경에 있는 경우 이고, false 그렇지 않으면 입니다.

반환 값

함수가 성공하면 를 반환 S_OK 합니다. 그렇지 않으면 HRESULT 오류 코드가 반환됩니다.

설명

MDAG(Microsoft Defender Application Guard)를 사용하는 모든 애플리케이션에는 실행 중인 실행 환경을 찾는 기능이 필요합니다. 앱이 사용자/엔터프라이즈 데이터, 사용자 ID 및 앱의 비즈니스 이익을 보호하기 위해 적절하게 동작할 수 있도록 이 작업이 필요합니다.

예제

다음 예제에서는 API를 IsProcessInIsolatedWindowsEnvironment 사용하여 앱의 실행 환경을 확인하는 방법을 보여 줍니다.

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

요구 사항

요구 사항
헤더 isolatedwindowsenvironmentutils.h
DLL isolatedwindowsenvironmentutils.dll

추가 정보

Microsoft Defender Application Guard 개요

IsolatedWindowsEnvironment

IsolatedWindowsEnvironmentHost