2

I am writing a 64-bit C# Windows forms application that will run under Windows PE 10 64-bit to pull the Display Name from Active Directory. I have to use 64-bit because the PCs I am running this on will only boot UEFI so I cannot boot into a 32-bit recovery environment. Every time my code reaches a certain spot, I receive the error message: Unknown Error [0x80005000]. If I compile this and run in 32-bit Windows PE 10, it runs fine, with no modification to the code other than compiling 32-bit.

I am using VS2019 and the code is using .NET v4.7.

Below is the code that I am using:

    using (PrincipalContext ad = new PrincipalContext(ContextType.Domain, 
        "dotted.domain.com", "OU=Users,DC=dotted,DC=domain,dc=com", 
        ContextOptions.Negotiate, main.interactiveUser, main.interactivePwd))
    {
        try
        {
            //this is where it fails
            using (UserPrincipal wantedUser = UserPrincipal.FindByIdentity(ad, combo1.Text))
            {
                if (wantedUser != null)
                {
                    givenName = wantedUser.DisplayName;
                }
                else
                {
                    MessageBox.Show("User name not found in AD.  Please locate manually", 
                        "Error finding name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    givenName = "DisplayNameNotFoundInAD";
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            break;
        }
    }

Here are the meanings of my variables:

dotted.domain.com = the name of my domain
main.interactiveUser = user name to log into the domain with from another form
main.interactivePwd = password for said user name
combo1.Text = text from combo box that has the user name I want to search for
wantedUser = user name of the person I want the display name for
givenName = display name for the user name I am searching for

I have tried it with and without the OU=Users with the same result. It also works fine if I am running in Windows normally. I found some other posts about possibly editing the registry with owner info, that made no difference.

Any ideas on why this is happening?

1 Answers1

0

Had a similar issue accessing the registry in 64-bit WinPE in the past. From my understanding it is exactly what PrincipalContext does. In my case, I had to uncheck

prefer 32-bit

on the build-tab in VS.

PS: Would have commented only, but currently I'm not on enough reputation

Mahobo
  • 105
  • 1
  • 16
  • 1
    I did that, but the problem persists. If I have it be "any cpu" and leave "prefer 32-bit" checked, the program does not launch at all in WinPE. If I compile straight x64, or uncheck "prefer 32-bit" it gives the error mentioned in my original post. – IJustToldYou Nov 25 '19 at 14:14
  • 1
    I know you have to use a whole different set of packages for WinPE 64. Is there any chance you've accidentally left a path to the 32 bit packages, or possibly left a package out, in your PE build script(s)? – Clay Nov 28 '19 at 13:36
  • I tried recreating my 64bit PE environment and loaded just the 64bit .NET framework, scripting and WMI OCs. Still getting the error. Rebuilt it again and added everything except the OCs that I know I don't need and many I know I won't need. All still failed with the same error. When I'm recreating my PE environments, I'm using only amd64 for the OCs and the original content. – IJustToldYou Dec 03 '19 at 21:30