Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Setting file permissions help needed


4 replies to this topic

KBrecheisen

KBrecheisen
  • Full Members
  • 5 posts

Posted 15 May 2007 - 19:45

I need to be able to set the file permissions on a data file copied to the [CommonAppDataFoler]MyFolder location by an InstallScript Custom Action. The file is a unique per client license file so it is not distributed in the installation package. I am creating the directory in the MSI package and granting Full Control to Everyone, but I need to grant the same rights to the file I am copying into that directory.

This data file formerly resided in the [ProgramFiles]CompanyName\ProductName folder, but because of Vista I am moving it to the [CommonAppDataFoler]MyFolder location.

Anyone have any ideas. The solution must work for Windows 2000, 2003, XP and Vista.

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 16 May 2007 - 01:25

You should be able to use cacls.exe or subinacl.exe (both from Microsoft). cacls.exe should be on the OS (not sure about Vista), but subinacl.exe would need to be included in your setup's binary table (which is safer anyway).

Subinacl.exe is a typical Microsoft tool: everything is possible, but nothing is easy (Note that there appears to be a serious bug in subinacl.exe when applying permissions to files straight of the root of C:\ - it seems to search the entire drive for folders / files matching the specified root file / folder. Other than that subinacl.exe is very solid).

Here are some basic sample command lines to get you going:

---------------
FILES & FOLDERS
---------------

Open folder (only) for users:
subinacl /subdirectories "C:\Program Files\Test" /grant=Users=F

Open files for users (only - directories not affected):
subinacl /subdirectories "C:\Program Files\Test\*.*" /grant=Users=F

Set single file read only:
subinacl /file "C:\Program Files\Test\WSUSNow.log" /grant=Users=R

--------
REGISTRY
--------

Open registry folder for users:
subinacl /subkeyreg "HKEY_LOCAL_MACHINE\SOFTWARE\test" /grant=Users=F

Set registry folder read only for users:
subinacl /subkeyreg "HKEY_LOCAL_MACHINE\SOFTWARE\test" /grant=Users=R


Regards
-Stein Åsmul

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 16 May 2007 - 01:27

Just so it is clear:

1: Add subinacl.exe to the binary table
2: Call subinacl.exe from deferred mode, system context, syncronous, ignore exit code
3: If you are using Wise use an "Execute Program From Instalation" custom action - not sure what the equivalent is for Installshield.
4: Remember to condition the custom actions to run only during fresh install (Not Installed)
5: Should you need to remove the custom access during uninstall add a corresponding custom action to run only during uninstall (REMOVE~="ALL)
Regards
-Stein Åsmul

MrSmersh

MrSmersh
  • Full Members
  • 48 posts

Posted 16 May 2007 - 11:10

You could look here: http://www.installsi...s/en/isp_os.htm the section Setting Access Permissions.
Since is InstallScript MSI it should work.

KBrecheisen

KBrecheisen
  • Full Members
  • 5 posts

Posted 17 May 2007 - 20:29

Thanks for the replys. I discovered a fairly low tech way to do what I was looking to do.

My objective was to copy the file "Wicks.Lic" from any possible location into the [CommonAppDataFolder]\AIO directory. The problem is that there is no way of knowing what the file permissions are set to on the source file. The file is being located using an AskPath dialog and then copied to the target folder. Since the copy is done in this manner, I have no access to the MSI functions for setting file permissions.

My solution:
1. Create a new "Generic.Lic" file and make it the Key file of a component.
2. Set the file permissions for Everyone - Full Control on the Generic.Lic file (Files and Folders view, Right Click File, Select Properties, Press Permissions Button, Set user Everyone to Full Control).
3. Install the file to the [CommonAppDataFolder]\AIO folder.
4. During runtime, I check if a valid Wicks.Lic file is installed in the target directory. If not, I copy the Generic.Lic to Wicks.Lic in the same directory.
5. The copy of the Generic.Lic file (now named Wicks.Lic) carries the permissions of the original.
6. Now I copy the real Wicks.Lic file over the fake Wicks.Lic file from whatever souce location is selected. The copied file will carry the permissions of the original file.

So.. a couple of lines of InstallScript code and one extra file to install solves my dilema in a low tech way that appears to be very reliable on the operating systems I have tested it on...2000, XP and Vista.