C#程序自杀 程序删除自己
2016-04-29 17:03
423 查看
主要是使用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();
}
主要是方便卸载程序在卸载完成之后,可以把自己也干掉,正所谓十步杀一人,千里不留行!
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();
}
主要是方便卸载程序在卸载完成之后,可以把自己也干掉,正所谓十步杀一人,千里不留行!
相关文章推荐
- 让Python文件也可以当bat文件运行
- c#调用COM组件
- 用批处理删除注册表健值的方法分享
- cmd批处理转义字符%的详细解释
- 通过批处理调用SQL的方法(osql)
- 将批处理文件注册成服务在系统启动的时候自动调用
- C#实现把指定数据写入串口
- C#动态创建button的方法
- 用批处理实现读取文本文件并实现超链接代码的输出[原创]_DOS/BAT_脚本之家
- 用批处理解决数学问题的代码第1/4页
- 如何让批处理程序启动的时候最小化
- 利用批处理结合winrar轻松压缩文件
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现给图片加水印的方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#中的delegate委托类型基本学习教程
- C#实现子窗体与父窗体通信方法实例总结