主要是使用bat批處理命令,話不多說,代碼說事
private void DeleteUnInstallself()
{
string batDelFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\delself.bat";
using (StreamWriter sw = new StreamWriter(batDelFile, false, Encoding.Default))
{
sw.Write(string.Format(
":del\r\n" +
" del \"{0}\"\r\n" +
"if exist \"{0}\" goto del\r\n" +
"del %0\r\n", Application.ExecutablePath));
}
//************ 執行批處理
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = batDelFile;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
//************ 結束退出
Close();
}
主要是方便卸載程序在卸載完成之後,可以把自己也幹掉,正所謂十步殺一人,千里不留行!