Load external dll Active Directory

Feb 6, 2015 at 8:21 AM
I want to load an external dll from msiext. With this dll i can browse for usernames in Active Directory. In Wix I would do the following:

<CustomAction Id="DirectoryObjectPicker" BinaryKey="ActiveDirectory" DllEntry="DirectoryObjectPicker" Execute="immediate" Return="check" />
<Binary Id="ActiveDirectory" SourceFile="$(var.BinDir)\ActiveDirectory.dll" />

The following code adds a Browse for users button to a Wix UI.

<Control Id="UsernameBrowse" Type="PushButton" X="235" Y="120" Width="75" Height="17" Text="&Browse ...">
<Publish Property="DSOP_SCOPE_TYPES" Value="DSOP_SCOPE_TYPE_TARGET_COMPUTER|DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN" Order="1">1</Publish>
<Publish Property="DSOP_SCOPE_FLAGS" Value="DSOP_SCOPE_FLAG_STARTING_SCOPE|DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS" Order="1">1</Publish>
<Publish Property="DSOP_SCOPE_FILTER_FLAGS" Value="DSOP_FILTER_USERS" Order="1">1</Publish>
<Publish Property="DSOP_DOWNLEVEL_SCOPE_FILTER_FLAGS" Value="DSOP_DOWNLEVEL_FILTER_USERS" Order="1">1</Publish>
<Publish Event="DoAction" Value="DirectoryObjectPicker" Order="2">1</Publish>
<Publish Property="SERVICE_USERNAME" Value="[DSOP_UPN]" Order="3"><![CDATA[DSOP_UPN <> ""]]></Publish>
<Publish Property="SERVICE_USERNAME" Value="[DSOP_NAME]" Order="3"><![CDATA[DSOP_NAME <> "" AND DSOP_UPN = ""]]></Publish>
</Control>

How can I do this in WixSharp?

Thanks!

Robin Lutteke
Feb 18, 2015 at 12:49 AM
Wix# support for custom WiX dialogs is not very comprehensive but it is doable. Please see <Wix# Samples>\Custom_UI\CustomMSIDialog sample. And this CodeProject article explains the limitations.

I would rather use an injected WinForm dialog (<Wix# Samples>\Custom_UI\CustomCLRDialog sample) and update it with a simple C# routine for obtaining the user names:
using (var context = new PrincipalContext(ContextType.Domain, Environment.UserDomainName))
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
    foreach (var result in searcher.FindAll())
    {
        DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
        Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
        Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
        Console.WriteLine("SAM account name   : " + de.Properties["samAccountName"].Value);
        Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
        Console.WriteLine();
    }
}