D
Dim_User_As_Jim
Guest
Heres a working code for my environment.
1. Bind the rootdse and ask for the defaultnamingcontext, which will give us the domain where we are. (dc=corporation,dc=com).
2. Get the logonserver where logged in via Wscript.shell
-----------
the defaultnamingcontext is splitted and parsed together to get corporation.com for the purpose of ping
finally all this combined and we have a ping for servername.corporation.com and we can output the results (or use them somewhere else)
1. Bind the rootdse and ask for the defaultnamingcontext, which will give us the domain where we are. (dc=corporation,dc=com).
2. Get the logonserver where logged in via Wscript.shell
-----------
the defaultnamingcontext is splitted and parsed together to get corporation.com for the purpose of ping
finally all this combined and we have a ping for servername.corporation.com and we can output the results (or use them somewhere else)
Code:
Dim root As IADs
Dim oShell, sServer
root = GetObject("LDAP://RootDSE")
oShell = CreateObject("Wscript.Shell")
sServer = oShell.Environment("Process").Item("LogonServer")
oShell = Nothing
MessageBox.Show(root.Get("defaultNamingContext")) returns: "dc=corporation,dc=com"
Dim cut, cut2
Dim whole As String
cut = Split(root.Get("defaultNamingContext"), ",") after this we have "dc=corporation" and "dc=com"
cut2 = Split(cut(0), "=")
whole = cut2(1) for the final we have now "corporation"
cut2 = Split(cut(1), "=")
whole &= "." & cut2(1) and now "corporation.com"
cut = Nothing
cut2 = Nothing
Dim DCIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(Microsoft.VisualBasic.Right(sServer, sServer.length - 2) & "." & whole)
Dim IP As String = CType(DCIP.AddressList.GetValue(0), System.Net.IPAddress).ToString
MessageBox.Show("Connected to: " & Microsoft.VisualBasic.Right(sServer, sServer.length - 2) & " (" & IP & ").")