Материал из .Net Framework эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Set Security
#include "stdafx.h"
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Policy;
void main(){
PermissionSet^ permSet = gcnew PermissionSet(PermissionState::None);
permSet->AddPermission(gcnew SecurityPermission(PermissionState::Unrestricted));
permSet->AddPermission(gcnew UIPermission(PermissionState::Unrestricted));
permSet->AddPermission(gcnew FileIOPermission(FileIOPermissionAccess::Read,"C:\\Test"));
PolicyStatement^ policy = gcnew PolicyStatement(permSet);
IMembershipCondition^ membership = gcnew UrlMembershipCondition("http://192.168.1.1/*");
CodeGroup^ codeGroup = gcnew UnionCodeGroup(membership, policy);
codeGroup->Description = "C:\\";
codeGroup->Name = "ReadOnly Secure Group";
System::Collections::IEnumerator^ ph = SecurityManager::PolicyHierarchy();
while( ph->MoveNext() )
{
PolicyLevel^ pl = (PolicyLevel^)ph->Current;
if( pl->Label == "Machine" )
{
// Add code group to Machine policy
pl->RootCodeGroup->AddChild(codeGroup);
break;
}
}
SecurityManager::SavePolicy();
}