本文整理汇总了C#中RegistryKeyPermissionCheck类的典型用法代码示例。如果您正苦于以下问题:C# RegistryKeyPermissionCheck类的具体用法?C# RegistryKeyPermissionCheck怎么用?C# RegistryKeyPermissionCheck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegistryKeyPermissionCheck类属于命名空间,在下文中一共展示了RegistryKeyPermissionCheck类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenKey
internal static RegistryKey OpenKey( string key, RegistryKeyPermissionCheck permissionCheck )
{
var root = OpenRoot( key );
var path = key.Replace( root.Name, string.Empty ).Trim( '\\' );
if ( string.IsNullOrEmpty( path ) )
{
return root;
}
using ( root )
{
return root.CreateSubKey( path, permissionCheck );
}
}
示例2: CreateRegistrySubKey
/// <summary>
/// Function to create a new SubKey in the Windows Registry
/// </summary>
/// <param name="KeyPermissions">RegistryKepPermissionCheck -> Specifies permissions of the SubKey to be created</param>
/// <returns>True (Succeeded)/False (Failed)</returns>
/// <remarks>Created 22DEC07 -> Richard L. McCutchen</remarks>
public bool CreateRegistrySubKey(RegistryKeyPermissionCheck KeyPermissions)
{
try
{
MainKey.CreateSubKey(Key, KeyPermissions);
return true;
}
catch (Exception ex)
{
//since an exception occurred we need to let the user know
MessageBox.Show(ex.Message, "Error: Creating SubKey", MessageBoxButtons.OK, MessageBoxIcon.Error);
//set our success variable to false since it failed
return false;
}
//return the value to the calling method
return IsSuccessful;
}
示例3: OpenSubKey
public TransactedRegistryKey OpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights)
{
return InternalOpenSubKey(name, permissionCheck, (int)rights);
}
示例4: CreateSubKeyInternal
private unsafe TransactedRegistryKey CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj)
{
ValidateKeyName(subkey);
// RegCreateKeyTransacted requires a non-empty key name, so let's deal with that here.
if (string.Empty == subkey)
{
throw new ArgumentException(RegistryProviderStrings.Arg_RegKeyStrEmpty);
}
ValidateKeyMode(permissionCheck);
EnsureWriteable();
subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
// only keys opened under read mode is not writable
TransactedRegistryKey existingKey = InternalOpenSubKey(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
if (existingKey != null)
{ // Key already exits
CheckSubKeyWritePermission(subkey);
CheckSubTreePermission(subkey, permissionCheck);
existingKey._checkMode = permissionCheck;
return existingKey;
}
CheckSubKeyCreatePermission(subkey);
Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
TransactedRegistrySecurity registrySecurity = registrySecurityObj as TransactedRegistrySecurity;
// For ACL's, get the security descriptor from the RegistrySecurity.
if (registrySecurity != null)
{
secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);
byte[] sd = registrySecurity.GetSecurityDescriptorBinaryForm();
// We allocate memory on the stack to improve the speed.
// So this part of code can't be refactored into a method.
byte* pSecDescriptor = stackalloc byte[sd.Length];
Microsoft.PowerShell.Commands.Internal.Buffer.memcpy(sd, 0, pSecDescriptor, 0, sd.Length);
secAttrs.pSecurityDescriptor = pSecDescriptor;
}
int disposition = 0;
// By default, the new key will be writable.
SafeRegistryHandle result = null;
int ret = 0;
SafeTransactionHandle safeTransactionHandle = GetTransactionHandle();
ret = Win32Native.RegCreateKeyTransacted(_hkey,
subkey,
0,
null,
0,
GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree),
secAttrs,
out result,
out disposition,
safeTransactionHandle,
IntPtr.Zero
);
if (ret == 0 && !result.IsInvalid)
{
TransactedRegistryKey key = new TransactedRegistryKey(result, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree), false,
Transaction.Current, safeTransactionHandle);
CheckSubTreePermission(subkey, permissionCheck);
key._checkMode = permissionCheck;
if (subkey.Length == 0)
key._keyName = _keyName;
else
key._keyName = _keyName + "\\" + subkey;
return key;
}
else if (ret != 0) // syscall failed, ret is an error code.
Win32Error(ret, _keyName + "\\" + subkey); // Access denied?
BCLDebug.Assert(false, "Unexpected code path in RegistryKey::CreateSubKey");
return null;
}
示例5: CreateSubKey
public TransactedRegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck)
{
return CreateSubKeyInternal(subkey, permissionCheck, (TransactedRegistrySecurity)null);
}
示例6: GetRegistryKeyAccess
private static int GetRegistryKeyAccess(RegistryKeyPermissionCheck mode)
{
int winAccess = 0;
switch (mode)
{
case RegistryKeyPermissionCheck.ReadSubTree:
case RegistryKeyPermissionCheck.Default:
winAccess = Win32Native.KEY_READ;
break;
case RegistryKeyPermissionCheck.ReadWriteSubTree:
winAccess = Win32Native.KEY_READ | Win32Native.KEY_WRITE;
break;
default:
BCLDebug.Assert(false, "unexpected code path");
break;
}
return winAccess;
}
示例7: CheckOpenSubKeyPermission
private void CheckOpenSubKeyPermission(string subkeyName, RegistryKeyPermissionCheck subKeyCheck)
{
if (subKeyCheck == RegistryKeyPermissionCheck.Default)
{
if (_checkMode == RegistryKeyPermissionCheck.Default)
{
CheckSubKeyReadPermission(subkeyName);
}
}
CheckSubTreePermission(subkeyName, subKeyCheck);
}
示例8: CreateSubKey
public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions, System.Security.AccessControl.RegistrySecurity registrySecurity)
{
return default(RegistryKey);
}
示例9: GetKey
private RegistryKey GetKey( string sectionName, RegistryKeyPermissionCheck permissionCheck )
{
RegistryKey key;
if ( Root.Name.EndsWith( ( sectionName ) ) )
{
key = CloneKey( Root, permissionCheck );
}
else
{
string trimmed = sectionName.Replace( Root.Name, string.Empty ).Trim( '\\' );
key = Root.CreateSubKey( trimmed, permissionCheck );
}
return key;
}
示例10: CloneKey
internal static RegistryKey CloneKey( RegistryKey source, RegistryKeyPermissionCheck permissionCheck )
{
RegistryKey clone = OpenKey( source.Name, permissionCheck );
return clone;
}
示例11: InternalOpenSubKey
[System.Security.SecurityCritical] // auto-generated
private RegistryKey InternalOpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, int rights) {
ValidateKeyName(name);
ValidateKeyMode(permissionCheck);
ValidateKeyRights(rights);
EnsureNotDisposed();
name = FixupName(name); // Fixup multiple slashes to a single slash
CheckPermission(RegistryInternalCheck.CheckOpenSubKeyPermission, name, false, permissionCheck);
CheckPermission(RegistryInternalCheck.CheckSubTreePermission, name, false, permissionCheck);
SafeRegistryHandle result = null;
int ret = Win32Native.RegOpenKeyEx(hkey, name, 0, (rights | (int)regView), out result);
if (ret == 0 && !result.IsInvalid) {
RegistryKey key = new RegistryKey(result, (permissionCheck == RegistryKeyPermissionCheck.ReadWriteSubTree), false, remoteKey, false, regView);
key.keyName = keyName + "\\" + name;
key.checkMode = permissionCheck;
return key;
}
// Return null if we didn't find the key.
if (ret == Win32Native.ERROR_ACCESS_DENIED || ret == Win32Native.ERROR_BAD_IMPERSONATION_LEVEL) {
// We need to throw SecurityException here for compatiblity reason,
// although UnauthorizedAccessException will make more sense.
ThrowHelper.ThrowSecurityException(ExceptionResource.Security_RegistryPermission);
}
return null;
}
示例12: CreateSubKeyInternal
private unsafe RegistryKey CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj, RegistryOptions registryOptions)
{
ValidateKeyOptions(registryOptions);
ValidateKeyName(subkey);
ValidateKeyMode(permissionCheck);
EnsureWriteable();
subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
// only keys opened under read mode is not writable
if (!remoteKey) {
RegistryKey key = InternalOpenSubKey(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
if (key != null) { // Key already exits
CheckPermission(RegistryInternalCheck.CheckSubKeyWritePermission, subkey, false, RegistryKeyPermissionCheck.Default);
CheckPermission(RegistryInternalCheck.CheckSubTreePermission, subkey, false, permissionCheck);
key.checkMode = permissionCheck;
return key;
}
}
CheckPermission(RegistryInternalCheck.CheckSubKeyCreatePermission, subkey, false, RegistryKeyPermissionCheck.Default);
Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
#if FEATURE_MACL
RegistrySecurity registrySecurity = (RegistrySecurity)registrySecurityObj;
// For ACL's, get the security descriptor from the RegistrySecurity.
if (registrySecurity != null) {
secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);
byte[] sd = registrySecurity.GetSecurityDescriptorBinaryForm();
// We allocate memory on the stack to improve the speed.
// So this part of code can't be refactored into a method.
byte* pSecDescriptor = stackalloc byte[sd.Length];
Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
secAttrs.pSecurityDescriptor = pSecDescriptor;
}
#endif
int disposition = 0;
// By default, the new key will be writable.
SafeRegistryHandle result = null;
int ret = Win32Native.RegCreateKeyEx(hkey,
subkey,
0,
null,
(int)registryOptions /* specifies if the key is volatile */,
GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree) | (int)regView,
secAttrs,
out result,
out disposition);
if (ret == 0 && !result.IsInvalid) {
RegistryKey key = new RegistryKey(result, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree), false, remoteKey, false, regView);
CheckPermission(RegistryInternalCheck.CheckSubTreePermission, subkey, false, permissionCheck);
key.checkMode = permissionCheck;
if (subkey.Length == 0)
key.keyName = keyName;
else
key.keyName = keyName + "\\" + subkey;
return key;
}
else if (ret != 0) // syscall failed, ret is an error code.
Win32Error(ret, keyName + "\\" + subkey); // Access denied?
BCLDebug.Assert(false, "Unexpected code path in RegistryKey::CreateSubKey");
return null;
}
示例13: CreateSubKey
public unsafe RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions, RegistrySecurity registrySecurity)
{
return CreateSubKeyInternal(subkey, permissionCheck, registrySecurity, registryOptions);
}
示例14: ValidateKeyMode
static private void ValidateKeyMode(RegistryKeyPermissionCheck mode) {
if( mode < RegistryKeyPermissionCheck.Default || mode > RegistryKeyPermissionCheck.ReadWriteSubTree) {
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck, ExceptionArgument.mode);
}
}
示例15: OpenSubKey
public RegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck)
{
return default(RegistryKey);
}