IsProcessInIsolatedWindowsEnvironment 函式 (isolatedwindowsenvironmentutils.h)
決定應用程式執行所在的執行環境 – 主機或隔離的環境。
語法
HRESULT IsProcessInIsolatedWindowsEnvironment(
BOOL *isProcessInIsolatedWindowsEnvironment
);
參數
isProcessInIsolatedWindowsEnvironment
[out]
接收 API 結果之布爾值的指標。 如果行程位於隔離的 Windows 環境中,這個參數將會 true
是 , false
否則為 。
傳回值
S_OK
如果函式成功,則傳回 。 如果方法失敗,則會傳回 HRESULT
錯誤碼。
備註
任何使用 #D82A75EE833C241079F071CE88AFDFD88 (MDAG) 的應用程式,都需要能夠尋找執行所在的執行環境。 這是必要的,應用程式可以適當地運作,以保護使用者/企業數據、使用者身分識別,以及應用程式的商業興趣。
範例
下列範例示範如何使用 IsProcessInIsolatedWindowsEnvironment
API 來判斷應用程式的執行環境。
#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 |