Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 通过msiexec/x命令行选项卸载时删除user.config_.net_Windows Installer_Uninstallation_User.config - Fatal编程技术网

.net 通过msiexec/x命令行选项卸载时删除user.config

.net 通过msiexec/x命令行选项卸载时删除user.config,.net,windows-installer,uninstallation,user.config,.net,Windows Installer,Uninstallation,User.config,我有一个安装.net应用程序的MSI安装程序包。它还安装通过msiexec/x选项执行卸载的Uninstall.bat文件。但它不会删除在用户本地设置\应用程序数据文件夹\公司名称\产品文件夹中创建的user.config文件。 我不知道我该怎么做,因为我无法在安装程序中找到任何选项 我可以创建另一个批处理文件来完成这项工作,但不确定这是否是正确的方法。另外,如果我尝试使用批处理文件,我将如何找到当前用户以访问正确的文件夹?我不想把事情弄得太复杂。有没有简单的方法 请建议 我成功了。我在解决方案

我有一个安装.net应用程序的MSI安装程序包。它还安装通过msiexec/x选项执行卸载的Uninstall.bat文件。但它不会删除在用户本地设置\应用程序数据文件夹\公司名称\产品文件夹中创建的user.config文件。

我不知道我该怎么做,因为我无法在安装程序中找到任何选项

我可以创建另一个批处理文件来完成这项工作,但不确定这是否是正确的方法。另外,如果我尝试使用批处理文件,我将如何找到当前用户以访问正确的文件夹?我不想把事情弄得太复杂。有没有简单的方法


请建议

我成功了。我在解决方案中创建了一个新的控制台项目“UninstallHelper”。在UninstallHelper项目中添加了一个InstallerClass。我正在覆盖OnBeforeUninstall方法:

protected override void OnBeforeUninstall(IDictionary savedState)
    {
        base.OnBeforeUninstall(savedState);
        try 
        {
            List<string> appFolders = new List<string>();
            string userFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string userDataFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);


            userFolderPath = userFolderPath + @"\CompanyName";
            userDataFolderPath = userDataFolderPath + @"\CompanyName";


            appFolders.Add(userFolderPath);
            appFolders.Add(userDataFolderPath);


            foreach (string folderPath in appFolders)
            {
                List<string> umDirs = new List<string>();
                DirectoryInfo targetDir = new DirectoryInfo(folderPath);

                foreach (DirectoryInfo dir in targetDir.GetDirectories())
                {
                    if (dir.Name.StartsWith("ProductName"))
                        umDirs.Add(dir.FullName);
                }

                foreach (string dirName in umDirs)
                {
                    DirectoryInfo subDir = new DirectoryInfo(dirName);
                    foreach (FileInfo file in subDir.GetFiles())
                    {
                        if (file.Exists)
                            file.Delete();
                    }

                    foreach (DirectoryInfo dir in subDir.GetDirectories())
                    {
                        if (dir.Exists)
                            dir.Delete(true);
                    }

                    subDir.Delete();
                }
            }
        }
        catch(Exception ex)
        {
            //Console.WriteLine(ex.Message);
            //Console.ReadKey();
        }
卸载前受保护的覆盖无效(IDictionary savedState) { base.onbeforeunstall(savedState); 尝试 { List appFolders=新建列表(); 字符串userFolderPath=Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); 字符串userDataFolderPath=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); userFolderPath=userFolderPath+@“\CompanyName”; userDataFolderPath=userDataFolderPath+@“\CompanyName”; appFolders.Add(userFolderPath); 添加(userDataFolderPath); foreach(appFolders中的字符串folderPath) { List umDirs=新列表(); DirectoryInfo targetDir=新的DirectoryInfo(folderPath); foreach(targetDir.GetDirectories()中的DirectoryInfo目录) { if(dir.Name.StartsWith(“ProductName”)) umDirs.Add(目录全名); } foreach(umDirs中的字符串dirName) { DirectoryInfo subDir=新的DirectoryInfo(dirName); foreach(subDir.GetFiles()中的FileInfo文件) { 如果(file.Exists) Delete(); } foreach(subDir.GetDirectories()中的DirectoryInfo目录) { 如果(目录存在) 直接删除(正确); } 删除子目录(); } } } 捕获(例外情况除外) { //控制台写入线(例如消息); //Console.ReadKey(); } 现在我在安装程序中添加此项目的主要输出。最后,我在卸载中添加一个自定义操作作为卸载帮助程序项目的主要输出

这对我起了作用