Solved

Get workgroup name(s) in LAN

Posted on 2004-05-03
9
1,207 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FInd Image Control Gridview 3 37
VB.Net. Reading xml value 6 38
vb.net background worker crossthread 11 30
vb.net datagrid point 4 22
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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