Re: Get Domain Name



The domain name for what? If you want the current user's domain name (which
is what you are getting with this code), why not parse out what is returned
from System.Security.Principal.WindowsIdentity.GetCurrent().Name?

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Dan" <danycloutier@xxxxxxxxx> wrote in message
news:1168546323.938859.257680@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi

I need to get the Domain Name in NT format. I can do it with the
following code, but it takes 5 seconds to execute, which is to much for
me. Anyone know how to do it faster ?

Thanks

Dany


DirectoryEntry rootDSE = new
DirectoryEntry("LDAP://RootDSE";);
string dnc =
(string)rootDSE.Properties["defaultNamingContext"].Value;

DWORD rc; //code de retour
HANDLE handle = IntPtr.Zero;

rc = NativeMethods.DsBind(
null,
null,
out handle
);

if (rc != 0)
{
throw new Exception("...");
}

string[] nomDomaine;
try
{
nomDomaine = NameUtility.DsCrackNamesWrapper(
new string[] { dnc },
handle,
DS_NAME_FORMAT.DS_FQDN_1779_NAME,
DS_NAME_FORMAT.DS_NT4_ACCOUNT_NAME
);
}
catch (Exception ex)
{
throw new Exception("...." + ex.Message);
}
finally
{
NativeMethods.DsUnBind(ref handle);
}
return nomDomaine[0];



.



Relevant Pages

  • Get Domain Name
    ... following code, but it takes 5 seconds to execute, which is to much for ... string[] nomDomaine; ... nomDomaine = NameUtility.DsCrackNamesWrapper( ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Need help with DirectorySearcher FILTER using SID.
    ... the escape character should be a single backslash in the filter. ... actual string doesn't contain \\. ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... After I retrive this sid from meeting class, I need to use it as the ...
    (microsoft.public.dotnet.security)
  • Re: Ldifde - import password
    ... it looks like the string you had included in your LDIF file is what you ... Joe Kaplan-MS MVP Directory Services Programming ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... attribute with the base64 data, ...
    (microsoft.public.windows.server.active_directory)
  • Re: WindowsIdentity error
    ... Joe Kaplan-MS MVP Directory Services Programming ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... sUserPrincipalName)\r\n at SM.SM..ctor(Object objSession, String ... This call works from when run from a Windows Server 2003 enviroment. ...
    (microsoft.public.dotnet.security)
  • Re: How do I convert sid retrieved from the AD to SDDL string form
    ... "Joe Kaplan" wrote: ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... objectSid property to a SecurityIdentifier class. ... string AdSelect = "select objectSid, cn, operatingSystem, ...
    (microsoft.public.dotnet.security)