开发者

Force remove the user.config during uninstall?

开发者 https://www.devze.com 2023-03-20 19:36 出处:网络
how do i code the custom action during the uninstall? Would it requ开发者_运维百科ire a batch file?

how do i code the custom action during the uninstall? Would it requ开发者_运维百科ire a batch file?

thanks!


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.


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).


var filePath = Environment.ExpandEnvironmentVariables(@"%userprofile%\APPDATA/ProjectName");
System.IO.Directory.Delete(filePath );


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.


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);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消