Monday, October 22, 2012

Wix: Giving default Users group full access to a folder.

Using VbScript Custom Action:

I had a situation in which Windows default Users group was required Full Permissions upon a folder which was creating by my installers. This is not a big problem. Actual problem which I was facing is that on German Windows, default Users group is not Users group. Its “Benutzer” there actually. So I had to use a vbscript while hardcoding group name and applying Windows built-in command cacls.exe (now its icacls.exe):

VbScript Custom Action:
  1. 'Reading the Locale Value to detect which Regional Language this Windows (NT)  have
  2. nLocale=WshShell.RegRead("HKEY_USERS\.DEFAULT\Control Panel\International\\Locale")
  3. if (nLocale="") or IsEmpty(nLocale) or IsNull(nLocale) then
  4.     nLocale=00000409
  5.     sUserGroup="Users"
  6. end if
  7.  
  8. if nLocale=00000409 then 'Its English
  9.     sUserGroup="Users"
  10. elseif nLocale=00000407 then 'Its German
  11.     sUserGroup="Benutzer"
  12. end if
  13.  
  14. 'Applying permissions
  15. if fso.FolderExists(sLocalRoot) then
  16.         'StrCommand = "cmd /c cacls.exe " & """" & sLocalRoot & """" & " /G EveryOne:F /E"
  17.         StrCommand = "/c cacls.exe " & """" & sLocalRoot & """" & " /G " & sUserGroup & ":F /E /T"    
  18.         
  19.         'Get the Windows Major Version from the Registry
  20.         sOSversion=WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
  21.         If CInt(sOSversion) >= 6 then
  22.             objShell.ShellExecute "cmd.exe ", StrCommand, "", "runas", 1
  23.         Else
  24.             WshShell.Run "Cmd.exe " & " " & StrCommand  
  25.         End If
  26. End if

 

Using Wix Util Extension:

Now using Wix Util extension, this has been shorten to:

1 <!--Referencing property defined by Util Extension-->
2 <PropertyRef Id="WIX_ACCOUNT_USERS"/>
3
4 <!-- +++++++++++++++++++++++++++++++ -Directory Structure +++++++++++++++++++++++++++++++ -->
5 <Directory Id="TARGETDIR" Name="SourceDir">
6 <Directory Id="DATASET" Name="MyDataSet">
7 <Component Id="DoPermissions" DiskId="1" Guid="{2E90BD04-2E1B-4CAE-994B-090D937F3E5A}">
8 <CreateFolder>
9 <util:PermissionEx ChangePermission="yes" GenericAll="yes" User="[WIX_ACCOUNT_USERS]" Traverse="yes" />
10 </CreateFolder>
11 </Component>
12 </Directory>

Property WIX_ACCOUNT_USERS would detect the default Users group and PermissionEx command would apply permissions using its value for a specific folder.


Note: You have to include WixUtilExtension with Candle and Light.

No comments: