I am looking a way to find out the LDAP path of a computer object. I found an example in vbs, but I don't figure out to translate this in c#. Does anyone got an idea how to do this
Thanks.
I post you the vbs code for your info.
Public Const ADS_NAME_INITTYPE_GC = 3
Public Const ADS_NAME_TYPE_1779 = 1
Public const ADS_NAME_TYPE_NT4 = 3
sSAMAccountName = "domain\computername$" 'replace with the computer account with $ on the end
Set oNTr = WScript.CreateObject("NameTranslate")
oNTr.Init ADS_NAME_INITTYPE_GC, ""
oNTr.Set ADS_NAME_TYPE_NT4, sSAMAccountName
GetDNFromSAM = oNTr.Get(ADS_NAME_TYPE_1779)
Set oUser = GetObject("GC://" & GetDNFromSAM)
sUserContainerDN = Replace(lcase(oUser.distinguishedName), lcase("cn=" & oUser.cn) & ",", "")
WScript.Echo sUserContainerDN

Computer LDAP path
Adrian w
Thanks for answering.
At the moment it doesn't bring me further.
I was looking in the help files of VS2005 and came across this:
try
{
DirectoryEntry usr = new DirectoryEntry("WinNT://hostname,computer");
string test = (string)usr.InvokeGet("ADsPath");
MessageBox.Show("test=" + test);
}
catch (System.Exception ex)
{ MessageBox.Show(ex.Message); }
But it doesn't get me in a good direction.
Can you help me out
James Hill
Marcel Lattmann
http://www.techietwo.com/detail-6060651.html
Ok, the solution:
Add a COM reference ActiveDs (Active DS Type Library)
On top of the document add using ActiveDs;
Private void GetPath()
{
string sComputerName = "Hostname";
ActiveDs.IADsADSystemInfo oSysInfo = new ActiveDs.ADSystemInfoClass();
ActiveDs.IADsNameTranslate oNameTranslate = new ActiveDs.NameTranslateClass();
oNameTranslate.Init((int)ActiveDs.ADS_NAME_INITTYPE_ENUM.ADS_NAME_INITTYPE_DOMAIN,"EUROPE");
oNameTranslate.Set((int)ActiveDs.ADS_NAME_TYPE_ENUM.ADS_NAME_TYPE_NT4,("EUROPE\\" + sComputerName + "$"));
string sTemp = oNameTranslate.Get((int)ActiveDs.ADS_NAME_TYPE_ENUM.ADS_NAME_TYPE_1779);
MessageBox.Show("Path=" + sTemp);
}
Note the $ sign, that is needed in order to get the path = the Netbios name of the computer object.
Thanks all, hopefully you have something on it.