设为首页 加入收藏

TOP

visual studio installer 卸载时不能删除安装目录问题
2017-10-11 18:26:02 】 浏览:6762
Tags:visual studio installer 卸载 不能 删除 安装 目录 问题

 

在vs中可以制作安装程序,但是这个安装程序默认卸载的时候不会把安装目录卸载,如果想在卸载的时候删除这个目录,那就要费点周折了。此方法同时适应于程序自删除以及工作目录删除。

基本思路是在程序要退出的时候启动一个脚本,该脚本会做好善后工作,删除所有不必要的东西。注意这个脚本应该是在程序完全退出以后再去删工作目录。

直接贴代码了,思路也很简单,主要是通过一个ping来进行延时,保证程序退出以后再删。

protected override void OnAfterUninstall(IDictionary savedState)

{

Assembly asm = Assembly.GetExecutingAssembly();

string path = asm.Location.Remove(asm.Location.LastIndexOf("\\"));

DeleteAllSelf(path);

static void DeleteAllSelf(string path)

{

System.IO.Directory.SetCurrentDirectory("c:\\");

string fileName = Path.Combine("c:\\", "remove.bat");

StreamWriter bat = new StreamWriter(fileName, false, Encoding.Default);

bat.WriteLine("ping 127.0.0.1 -n 7 > nul"); //此处的延时非常必要,,保证删目录的时候程序已经完全退出了!

bat.WriteLine(string.Format("rd \"{0}\" /q /s", path));

bat.WriteLine(string.Format("del \"{0}\" /q", fileName));

 

bat.Close();

ProcessStartInfo info = new ProcessStartInfo(fileName);

info.WorkingDirectory = "c:\\";

info.WindowStyle = ProcessWindowStyle.Hidden;

Process.Start(info);

}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇GHOST WIN7系统64位经典优化版 V2.. 下一篇windows 10 & Office 2016 安装

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目