コード例 #1
0
ファイル: uc_uninstall.cs プロジェクト: ExTEnS10N/BreakTime
        public static void Uninstall()
        {
            uc_timer.ShouldPauseTopMost = true;

            //删除计划任务
            TaskManager TaskDeletion = new TaskManager();
            TaskDeletion.DeleteLogonTask();
            TaskDeletion.DeleteScheduleTask();

            //删除配置文件
            string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string CompanyPath = applicationData.Substring(0, applicationData.LastIndexOf('\\') + 1)
                + "Local\\"
                + Application.CompanyName.Replace(' ', '_');
            if (Directory.Exists(CompanyPath))
            {
                string[] allAppSettingsPath = Directory.GetDirectories(CompanyPath);
                foreach (string AppSettings in allAppSettingsPath)
                {
                    if (AppSettings.Substring(AppSettings.LastIndexOf('\\') + 1)
                        .IndexOf(Application.ProductName) >= 0)
                    {
                        Directory.Delete(AppSettings, true);
                    }
                }
            }

            //删除自己
            StreamWriter UninstallStream = new StreamWriter(Path.GetTempPath() + "\\Uninstall.bat", false);
            UninstallStream.WriteLine("ping -n 2 127.0.0.1");
            UninstallStream.WriteLine("del /F/Q \""+ System.Windows.Forms.Application.ExecutablePath + "\"");
            UninstallStream.WriteLine("del /F/Q %0");
            UninstallStream.Close();
            Process CMD = new Process();
            CMD.StartInfo.FileName = "cmd.exe";
            CMD.StartInfo.UseShellExecute = false;
            CMD.StartInfo.CreateNoWindow = true;
            CMD.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            CMD.StartInfo.Arguments = "/c \"" + Path.GetTempPath() + "\\Uninstall.bat\"";
            CMD.Start();
            Application.Exit();
        }
コード例 #2
0
 public CommandLineTask()
 {
     string[] Arguments = Environment.GetCommandLineArgs();
     if (Arguments.Length > 1)
     {
         switch (Arguments[1])
         {
             case "-TaskManager":
                 {
                     TaskManager TM = new TaskManager();
                     if (Arguments.Length > 1)
                     {
                         switch (Arguments[2])
                         {
                             case "-DeleteScheduleTask":
                                 TM.DeleteScheduleTask();
                                 System.Windows.Forms.Application.Exit();
                                 break;
                             case "-DeleteLogonTask":
                                 TM.DeleteLogonTask();
                                 System.Windows.Forms.Application.Exit();
                                 break;
                             case "-AutoStart":
                                 {
                                     if (Properties.Settings.Default.AutoStart)
                                         TM.AutoRun();
                                     else
                                         TM.DeleteLogonTask();
                                     System.Windows.Forms.Application.Exit();
                                 }
                                 break;
                         }
                     }
                 }
                 break;
             case "-Uninstall":
                 uc_uninstall.Uninstall();
                 break;
         }
     }
 }