もう1つのオプションは、SIDを含むmsiプロパティをローカライズされたOSからのグループの実際の名前に変換するだけの単純なCAを用意することです。CAは延期する必要はなく、権限を設定する実際の作業を実行していません。
以下は、PROPERTY_TO_BE_TRANSLATED msiプロパティの値を読み取り、それによって示されるmsiプロパティを変換するCAのサンプルです。このようにして、CAを実行してさまざまなmsiプロパティを変換できます。
[CustomAction]
public static ActionResult TranslateSidToName(Session session)
{
var property = session["PROPERTY_TO_BE_TRANSLATED"];
if (String.IsNullOrEmpty(property))
{
session.Log("The {0} property that should say what property to translate is empty", translateSidProperty);
return ActionResult.Failure;
}
var sid = session[property];
if (String.IsNullOrEmpty(sid))
{
session.Log("The {0} property that should contain the SID to translate is empty", property);
return ActionResult.Failure;
}
try
{
// convert the user sid to a domain\name
var account = new SecurityIdentifier(sid).Translate(typeof(NTAccount)).ToString();
session[property] = account;
session.Log("The {0} property translated from {1} SID to {2}", property, sid, account);
}
catch (Exception e)
{
session.Log("Exception getting the name for the {0} sid. Message: {1}", sid, e.Message);
return ActionResult.Failure;
}
return ActionResult.Success;
}
WiXでは、アカウントのSIDを使用して変換するプロパティを定義します。
<Property Id="AdminAccount" Value="S-1-5-32-544" />
<Property Id="EveryoneAccount" Value="S-1-1-0" />
PROPERTY_TO_BE_TRANSLATEDプロパティを設定するCAを作成してから、変換を行うCAを呼び出します。
<CustomAction Id="TranslateAdmin_SetProperty" Property="PROPERTY_TO_BE_TRANSLATED" Value="AdminAccount"/>
<CustomAction Id="TranslateAdmin" BinaryKey="CommonCustomActions" DllEntry="TranslateSidToName" Impersonate="no" />
<CustomAction Id="TranslateEveryone_SetProperty" Property="PROPERTY_TO_BE_TRANSLATED" Value="EveryoneAccount" />
<CustomAction Id="TranslateEveryone" BinaryKey="CommonCustomActions" DllEntry="TranslateSidToName" Impersonate="no" />
権限を設定するときは、msiプロパティを使用することを忘れないでください。
<CreateFolder>
<Permission GenericAll="yes" User="[AdminAccount]" />
<Permission GenericRead="yes" GenericExecute="yes" User="[EveryoneAccount]" />
</CreateFolder>
最後に、CreateFolderの前にCAをスケジュールします
<InstallExecuteSequence>
<Custom Action='TranslateAdmin_SetProperty' Before='TranslateAdmin' />
<Custom Action='TranslateAdmin' Before='CreateFolders' />
<Custom Action='TranslateEveryone_SetProperty' Before='TranslateEveryone' />
<Custom Action='TranslateEveryone' Before='CreateFolders' />
</InstallExecuteSequence>
このように、CAはいくつかの簡単な作業のみを実行し、アクセス許可の設定はWiX要素に任せます。