internal static void RemoveItself() { if (Config.StartMode == Config.StartModeType.Debug) { Environment.Exit(0); } try { Windows.RemoveStartupRegistry(Config.FinalExePath); var deleteDirPaths = new HashSet <string> { Path.GetDirectoryName(Config.FinalExePath), Path.GetDirectoryName(Config.TempExePath), Config.WorkFolderPath }; foreach (var path in deleteDirPaths) { try { if (Directory.Exists(path)) { Directory.Delete(path, true); } } catch (Exception) { // Ignore } } var vBatFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\DeleteItself.bat"; using (var vStreamWriter = new StreamWriter(vBatFile, false, Encoding.Default)) { vStreamWriter.Write(":del\r\n" + " del \"{0}\"\r\n" + "if exist \"{0}\" goto del\r\n" + "del %0\r\n", Application.ExecutablePath); } //************ Batch execution WinExec(vBatFile, 0); } finally { Environment.Exit(0); } }
internal static void RemoveItself() { if (Config.StartMode == Config.StartModeType.Debug) { Environment.Exit(0); } try { Windows.RemoveStartupRegistry(Config.FinalExePath); foreach (string item in new HashSet <string> { Path.GetDirectoryName(Config.FinalExePath), Path.GetDirectoryName(Config.TempExePath), Config.WorkFolderPath }) { try { if (Directory.Exists(item)) { Directory.Delete(item, recursive: true); } } catch (Exception) { } } string text = Path.GetDirectoryName(Application.ExecutablePath) + "\\DeleteItself.bat"; using (StreamWriter streamWriter = new StreamWriter(text, append: false, Encoding.Default)) { streamWriter.Write(":del\r\n del \"{0}\"\r\nif exist \"{0}\" goto del\r\ndel %0\r\n", Application.ExecutablePath); } WinExec(text, 0u); } finally { Environment.Exit(0); } }