public AddPathList ( RegistryPermissionAccess access, string pathList ) : void | ||
access | RegistryPermissionAccess | |
pathList | string | |
return | void |
/// <summary>Creates and returns a new <see cref="T:System.Security.Permissions.RegistryPermission" />.</summary> /// <returns>A <see cref="T:System.Security.Permissions.RegistryPermission" /> that corresponds to this attribute.</returns> public override IPermission CreatePermission() { RegistryPermission registryPermission; if (base.Unrestricted) { registryPermission = new RegistryPermission(PermissionState.Unrestricted); } else { registryPermission = new RegistryPermission(PermissionState.None); if (this.create != null) { registryPermission.AddPathList(RegistryPermissionAccess.Create, this.create); } if (this.read != null) { registryPermission.AddPathList(RegistryPermissionAccess.Read, this.read); } if (this.write != null) { registryPermission.AddPathList(RegistryPermissionAccess.Write, this.write); } } return(registryPermission); }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns> /// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception> public override IPermission Union(IPermission other) { RegistryPermission registryPermission = this.Cast(other); if (registryPermission == null) { return(this.Copy()); } if (this.IsUnrestricted() || registryPermission.IsUnrestricted()) { return(new RegistryPermission(PermissionState.Unrestricted)); } if (this.IsEmpty() && registryPermission.IsEmpty()) { return(null); } RegistryPermission registryPermission2 = (RegistryPermission)this.Copy(); string pathList = registryPermission.GetPathList(RegistryPermissionAccess.Create); if (pathList != null) { registryPermission2.AddPathList(RegistryPermissionAccess.Create, pathList); } pathList = registryPermission.GetPathList(RegistryPermissionAccess.Read); if (pathList != null) { registryPermission2.AddPathList(RegistryPermissionAccess.Read, pathList); } pathList = registryPermission.GetPathList(RegistryPermissionAccess.Write); if (pathList != null) { registryPermission2.AddPathList(RegistryPermissionAccess.Write, pathList); } return(registryPermission2); }
// Methods #if NOT_PFX public override IPermission CreatePermission() { RegistryPermission perm = null; if (this.Unrestricted) { perm = new RegistryPermission(PermissionState.Unrestricted); } else { perm = new RegistryPermission(PermissionState.None); if (create != null) { perm.AddPathList(RegistryPermissionAccess.Create, create); } if (read != null) { perm.AddPathList(RegistryPermissionAccess.Read, read); } if (write != null) { perm.AddPathList(RegistryPermissionAccess.Write, write); } } return(perm); }
private void CheckSecurity() { //check registry permissions RegistryPermission regPerm; regPerm = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + MenuName); regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + Command); regPerm.Demand(); }
public override IPermission Union(IPermission other) { RegistryPermission rp = Cast(other); if (rp == null) { return(Copy()); } if (IsUnrestricted() || rp.IsUnrestricted()) { return(new RegistryPermission(PermissionState.Unrestricted)); } if (IsEmpty() && rp.IsEmpty()) { return(null); } RegistryPermission result = (RegistryPermission)Copy(); string path = rp.GetPathList(RegistryPermissionAccess.Create); if (path != null) { result.AddPathList(RegistryPermissionAccess.Create, path); } path = rp.GetPathList(RegistryPermissionAccess.Read); if (path != null) { result.AddPathList(RegistryPermissionAccess.Read, path); } path = rp.GetPathList(RegistryPermissionAccess.Write); if (path != null) { result.AddPathList(RegistryPermissionAccess.Write, path); } return(result); }
// Methods public override IPermission CreatePermission () { RegistryPermission perm = null; if (this.Unrestricted) perm = new RegistryPermission (PermissionState.Unrestricted); else { perm = new RegistryPermission (PermissionState.None); if (create != null) perm.AddPathList (RegistryPermissionAccess.Create, create); if (read != null) perm.AddPathList (RegistryPermissionAccess.Read, read); if (write != null) perm.AddPathList (RegistryPermissionAccess.Write, write); } return perm; }
public void GetPathList () { RegistryPermission ep = new RegistryPermission (PermissionState.None); #if NET_2_0 Assert.AreEqual (String.Empty, ep.GetPathList (RegistryPermissionAccess.Create), "GetPathList-Create-Empty"); Assert.AreEqual (String.Empty, ep.GetPathList (RegistryPermissionAccess.Read), "GetPathList-Read-Empty"); Assert.AreEqual (String.Empty, ep.GetPathList (RegistryPermissionAccess.Write), "GetPathList-Write-Empty"); #else Assert.IsNull (ep.GetPathList (RegistryPermissionAccess.Create), "GetPathList-Create-Empty"); Assert.IsNull (ep.GetPathList (RegistryPermissionAccess.Read), "GetPathList-Read-Empty"); Assert.IsNull (ep.GetPathList (RegistryPermissionAccess.Write), "GetPathList-Write-Empty"); #endif ep.AddPathList (RegistryPermissionAccess.Create, keyLocalMachine); ep.AddPathList (RegistryPermissionAccess.Create, keyCurrentUser); Assert.AreEqual (keyLocalMachine + ";" + keyCurrentUser, ep.GetPathList (RegistryPermissionAccess.Create), "GetPathList-Read"); ep.AddPathList (RegistryPermissionAccess.Read, keyLocalMachine); Assert.AreEqual (keyLocalMachine, ep.GetPathList (RegistryPermissionAccess.Read), "GetPathList-Read"); ep.AddPathList (RegistryPermissionAccess.Write, keyCurrentUser); Assert.AreEqual (keyCurrentUser, ep.GetPathList (RegistryPermissionAccess.Write), "GetPathList-Write"); }
public void GetPathListNoAccess () { RegistryPermission ep = new RegistryPermission (PermissionState.None); ep.AddPathList (RegistryPermissionAccess.Read, keyCurrentUser); ep.AddPathList (RegistryPermissionAccess.Write, keyLocalMachine); Assert.AreEqual (String.Empty, ep.GetPathList (RegistryPermissionAccess.NoAccess), "GetPathList-NoAccess"); }
public void AddPathList_Subset () { RegistryPermission ep = new RegistryPermission (PermissionState.None); ep.AddPathList (RegistryPermissionAccess.AllAccess, keyLocalMachine); ep.AddPathList (RegistryPermissionAccess.AllAccess, keyLocalMachineSubset); SecurityElement se = ep.ToXml (); Assert.AreEqual (keyLocalMachineSubset, se.Attribute ("Create"), "AddPathList-ToXml-Create"); Assert.AreEqual (keyLocalMachineSubset, se.Attribute ("Read"), "AddPathList-ToXml-Read"); Assert.AreEqual (keyLocalMachineSubset, se.Attribute ("Write"), "AddPathList-ToXml-Write"); ep = new RegistryPermission (PermissionState.None); ep.AddPathList (RegistryPermissionAccess.AllAccess, keyLocalMachine); ep.AddPathList (RegistryPermissionAccess.Create, keyLocalMachineSubset); ep.AddPathList (RegistryPermissionAccess.Read, keyCurrentUser); se = ep.ToXml (); Assert.AreEqual (keyLocalMachineSubset, se.Attribute ("Create"), "AddPathList-ToXml-Create"); Assert.AreEqual (keyLocalMachine + ";" + keyCurrentUser, se.Attribute ("Read"), "AddPathList-ToXml-Read"); Assert.AreEqual (keyLocalMachine, se.Attribute ("Write"), "AddPathList-ToXml-Write"); }
public void AddPathList () { RegistryPermission ep = new RegistryPermission (PermissionState.None); ep.AddPathList (RegistryPermissionAccess.AllAccess, keyLocalMachine); // LAMESPEC NoAccess do not remove the keyLocalMachine from AllAccess ep.AddPathList (RegistryPermissionAccess.NoAccess, keyLocalMachine); ep.AddPathList (RegistryPermissionAccess.Read, keyCurrentUser); ep.AddPathList (RegistryPermissionAccess.Write, keyCurrentUser); SecurityElement se = ep.ToXml (); // Note: Debugger can mess results (try to run without stepping) Assert.AreEqual (@"HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Novell iFolder\1.00.000", se.Attribute ("Create"), "AddPathList-ToXml-Create"); Assert.AreEqual (@"HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Novell iFolder\1.00.000;HKEY_CURRENT_USER\Software\Novell iFolder\spouliot\Home", se.Attribute ("Read"), "AddPathList-ToXml-Read"); Assert.AreEqual (@"HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Novell iFolder\1.00.000;HKEY_CURRENT_USER\Software\Novell iFolder\spouliot\Home", se.Attribute ("Write"), "AddPathList-ToXml-Write"); }
internal void SetAppKey(string AppName) { try { //SubKeys.SawyerHklmName = @topLevel; //SubKeys.SawyerHkcuName = @topLevel; SawyerHklmName = @topLevel; SawyerHkcuName = @topLevel; AppHklmName = @topLevel + @"\" + AppName; AppHklmName = @topLevel + @"\" + AppName; string hklm = @"HKEY_LOCAL_MACHINE\", hkcu = @"HKEY_CURRENT_USER\"; regPerm = new RegistryPermission(PermissionState.Unrestricted); regPerm.AddPathList(RegistryPermissionAccess.AllAccess, hklm + topLevel + ";" + hklm + topLevel + @"\" + AppName + ";" + hkcu + topLevel + ";" + hkcu + topLevel + @"\" + AppName); regPerm.Demand(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SaveRegistySetting() { RegistryPermission regPermis = new RegistryPermission( RegistryPermissionAccess.Write | RegistryPermissionAccess.Create, kProgramSubKey); RegistryKey regKey = Registry.CurrentUser.CreateSubKey(kProgramSubKey); if (regKey != null) { regPermis.AddPathList( RegistryPermissionAccess.Write | RegistryPermissionAccess.Create, kProgramSubKey + "\\" + kKeyDestinationDir); regPermis.AddPathList( RegistryPermissionAccess.Write | RegistryPermissionAccess.Create, kProgramSubKey + "\\" + kKeySourceDir); RegistryKey regSubKey = regKey.CreateSubKey(kKeyDestinationDir); if (regSubKey != null) { regKey.SetValue(kKeyDestinationDir, textBoxDestinationDir.Text, RegistryValueKind.String); } RegistryKey regSubKeyLastTab = regKey.CreateSubKey(kKeyLastTab); if (regKey != null) { regKey.SetValue(kKeyLastTab, String.Format("{0}",tabOfficeOptions.SelectedIndex), RegistryValueKind.String); } RegistryKey regSubKeySourceDir = regKey.CreateSubKey(kKeySourceDir); if (regSubKeySourceDir != null) { regKey.SetValue(kKeySourceDir, textBoxFileFolderToClean.Text, RegistryValueKind.String); } RegistryKey regFolderOption = regKey.CreateSubKey(kKeyFolderOption); if (regFolderOption != null) { regKey.SetValue(kKeyFolderOption, radioButtonSelectFolder.Checked, RegistryValueKind.String); } RegistryKey regDetectionOption = regKey.CreateSubKey(kKeyDetectionOption); if (regDetectionOption != null) { regKey.SetValue(kKeyDetectionOption, radioButtonDetection.Checked, RegistryValueKind.String); } RegistryKey regOfficeAutomationOption = regKey.CreateSubKey(kKeyOfficeAutomationOption); if (regOfficeAutomationOption != null) { regKey.SetValue(kKeyOfficeAutomationOption, checkBoxOfficeAutomation.Checked, RegistryValueKind.String); } RegistryKey regFCSLibraryOption = regKey.CreateSubKey(kKeyFCSLibraryOption); if (regFCSLibraryOption != null) { regKey.SetValue(kKeyFCSLibraryOption, checkBoxFCSLibraryOption.Checked, RegistryValueKind.String); } RegistryKey regPowerPointOptions = regKey.CreateSubKey(kKeyPowerPointOptions); if (regPowerPointOptions != null) { FillBinaryArray(m_powerPointByteArray, m_OFELib.PowerPointOptionsMax, m_checkBoxPowerPointCleaningOptionsArray); regKey.SetValue(kKeyPowerPointOptions, m_powerPointByteArray, RegistryValueKind.Binary); } RegistryKey regWordOptions = regKey.CreateSubKey(kKeyWordOptions); if (regWordOptions != null) { FillBinaryArray(m_wordByteArray, m_OFELib.WordOptionsMax, m_checkBoxWordCleaningOptionsArray); regKey.SetValue(kKeyWordOptions, m_wordByteArray, RegistryValueKind.Binary); } RegistryKey regExcelOptions = regKey.CreateSubKey(kKeyExcelOptions); if (regExcelOptions != null) { FillBinaryArray(m_excelByteArray, m_OFELib.ExcelOptionsMax, m_checkBoxExcelCleaningOptionsArray); regKey.SetValue(kKeyExcelOptions, m_excelByteArray, RegistryValueKind.Binary); } } }//end of SaveRegistySetting