public void AclUser() { var account = new System.Security.Principal.NTAccount(Environment.UserName); Assert.That(account.ToString().Contains(Environment.UserName)); Assert.That(account.IsValidTargetType(typeof(System.Security.Principal.SecurityIdentifier))); var securityAccount = account.Translate(typeof(System.Security.Principal.SecurityIdentifier)) as System.Security.Principal.SecurityIdentifier; Assert.That(securityAccount.IsAccountSid(), Is.True); }
static void Main(string[] args) { DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\"); Debug.WriteLine("Directories in C drive:"); foreach (DirectoryInfo di in directoryInfo.GetDirectories()) { Debug.WriteLine(di.Name); } //Criar diretorios var directory = Directory.CreateDirectory(@"C:\Temp2\Directory"); var directoryCreate = new DirectoryInfo(@"C:\Temp2\DirectoryInfo"); directoryCreate.Create(); //Deletar /*if (Directory.Exists(@"C:\Temp2\Directory")) * { * Console.WriteLine("Deletando pasta 'C:\\Temp2\\Directory'"); * Directory.Delete(@"C:\Temp2\Directory"); * } * * if (directoryCreate.Exists) * { * directoryCreate.Delete(); * }*/ System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null); System.Security.Principal.NTAccount acct = sid.Translate(typeof(System.Security.Principal.NTAccount)) as System.Security.Principal.NTAccount; string strEveryoneAccount = acct.ToString(); //Controle de acesso as pastas //No caso abaixo não permitir a deleção de uma determinada pasta por um determinado usuario DirectorySecurity directorySecurity = directoryInfo.GetAccessControl(); directorySecurity.AddAccessRule(new FileSystemAccessRule(@"DESKTOP\FulanoX", FileSystemRights.Delete, AccessControlType.Deny)); directoryCreate.SetAccessControl(directorySecurity); Console.ReadLine(); }
private static void Main() { string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1 && args[1] == "-setpermissions") { System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null); System.Security.Principal.NTAccount acct = sid.Translate(typeof(System.Security.Principal.NTAccount)) as System.Security.Principal.NTAccount; string strEveryoneAccount = acct.ToString(); GeneralHelper.AddDirectorySecurity(".\\", strEveryoneAccount, FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.NoPropagateInherit, AccessControlType.Allow); GeneralHelper.AddDirectorySecurity(".\\", strEveryoneAccount, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); GeneralHelper.RemoveReadOnlyRecursive(".\\"); return; } string name = Path.GetFileNameWithoutExtension(Application.ExecutablePath); bool moved = false; #if DEBUG bool firstInstance = true; #else bool firstInstance = Process.GetProcessesByName(name).Length < 2; #endif string file = ""; if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { file += args[i] + " "; } file = file.Trim(); moved = true; } if (!firstInstance) { Thread.Sleep(1500); firstInstance = Process.GetProcessesByName(name).Length < 2; if (!firstInstance && !moved) { if (DialogResult.OK == MessageBox.Show("osu! is already running!\nWould you like to force-kill the other copy?", name, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)) { KillStuckProcesses(name); int count = 0; while (count++ < 20 && !firstInstance) { Thread.Sleep(100); firstInstance = Process.GetProcessesByName(name).Length < 2; } if (!firstInstance) { MessageBox.Show("Killing failed. Please manually kill the process using Task Manager.", name, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } } else { return; } } } if (moved || firstInstance) { if (firstInstance) { try { IPC.AcceptConnections(); } catch (Exception) { } } else { try { TcpClient c = new TcpClient("localhost", 13373); StreamWriter w = new StreamWriter(c.GetStream()); w.WriteLine(file); w.Flush(); c.Close(); } catch (Exception) { } return; } } Environment.CurrentDirectory = Application.StartupPath; using (GameBase game = new GameBase(file)) { if (File.Exists("_osume.exe")) { File.Delete("osume.exe"); File.Move("_osume.exe", "osume.exe"); GeneralHelper.ProcessStart("osume.exe"); } else #if !DEBUG { try { #endif game.Run(); } if (Restart) { GeneralHelper.ProcessStart("osu!.exe"); } #if !DEBUG }