K
Kurt Van Campenhout
Hi,
I am trying to get/set Terminal server information in the active directory
on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3,
I need to do it myself.
I'm fairly new to VB.NET, so I need some help.
Here is a code snippit :
Private Function GetDsDCName(ByVal Domainname As String) As String
Dim pInfo As IntPtr
Dim Computername As String = SystemInformation.ComputerName
Dim DomainGuid As guid
Dim ClientSiteName As String = ""
Dim Info As New PDOMAIN_CONTROLLER_INFO
Dim m_LastError As Long
If Exported("netapi32", "DSGetDCNameA") Then
m_LastError = DsGetDcNameA(Computername, Domainname, DomainGuid,
ClientSiteName, DS_DIRECTORY_SERVICE_REQUIRED, Info)
If m_LastError = NO_ERROR Then
Domainname = Info.DomainControllerName
NetApiBufferFreeIntPtr(pInfo)
End If
Else
MsgBox("DSGetDCName is not supported")
End If
End Function
The declare function for DSGetDCNameA is :
Declare Function DsGetDcNameA Lib "netapi32.dll" Alias "DsGetDcNameA" _
(ByVal ComputerName As String, ByVal DomainName As String, ByVal DomainGuid
As Guid, _
ByVal SiteName As String, ByVal Flags As Long, ByRef DomainControllerInfo As
PDOMAIN_CONTROLLER_INFO) As Long
Private Declare Function NetApiBufferFree& Lib "netapi32" _
(ByVal Buffer As Long)
And PDOMAIN_CONTROLLER INFO is a structure, created like this :
Structure PDOMAIN_CONTROLLER_INFO
Public DomainControllerName As String
Public DomainControllerAddress As String
Public DomainControllerAddressType As Long
Public DomainGuid As Guid
Public DomainName As String
Public DnsForestName As String
Public Flags As Long
Public DcSiteName As String
Public ClientSiteName As String
End Structure
The problem I'm having is that during the call
m_LastError = DsGetDcNameA(Computername, Domainname, DomainGuid,
ClientSiteName, DS_DIRECTORY_SERVICE_REQUIRED, Info)
I get the error message mentioned in the subject.
Can anybody point me to the problem? I tried just about anything I can think
of, to no avail... If I get this error correctly, it would suggest that
I didn't instantiate something, but I wouldn't know what. I have declared
all vars before using them to call the function with, as far as I know, I
don't need to create an instance of the function to be able to call it. Or
do I? If so, how do I do that?
Any help is appreciated.
Kurt.
I am trying to get/set Terminal server information in the active directory
on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3,
I need to do it myself.
I'm fairly new to VB.NET, so I need some help.
Here is a code snippit :
Private Function GetDsDCName(ByVal Domainname As String) As String
Dim pInfo As IntPtr
Dim Computername As String = SystemInformation.ComputerName
Dim DomainGuid As guid
Dim ClientSiteName As String = ""
Dim Info As New PDOMAIN_CONTROLLER_INFO
Dim m_LastError As Long
If Exported("netapi32", "DSGetDCNameA") Then
m_LastError = DsGetDcNameA(Computername, Domainname, DomainGuid,
ClientSiteName, DS_DIRECTORY_SERVICE_REQUIRED, Info)
If m_LastError = NO_ERROR Then
Domainname = Info.DomainControllerName
NetApiBufferFreeIntPtr(pInfo)
End If
Else
MsgBox("DSGetDCName is not supported")
End If
End Function
The declare function for DSGetDCNameA is :
Declare Function DsGetDcNameA Lib "netapi32.dll" Alias "DsGetDcNameA" _
(ByVal ComputerName As String, ByVal DomainName As String, ByVal DomainGuid
As Guid, _
ByVal SiteName As String, ByVal Flags As Long, ByRef DomainControllerInfo As
PDOMAIN_CONTROLLER_INFO) As Long
Private Declare Function NetApiBufferFree& Lib "netapi32" _
(ByVal Buffer As Long)
And PDOMAIN_CONTROLLER INFO is a structure, created like this :
Structure PDOMAIN_CONTROLLER_INFO
Public DomainControllerName As String
Public DomainControllerAddress As String
Public DomainControllerAddressType As Long
Public DomainGuid As Guid
Public DomainName As String
Public DnsForestName As String
Public Flags As Long
Public DcSiteName As String
Public ClientSiteName As String
End Structure
The problem I'm having is that during the call
m_LastError = DsGetDcNameA(Computername, Domainname, DomainGuid,
ClientSiteName, DS_DIRECTORY_SERVICE_REQUIRED, Info)
I get the error message mentioned in the subject.
Can anybody point me to the problem? I tried just about anything I can think
of, to no avail... If I get this error correctly, it would suggest that
I didn't instantiate something, but I wouldn't know what. I have declared
all vars before using them to call the function with, as far as I know, I
don't need to create an instance of the function to be able to call it. Or
do I? If so, how do I do that?
Any help is appreciated.
Kurt.