卸载时强制删除 user.config?

发布于 2024-11-24 03:55:24 字数 49 浏览 1 评论 0原文

如何在卸载过程中编写自定义操作的代码? 需要批处理文件吗?

谢谢!

how do i code the custom action during the uninstall?
Would it require a batch file?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

仲春光 2024-12-01 03:55:24

user.config 数据存储在 %APPDATA%\ProjectName 文件夹中。

如果您想在卸载时删除 user.config 数据,则可以使用 System.IO.Directory.Delete("%APPDATA%\ProjectName");

注意:您可以获取已安装的使用以下 Context.Parameters["assemblepath"] 这是用户选择安装项目的路径。

The user.config data gets stored in the %APPDATA%\ProjectName folder.

If you want to remove the user.config data when you uninstall then you can just use the System.IO.Directory.Delete("%APPDATA%\ProjectName");

Note: You can get the installed path using the following Context.Parameters["assemblypath"] this is the path that the user selects to install the project.

相对绾红妆 2024-12-01 03:55:24

根据上面的答案,这对我有用。对于我的应用程序,我只允许每个用户安装,而不是“所有用户”,因此我不必担心多个用户或当前运行卸载之外的用户的卸载。如果您允许“所有用户”安装,您将遇到一些问题需要解决。

    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        String p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CompanyName");
        string[] ss = Directory.GetDirectories(p, "ProjectName.*");
        foreach (string s in ss)
        {
            if(MessageBox.Show("Delete " + s + "?","Delete Settings?",MessageBoxButtons.YesNo) == DialogResult.Yes)
                Directory.Delete(s, true);
        }
        base.Uninstall(savedState);
    }

我实际上不会将提示留在那里,这只是为了测试以确保我不会删除电脑上的错误文件夹......直到此代码经过完全测试。需要更改 CompanyName 和 ProjectName 以匹配您的项目。

我可能会添加一个页面来卸载 UI,或者只是一个提示,询问他们是否要删除所有设置(这样如果他们要重新安装,他们可以选择不删除)。

This worked for me, based on the answer above. For my app I only allow per user installs, not "all users" so I don't have to worry about uninstalling for multiple users, or for users other than the current user running uninstall. If you allow "all user" installs, you'll have some issues to work out.

    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        String p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CompanyName");
        string[] ss = Directory.GetDirectories(p, "ProjectName.*");
        foreach (string s in ss)
        {
            if(MessageBox.Show("Delete " + s + "?","Delete Settings?",MessageBoxButtons.YesNo) == DialogResult.Yes)
                Directory.Delete(s, true);
        }
        base.Uninstall(savedState);
    }

I'm not actually going to leave the prompt in there, that is just for testing to make sure I'm not deleting the wrong folders on my PC.. until this code has been fully tested. CompanyName and ProjectName need to be changed to match your project.

I might add a page to uninstall UI or just a prompt to ask if they want to delete all settings (so they can choose not to if they are going to reinstall).

不弃不离 2024-12-01 03:55:24
var filePath = Environment.ExpandEnvironmentVariables(@"%userprofile%\APPDATA/ProjectName");
System.IO.Directory.Delete(filePath );
var filePath = Environment.ExpandEnvironmentVariables(@"%userprofile%\APPDATA/ProjectName");
System.IO.Directory.Delete(filePath );
柠檬色的秋千 2024-12-01 03:55:24

您可以编写自定义操作以在安装或卸载或同时安装和卸载时触发可执行文件。
例如:创建一个 .exe 它将删除 user.config 文件夹。将此exe添加到二进制表中。在 CustomAction 表中添加一个条目,其中 Source 是二进制表中名称的外键,TArget 是实际的 exe 文件名,类型 = 2。现在将此操作添加到 InstallExecuteSequence 中,使用您希望在安装过程中触发 .exe 的任何序列顺序。

You can write a custom action to trigger an executable while install or uninstall or both.
for eg: create an .exe which will delete the user.config folder. Add this exe in binary table. Add an entry in CustomAction table with Source being the foreign key to name in Binary table and TArget being the actual exe file name and type = 2. Now add this action in InstallExecuteSequence with whatever sequence order you wish to trigger the .exe in installation process.

嗼ふ静 2024-12-01 03:55:24

1) 创建自定义动作(文章包含图片)

2) 处理自定义操作的Uninstall事件

  [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
        try
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            path = Path.Combine(path, "{Your application folder name}");
            Directory.Delete(path, true);
        }
        catch(Exception)
        {
        }
        base.Uninstall(savedState);
    }

1) Create a custom action (article includes pictures)

2) Handle the Uninstall event of the custom action

  [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
        try
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            path = Path.Combine(path, "{Your application folder name}");
            Directory.Delete(path, true);
        }
        catch(Exception)
        {
        }
        base.Uninstall(savedState);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文