public RegistryKey CreateRegKey(string regKeyName = "") { if (string.IsNullOrEmpty(regKeyName)) { regKeyName = _regKey; } else { regKeyName = $"{this._regKey}\\{regKeyName}"; } // creazione chiave _baseKey?.CreateSubKey(regKeyName ?? "", RegistryKeyPermissionCheck.ReadWriteSubTree)?.Close(); // apertura con permessi per modifica permesssi RegistryKey key = _baseKey?.OpenSubKey( regKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey | RegistryRights.WriteKey | RegistryRights.FullControl ); // permessi da applicare RegistryRights acl = RegistryRights.WriteKey | RegistryRights.ReadKey | RegistryRights.Delete; // attuale policy if (EnvironmentUtils.IsWin()) { try { RegistrySecurity regSec = key?.GetAccessControl(); // aggiunta policy all'attuale regSec?.AddAccessRule( new RegistryAccessRule( $"{Environment.UserDomainName}\\{Environment.UserName}", acl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow ) ); // definizione proprietario regSec?.SetOwner(new NTAccount($"{Environment.UserDomainName}\\{Environment.UserName}")); // applicazione della policy key?.SetAccessControl(regSec); } catch { // ignore } } return(key); }
public static string RelativePath(string folderpath, string filePath) { // rimuove la directory dal percorso string fullFilePath = Path.GetFullPath(filePath); string fullFolderPath = Path.GetFullPath(folderpath); filePath = fullFilePath.Replace(fullFolderPath, string.Empty); // converte il path in formato unix if (EnvironmentUtils.IsWin()) { filePath = filePath.Replace('\\', '/'); } // rimuove il sepratatore dall'inizio del percorso filePath = filePath.TrimStart('/'); return(filePath); }