How to delete application file from AppData\Roaming folder - installation

I am using windows installer to create setup project.
How I can remove/delete application files from AppData\Roaming folder when application uninstalled.
I tried added a special folder and set DefaultLocaltion to [AppDataFolder] but it didn't working.
Do I need to do anything else?

I'd need to understand what you are trying to do to give you specific advice. In general what you are trying to do would be OK removing files from CommonAppDataFolder but not AppDataFolder as trying to clanup user data from multiple user profiles is not a best practice. Additionally trying to cleanup Roaming Profile User data is outright impossible because the other users aren't logged on.
You'll want to read:
Managing Roaming User Data Deployment Guide
Assuming you are trying to do what I think you are, you'll need a cleanup script / exe that you leave behind on uninstall and a custom action to write to the registry during uninstall ( MSI can't do this natively ) to call that script/EXE. You'll want to leverage the Active Setup trick as described here:
Using Active Setup to Repair User Settings
The way it'll work is your uninstall leaves the EXE and registry entry behind so that when a user logs on it's roaming data gets pulled down from the server to local and Active Setup realizes it hasn't run the script yet. The script runs (once) and the data is deleted. When the user logs off the data is replicated / deleted on the server. Then they log on again it doesn't run again.

By default Windows Installer does not remove the files created by your application, after the installation. To do that you need to either write your own custom action, that will run upon uninstall, or depending on the tool used for authoring the MSI, you can use built-in options for cleaning the application locations, as some tools have this support.

Related

SCCM and USMT does not perform well

Have just succeeded in setting up a State migration point on our SCCM and after that got USMT to make user profile backup and restore on the reinstalled PC.
According to the log everything is OK and User data and desktop is there but hardly anything else , not even my Edge favorites or any browser favorites.
USMT is the latest 20H2
Is this what to expect or is something wrong?
I know. Disapointing but it is only a question about updates.
Please get my EhlerTech updated custom xml files for USMT and include them in your SCCM USMT package.
Basically just use MigUser.xml, MigApp.xml and Win10.xml from my xml package.
In case you only need the users profile without scanning the rest of the drive for docs, use MigUser_Profile_only.xml (faster but only grabs data inside the user profiles)
To see a more thorough XML guide go here :-)
/Thomas

Best Practice User Files and Folders in AppData

I’m writing an application that should save user specific data into AppData. This application has an installer. Now I’m not sure, what is the best way to provide the folders in AppData.
Should the installer create (and delete) the folders, or should the application itself create (but probably never delete) the folders.
Also, if multiple user on the same computer use the app, the folders probably doesn’t exist, if another user installed the application.
I didn’t found anything that really explained this to me.
Thanks in advance.
I'll answer for Windows Installer, MSI files, and basically you shouldn't need to worry about it in the installer; just install files to their required locations, and the folder will be created automatically and removed at uninstall if it's empty.
In addition to Phil's correct answer:
If the files from the AppData folders used by your application are created only by the application, at run time, there is no need to configure the installer to create the empty folders. Those folders will be created the moment your app writes down the files.
Also, even if your installer is creating the folder, on uninstall it will not remove if in that folder are files created by the application. Windows Installer keeps track (should do it in a correctly configured package) of every file it installs and only removes the ones it installed (by default, it can be configured to force remove a folder and files which it did not install).
Regarding other users of the app. In this scenario, the simplest method is to use your application for creating the initial default files in the AppData folder, at the first launch of the app for each user.
If you need to install files to AppData from your installer then you could try one of the following approaches. These techniques can be applied with any setup authoring tool that can create MSI packages.

Windows installer is too clever, tries to repair when tester deletes config file

Our application is deployed to the target machine with an msi file. All works nicely. Our tester has gone through his plan, and one of the tests requires deleting the application's configuration file. The application is designed to alert the user with a dialog on startup saying "missing config". However, what happens is that - somehow! - the software starts the installer again and retrieves the missing file from the msi! Which is nice, but not what we want. How do we disable that behaviour?
without going into much depth of the windows installer mechanics (if you interested in that there a plenty of articles about this), the shortcut of the software is probably advertised, which means the windows installer checks if everything is in its place before the software is started.
if you can edit the msi, make the shortcut non advertised.
if you can't, install it with DISABLEADVTSHORTCUTS
e.g. msiexec /i myMsi.msi DISABLEADVTSHORTCUTS=1
please note that this is only a quick (and dirty) workaround,
to fix this proper you need to understand the whole windows installer advertising (also called repair or self resiliency) mechanism.
but explaining all the causes and the mechanism of the repair is far beyond this answer and there are quite some articles and posts about that on the internet (and especially on MSDN and stackoverflow)
There is a more correct answer to this, and it is NOT DISABLEADVTSHORTCUTS. You set the component id to null in the MSI file to prevent repair of that individual file. See ComponentId comments here:
http://msdn.microsoft.com/en-us/library/aa368007(v=vs.85).aspx
Edit the MSI file with Orca to delete the Componenty ID, and write an uninstall custom action to delete the file at uninstall if it's there.
In addition, that's a redundant test. Windows will restore that file for you if it's missing, so the idea that you need a test to notify that it's missing is pointless. The true test should be that Windows will restore the file if it's lost, and your app needs to do potentially nothing about the missing file.
You don't mention what tool you are using to make your MSI but I'm going to go out on a limb and guess Visual Studio Deployment Projects (.VDRPOJ).
One of the (many) horrible things about this tool was that it fails to expose the foundational concept of components. Instead it makes every file a key file of it's own component and hides the existence of the component from you. I say 'was' because Microsoft killed this project type in VS. There are around 50k people complaining on UserVoice to bring this tool back and I'm guessing that 49,990 of them don't know what a key path is.
Windows Installer has a concept called the component rules and each component has a keypath. The keypath teaches MSI how to handle repair scenarios. But your tool has to allow you to be able to control this to make it work.
Windows Installer is functioning exactly the way it's supposed to function. You just aren't up to speed on what that is.
However, if you want to ignore Windows Installer best practices and continue using the tool you use today, the trick is to install the app.config file as a different file. Then have the application copy the file to the real file name on run. Windows Installer won't service what it didn't install.
Several answers have been provided that can work:
You can install the file with a blank guid. Then you need to remove it on uninstall using the RemoveFile feature. You will also run into issues if you want to replace it during an upgrade. Could be tricky at times.
You can disable the advertised shortcut(s), but this affects too much in my opinion.
Finally you can use my suggestion to install a separate non-advertised shortcut to use to launch the application. Such a shortcut bypasses the self-repair check. It may still be invoked by other means such as missing file associations, COM registration or similar, but those are exception states.
However, my preference is that an application can start without a config file present, if at all possible. I always suggest a good startup routine with "internal defaults" available. The startup routine should also degrade gracefully if faced with any file system access denied conditions.
Most importantly you should place this config file in the userprofile so you can generate the file on first launch for the user in question. It can even be copied from a read-only copy in the main installation directory.
When you generate a file from internal defaults and put it in a userprofile location, the file will have no interference with Windows Installer at all. The issues that results is how to clean up user data on uninstall. I discussed this with Stefan Kruger (MSI MVP) at one point, and I agree with his notion that user data is indeed user data and should not be automatically dealt with by your installer at all. Leave it installed, and clean it up via system administrator tools if necessary - for example logon scripts.

InnoSetup: Pascal script for cancelling setup when file/folder exists

In my InnoSetup I use several file actions in the InstallRun section. If those are executed correctly without problems then a certain temp folder should have been deleted.
If something has gone wrong then the temp folder is still there. In that case I want the setup to be canceled with a messagebox displaying an error message of my choice.
As I have no experience (yet) with Pascal script I kindly ask you to provide me with an example script yo do this.
Thanks in advance!
Addition:
I'll now explain the reason I need this. The scenario is updating an existing version, which is a Windows Service application. Before updating those files I have to uninstall the services first. For this I use my own commandline that's in the installation package. The other new files will be temporary unpacked to a temp folder (subfolder of app folder). After the Windows services are uninstalled the new files are moved from the temp folder to the app folder. If something goes wrong here I want to cancel the setup and show an error message to the user. I can best tell if something has gone wrong by checking if the temp folder is still there.
Assuming that you mean the [Run] section, it is not possible to cancel the installation that late in the process.
Instead, you should look at using PrepareToInstall. In this, all you need to do is to stop and deregister the old service, either directly via API or by invoking a command on the old service EXE as you choose. (Don't forget to handle the case when the service doesn't exist yet, for new installs.)
After this [Files] will replace the files as normal and you can then [Run] or use code (via AfterInstall or CurStepChanged(ssPostInstall), depending on the time you want it to happen) to re-register and start the service.
No need to muck around with temporary folders -- which is good, because that would have caused problems for uninstall as well.

C# Deployement retaining files over an installation

I have created a Setup and deployment project using the Visual studio and install the setup.
After i install the setup it copies a few files(XML) which on using of the application are configured programmatically .
Now , If the user is reinstalling this setup again i need to ask the user whether these configured files need to be overwritten or be retained ??
Any idea as to how this can be accomplished ?
Thanks & Regards,
Fran
Look into file versioning rules for Windows Installer.
In short, assuming that these XML files you refer to are unversioned text files, MSI will compare the Created and Modified dates and will not replace the updated XML files which you say are updated programmatically (post-install-time).
I would suggest several other variables you need to consider to make sure things are working as you expect: major vs. minor upgrade, and the REINSTALLMODE property.
I find that the best way to approach this kind of scenario is to implement the "preserve changes" logic in your application as opposed to via the setup. This avoids complicating your setup and yields greater control of the config process since all logic is embedded in your main EXE file. This means you can step through the process and debug it the normal "development way".
To achieve this you can install your "base config" files to a read-only location such as
%ProgramFiles%\MyCompany\MyApp\MyConfig*.*
Then your application can detect on launch whether existing config files exist in the user profile (or in a writable shared location), and ask the user whether the new config files should overwrite the existing config or not. You can also easily implement backup functionality for the old config.
In order to ask the question only once per user after deployment, the normal apporach is to flag HKLM with the latest installed version of the application and then write a corresponding flag in HKCU when the copy operation has completed or the user dismissed it:
HKLM\Software\MyCompany\MyApp\Version = 2.0.0
HKCU\Software\MyCompany\MyApp\Version = 1.0.0
In the above scenario version 2.0.0 of the application has been installed, but the per user config copy has not run for the user in question yet. Once it has run the HKCU version will be set to 2.0.0 and the operation is not run again until HKLM is incremented.

Resources