您的位置:首页 > 编程语言 > C语言/C++

C++.net做的卸载程序删除不了安装目录下的文件夹!!====救命啊!

2007-09-05 18:13 399 查看
C++.net做的卸载程序删除不了安装目录下的文件夹
做法如下:
打包时加入卸载功能:
1.在打包项目中添加文件msiexec.exe(一般可在c:/windows/system32/下找到)
2.在文件系统视图中选择应用程序文件夹,在msiexec.exe上按右键,选择创建快捷方式,重命名快捷方式为"卸载".
3.更改此快捷方式的arguments属性设为:"/x {产品id}",其中{产品id}的值为打包项目的ProductCode属性值.
应用程序是删除了,可文件夹还在,怎样才能删除啊!
办法1:
DelFile()
{
    Type^ type = System::Object::typeid;
    String^ path = type->Assembly->Location;
     Directory::Delete(path, true);
}
在Uninstall工程里又加了以上函数,可以删除文件夹,可是打包后运行Uninstall.exe就不报错,需要关闭Uninstall.exe(这不是让程序卸载后还用自己删自己吗!~!)
办法2:
virtual void OnAfterUninstall(IDictionary^ SavedState) override
        {
            Installer::OnAfterUninstall(SavedState);

            // Del file
            Type^ type = System::Object::typeid;
            String^ path = type->Assembly->Location;
            try {
                // Determine whether the directory exists.
                if (!Directory::Exists(path)) {
                    // Create the directory.
                    Directory::CreateDirectory(path);
                }
                // This will succeed because subdirectories are being deleted.
                Directory::Delete(path, true);

                }catch(Exception^ e){
                Console::WriteLine(L"The process failed: {0}", e);
                }
           }
重载了这个函数,程序也进来了,可是还是报异常,请问有人解决这个问题的吗????!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐