.NETランタイムをアンマネージドプロセスでホストする必要があります。 COM経由でランタイムをロードするコードがあり、アセンブリをAppDomainにロードしてコードを正常に実行できます。ネットワーク権限を含む完全な信頼のアクセス許可を持つホストされたCLR AppDomainを作成する
しかし、ネットワーク共有でホストされているアプリケーションで問題が発生し、アプリケーションポリシーを変更して実行する必要がありますが、これはオプションではありません。だから私がしたいのは、ランタイムのメインAppDomainのアクセス権レベルを制限なしに設定することです。
誰かがAppDomainポリシーレベルを設定する方法の例を提供できますか?私は、ポリシーレベルとそれに関連するオブジェクトを作成し、ポリシーを設定するために、管理されていないコードから必要なクラスをインスタンス化する方法を理解できません。基本的には、私が使用するC++コードからこれを動作させるために必要な/名前空間参照を含むものがわかりません。
ここでは、この時点で私が持っているコードです:
/// Starts up the CLR and creates a Default AppDomain
DWORD WINAPI ClrLoad(char *ErrorMessage, DWORD *dwErrorSize)
{
if (spDefAppDomain)
return 1;
//Retrieve a pointer to the ICorRuntimeHost interface
HRESULT hr = CorBindToRuntimeEx(
ClrVersion, //Retrieve latest version by default
L"wks", //Request a WorkStation build of the CLR
STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | STARTUP_CONCURRENT_GC,
CLSID_CorRuntimeHost,
IID_ICorRuntimeHost,
(void**)&spRuntimeHost
);
if (FAILED(hr))
{
*dwErrorSize = SetError(hr,ErrorMessage);
return hr;
}
//Start the CLR
hr = spRuntimeHost->Start();
if (FAILED(hr))
return hr;
CComPtr<IUnknown> pUnk;
//Retrieve the IUnknown default AppDomain
//hr = spRuntimeHost->GetDefaultDomain(&pUnk);
//if (FAILED(hr))
// return hr;
WCHAR domainId[50];
swprintf(domainId,L"%s_%i",L"wwDotNetBridge",GetTickCount());
hr = spRuntimeHost->CreateDomain(domainId,NULL,&pUnk);
hr = pUnk->QueryInterface(&spDefAppDomain.p);
if (FAILED(hr))
return hr;
// // Create a new AppDomain PolicyLevel.
//PolicyLevel polLevel = PolicyLevel:: CreateAppDomainLevel();
//// Create a new, empty permission set.
// PermissionSet permSet = gcnew PermissionSet(PermissionState::Unrestricted);
//// Add permission to execute code to the permission set.
//permSet->AddPermission(gcnew SecurityPermission(SecurityPermissionFlag::Execution));
////// Give the policy level's root code group a new policy statement based
////// on the new permission set.
////polLevel->RootCodeGroup->PolicyStatement = gcnew PolicyStatement(permSet);
//// Give the new policy level to the application domain.
//spDefAppdomain->SetAppDomainPolicy(polLevel);
return 1;
}
私はそれが必要なものをやるように見えるいくつかのサンプルコード(コメント)を拾ったが、私は/ libには含まかを把握することはできませんが、私はPermissionSetとPolicyLevelの型参照をする必要があります。
感謝任意のアイデア...
私はあなたがICLRControlが必要だと思う:: SetAppDomainManagerType()カスタムのAppDomainマネージャを設定します。私が見つけた最良のリンクはhttp://blogs.msdn.com/b/dparys/archive/2007/07/20/common-language-runtime-hosting.aspx –
@Rickでした。あなたはこれに対して良い解決策を手に入れましたか? –