\
Skip Navigation LinksHome > eZine > Ask Vance\
 
 
Vance Hunt has provided home-user help desk style support for his consulting company for over 6 years. Making his home in beautiful Southern California, Vance provides general computer Q&A for users via his weekly column.

[]Ask Vance A Question
[]Browse Other Dates



 
Icon of Vance HuntFriday, February 19, 2010
The fun world of 64-bit Windows 7 - and all the legacy things it doesn't bring to the table any more.
By Vance Hunt
 
Shout-Back! Read Comments  |  Post A Comment

Q: How do I dynamically discover the NetBIOS name of the domain a computer is joined to?

 
A: It is actually easier than you might think, and from within VBS or JScript, you don't even need administrative credentials.  Here are the functions:

 

VBScript
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

Set objRDSE = GetObject("LDAP://RootDSE")
Set objTrans = CreateObject("NameTranslate")

objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, objRDSE.Get("defaultNamingContext")

strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

WScript.Echo strNetBIOSDomain

JScript
var ADS_NAME_INITTYPE_GC = 3;
var ADS_NAME_TYPE_NT4 = 3;
var ADS_NAME_TYPE_1779 = 1;

var objRDSE = GetObject("LDAP://RootDSE");
var objTrans = new ActiveXObject("NameTranslate");

objTrans.Init(ADS_NAME_INITTYPE_GC, "");
objTrans.Set(ADS_NAME_TYPE_1779, objRDSE.Get("defaultNamingContext"));

var strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4);
strNetBIOSDomain = String(strNetBIOSDomain).substring(0,strNetBIOSDomain.length-1);

WScript.Echo(strNetBIOSDomain);

VB.NET
Private Function GetNetBIOSDomainName( _
     Optional ByVal strDomainAccountName As String = "", _
     Optional ByVal strPassword As String = "") As String

Dim objRDSE As New System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")

If Not String.IsNullOrEmpty(objRDSE.Properties("defaultNamingContext").Value) Then
     Dim objDomain As New System.DirectoryServices.DirectoryEntry( _
          "LDAP://CN=Partitions,CN=Configuration," & objRDSE.Properties("defaultNamingContext").Value, _
          strDomainAccountName, strPassword)

     For Each objDE As System.DirectoryServices.DirectoryEntry In objDomain.Children
          If objDE.Properties("nCName").Value = objRDSE.Properties("defaultNamingContext").Value Then
                GetNetBIOSDomainName = objDE.Properties("NetBIOSName").Value
          End If
     Next
Else
     GetNetBIOSDomainName = Nothing
End If

objRDSE.Dispose()

End Function
 

There are "fun" ways to use the NameTranslate object in .NET, but gets a little convoluted and uses a lot of COM objects instead of the .NET Framework, so the presented way is typically considered the easiest, although it does require that an username/password with sufficient rights to the Active Directory be used in order to return a value.



Q: I have an application I wrote in Visual Studio 2008 that makes use of a JET Database [Microsoft Access MDB file].  Its a "work in progress" but I've been using it on a few different computers for quite a while (XP and Vista).  I recently bought a new computer with Windows 7 64-bit on it, made a few changes in the application, recompiled it, and now every time I go to run it I get a Provider Not Found error.  The changes were very minor, the previously compiled version works just fine, and even rolling back my current changes do not resolve the issue.  I'm at a loss to figure out what the problem is.

 
A: The problem is your 64-bit environment and the JET database providers: There are no 64-bit JET providers available for Windows.  You initially wrote and compiled your application on a 32-bit platform which means that you have a 32-bit executable.  When you launch that 32-bit executable, even in a 64-bit environment, Windows runs it with the 32-bit subsystem and thus you have access to the JET provider.  But when you reopened your project in Windows 7 64-bit, made changes and recompiled it, it compiled as a 64-bit executable, and thus no providers. 

In Visual Studio, ensure that you can always access the advanced build configuration dialog (Tools | Options | Projects and Solutions | General | Show advanced build configurations). From the build menu, select the Configuration Manager and change your project's solution platform from 64-bit to 32-bit (you may need to select the "<<new>>" option and follow the prompts).  Once your project has been changed back to 32-bit, you can compile it and use it again as expected.




Comments: [0]   [Show Disclaimer]

Post a Comment
Display Name:
Comment:
(Plain text only - all HTML will be stripped)

Previous Ask Vance Questions:

 FAQs  |  Terms Of Use  |  Privacy Policy  |  Contact Us
Copyright © 1997 - 2012 Dx21, LLC. All rights reserved.
Dx21, LLC a Washington Limited Liability Company
Page Rendered at: 5/17/2012 7:58:07 AM for Unknown