Tulpep / Active-Directory-Object-Picker

The standard Active Directory object picker dialog for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Q: how do I know how to present the result DO user name

mwpowellhtx opened this issue · comments

i.e. as a local user, ".\user" along these lines, when the resulting DirectoryObject.Path is something like this, "WinNT://group/machineName/user". Any guidance around that, if you please. With group and machineName, ostensibly being the name of the local working group and machine names, respectively. Thanks so much...

To clarify, I can probably do some searching for string patterns and such from various dotnet sourced resources, but in particular, with regard to the Tulpep use case, and resulting instances. It is easy enough, for instance, to identify machine names, IIRC, and possibly even working group names, I do not know, as I am less familiar with that.

In general, my use case is to identify the principal that would be used to configure a Windows Service. If there is any guidance around that aspect, in general, would be greatly appreciated.

Here's a snippet that looks promising, but again, could this be stitched together by DirectoryObject in a bit more useful, cohesive manner, without extraneous consumer view model intervention.

var machineName = Environment.MachineName;
var compSys = new ManagementObject($"Win32_ComputerSystem.Name='{machineName}'");
var workgroupValue = compSys["Workgroup"];
var workgroup = $"{workgroupValue}";

Apparently, requirest at least System.Management package dependencies.

Such that, when we see something like this "WinNT://group/machineName/user", instead we are (correctly, IMO) presented with this ".\user", especially, in particular, when that user is a user on the local machine.

Verified under debugging.

Possibly also in need of the System.DirectoryServices.AccountManagement package, especially if you go the extra mile and validate credentials.