jerryz
Posts: 13
Joined: Fri Mar 08, 2013 11:51 am

How to prevent users from installing directly to system folders like "Program Files"?

Hello,
What is the most simple way to check whether user selected (using an installation dialog) as a main installation patch some system folder like 'C:\Program Files" and force him to use a custom path like 'C:\Program Files\MyProgram" ?

Many thanks for help. J.
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: How to prevent users from installing directly to system folders like "Program Files"?

Hello J.,

In order to achieve that, please have a look over the following forum thread in which I have explained to another user how this can be achieved:

Prevent installation in the system folder

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jerryz
Posts: 13
Joined: Fri Mar 08, 2013 11:51 am

Re: How to prevent users from installing directly to system folders like "Program Files"?

I'm sorry, but our the problem is different than "installing under ProgramFiles". We don't want users select "ProgramFiles" or other system folder as APPDIR. We clean the whole APPDIR after the uninstallation and if the APPDIR is ProgramFiles, then all content of ProgramFiles (other installed apps included) get cleaned/deleted.

So we want to make sure that users always selects installation path with custom subdirectory at the end... like "ProgramFiles/UsersCustomDirectory".
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: How to prevent users from installing directly to system folders like "Program Files"?

Hello J.,

Honestly, I can not really think of a programmatic way of achieving this, other than simply comparing APPDIR with every path that is not compatible and prompting a messagebox to the user. For instance, a condition for the messagebox may look like this:

Code: Select all

(APPDIR >< ProgramFilesFolder) OR (APPDIR >< ProgramFilesFolder64)
The above condition would translate to:
if APPDIR contains ProgramFilesFolder or APPDIR contains ProgramFilesFolder 64
Beside prompting the messagebox, another thing that could be done (silently) would be to set the APPDIR property right after the user has set it using a "Set property" as a "Published Event" on the "Next" button of the "FolderDlg" dialog. However, in a normal scenario, you'd like to condition this "Set property" event to only executes when needed and once again, the only way of doing so is the solution presented above.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”