|
| ||||||||||
| Tags: domain name, full domain, vbnet, visual basic |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How do I get the full domain name in VB.NET
Code: Public Class MyForm Inherits System.Web.UI.Page
#MyCode "My Generated Code"
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents txtDomain As System.Web.UI.WebControls.TextBox
Protected WithEvents lblName As System.Web.UI.WebControls.Label
Protected WithEvents btnRefresh As System.Web.UI.WebControls.Button
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
#End MyCode
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtDomain.Text = "Test"
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
txtDomain.Text = System.Environment.GetEnvironmentVariable("USERDNSDOMAIN")
End Sub
End Class |
|
#2
| |||
| |||
| Re: How do I get the full domain name in VB.NET
You missed out to add system.management reference. Code: Imports System.Management
Module MyModule
Sub Main()
Using objSearch As New ManagementObjectSearcher(New SelectQuery("Win32_ComputerSystem"))
For Each mngtObj As ManagementObject In searcher.[Get]()
Dim myDomainName As String = String.Format("{0}.{1}", mngtObj("name"), If(CBool(mngtObj("partofdomain")), mngtObj("domain"), mngtObj("workgroup")))
Console.WriteLine(myDomainName)
Exit For
Next
End Using
End Sub
End Module |
|
#3
| ||||
| ||||
| Re: How do I get the full domain name in VB.NET
A better idea would be: Code: Public Function GetCompInfo() As Boolean
Dim objSearch As ManagementObjectSearcher
Dim objCollection As ManagementObjectCollection
Dim sqlCommand As String = "SELECT * FROM Win32_ComputerSystem"
Dim mngtScope As ManagementScope = New ManagementScope("root\cimv2")
Dim newQuery As SelectQuery = New SelectQuery(sqlCommand)
objSearch = New ManagementObjectSearcher(mngtScope, newQuery)
objCollection = objSearch.Get()
Dim mngtObject As ManagementObject
For Each management_object In objCollection
Console.WriteLine(mngtObject("Domain") + "\" + mngtObject("Name"))
Next mngtObject
Return True
End Function |
|
#4
| |||
| |||
| Re: How do I get the full domain name in VB.NET
Thank you for your suggestions. I tried all that changing it based on my software. CitricAcid, I am unable to let my Visual Studio understand the using function but always I end up with build error. However I tried something different as below: Code: Private Function myDomainName()
Dim ipHost as System.Net.IPHostEntry = System.Net.Dns.Resolve("SERVER")
Dim domainName As String = ipHost.hostname
Return domainName
End Function |
|
#5
| |||
| |||
| Re: How do I get the full domain name in VB.NET
Here is a slight modification to your code which is required according to me: Code: Dim getHostName As String = System.Net.Dns.GetHostName
Private Function myDomainName()
Dim getHostName As String = System.Net.Dns.GetHostName
Dim ipHost as System.Net.IPHostEntry = System.Net.Dns.Resolve(getHostName)
Dim domainName As String = ipHost.hostname
Return domainName
End Function |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How do I get the full domain name in VB.NET" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An active directory Domain Controller for the domain could not becontacted in windows vista Business | CheyeNnne | Active Directory | 7 | 28-12-2010 09:05 PM |
| I have got two domain, I can't ping FQDN, Domain name but not the hostname of the other domain | kaikoa | Networking & Security | 1 | 16-09-2009 10:11 AM |
| Migrate users from Existing Windows 2003 Domain to new 2008 Domain | Lupin | Active Directory | 3 | 09-07-2009 05:57 PM |
| Canon EOS 5D Mark II 21.1 megapixel with Full-Frame, Full-HD video | JamesMK | Portable Devices | 1 | 17-09-2008 01:11 PM |
| Child domain user does not show parent domain group membership | Pratim | Active Directory | 1 | 19-06-2008 01:58 AM |