Solved

Get workgroup name(s) in LAN

Posted on 2004-05-03
9
1,167 Views
Last Modified: 2012-06-27
I have been searching the internet for 2 days now, and I can't find any good line(s) of code about how to retrieve the workgroup name I am connected to. Or even better: getting all workgroups within the local network (LAN). I am using Windows XP (Home edition) but it would be nice if it works for all versions of windows.

Code should be in VB.Net !

Thanks
0
Comment
Question by:DubbleEagle
  • 5
  • 3
9 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 10976131
0
 

Author Comment

by:DubbleEagle
ID: 10976170
Ronald, I have seen this topic before, and I got some problems testing it. If I insert the code in VB.Net, I get some errors, including the line

Dim wshShell As New IWshShell_Class

which is (in my opinion) part of the code for retrieving a registry value. IWshShell_Class is not known by my compiler (maybe I should add a reference?).

Also, if I check my registry (via regedit), I cannot find the subdirectory "VDX" in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\

Maybe usefull information (?): I am using Visual Studio .Net 2003 Professional
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 10976468
Imports System
Imports System.Security

Private Function GetUserName() As String
        Return Principal.WindowsIdentity.GetCurrent.Name()
        ' This will return 'domain(or workgroup)\username' so just parse the Info
    End Function
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 10976562
0
 

Author Comment

by:DubbleEagle
ID: 10976582
I tried the code you suggested (with msgbox() instead of return), but it gives me the following information:

"Computername/CurrentUserName"

The name of the workgroup is not listed  :(
0
 

Author Comment

by:DubbleEagle
ID: 10976602
I'll try out that topic, and will let you know if it worked  :-)
0
 

Author Comment

by:DubbleEagle
ID: 10976713
Ok, I tried everything listed there. Good thing is: I don't need the workgroup name to get all workstations/servers from the network. Bad thing is, that I still can't get the name of the workgroup I'm connected to.

I would like to create a tree-structure of all workgroups, with all computers connected to them (like windows-explorer: my-network-connections, microsoft-windows-network  -  from there, you get a tree view of the entire network)

If that shouldn't be possible, at least I would like to retrieve the name of my workgroup
0
 
LVL 41

Accepted Solution

by:
graye earned 250 total points
ID: 10977075
To get the current workgroup (or domain) that you're connected to, you can use a combination of WMI and poking around the registry.  Here is a chunk of code to demonstrate (not a complete application)

                Dim wmi As ManagementClass
                Dim objs As ManagementObjectCollection
                Dim obj As ManagementObject
                Dim reg, key, subkey As Microsoft.Win32.RegistryKey
                Dim Domain As String

                ' let's make sure you're "one of us"
                Try
                    wmi = New ManagementClass("Win32_ComputerSystem")
                    objs = wmi.GetInstances()
                    For Each obj In objs
                        ' "PartOfDomain" is unreliable for Win9x
                        If IsNothing(obj("DomainRole")) Then
                            reg = Microsoft.Win32.Registry.LocalMachine
                            key = reg.OpenSubKey("System\CurrentControlSet\Services\VxD\VNETSUP", False)
                            If Not IsNothing(key) AndAlso Not IsNothing(key.GetValue("Workgroup")) Then
                                Domain = key.GetValue("Workgroup").ToString.ToUpper
                                key.Close()
                            End If
                        Else
                            Domain = obj("Domain")
                        End If
                    Next
                    objs.Dispose()
                    wmi.Dispose()
                Catch e As Exception
                    ' Hey, if this simple probing doesn't work.. then forget it
                    ErrorLog(e)
                    Exit Sub
                End Try

But to get the list of other Workgroups/Domains that are available on your local LAN... that take a wee bit more work.  There are no .Net framework tools for this function, so you're stuck with using the APIs.   Those examples are a bit big to post here...



0
 

Author Comment

by:DubbleEagle
ID: 10978651
Thnx, this works perfect!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question