Finding out what network I'm connected to

I need to find out the name of the NETWORK that this computer is connected to. The NETWORK ... NOT

REPEAT

****NOT****

^^^^^^^^^^^^^ NOT NOT NOT NOT NOT NOT NOT ....


.... the domain name.


My PC has not joined the domain. As a result, when I use things like Environment.UserDomainName I get my PC's own name, and ActiveDirectory functions throw errors.

solutions preferably in VB.NET but C# is acceptable
LVL 4
WernerVonBraunAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Do you mean the Workgroup name?  That's the only name any of my networks have since I don't have ActiveDirectory at all.
0
Dave BaldwinFixer of ProblemsCommented:
0
WernerVonBraunAuthor Commented:
Nope.

Ok - move your mouse down to the notifications area and hover it over the network icon.

It'll pop up something like

nameofsomenetwork
internet access

unidentified network
no internet access


and so on. I want to read "nameofsomenetwork" and "unidentified network"
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Dave BaldwinFixer of ProblemsCommented:
Those would be wireless networks.  I forgot that they have names.  I don't have any wireless running at the moment.
0
WernerVonBraunAuthor Commented:
Yeah. Or LAN connections. :-)
0
WernerVonBraunAuthor Commented:
ugh - so .... I loop through all connections:

For Each oAd As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces

I could get IP properties:
Dim oIPInt As System.Net.NetworkInformation.IPInterfaceProperties = oAd.GetIPProperties()

But then what? That may give me DNS addresses or whatnot, but they're all IP addresses. How do I get "nameofsomenetwork" out of that - or ANY name of any machine corresponding to what GetIPProperties returns?
0
WernerVonBraunAuthor Commented:
Even if I could get the "Connection-specific DNS Suffix" as you'd get when you run IPCONFIG in a command prompt, I'd be happy
0
frankhelkCommented:
I don't have an example at hand, but I'll try to point the way (even while it is not very elegant):

Spawn "ipconfig.exe /all" as command line process with the Shell() command (or via a Process class object) and redirect the output into a file or a buffer string etc.

Spawning by the Process class would look like this:
Dim myProcess As Process = New Process()
        Dim StringBuffer As String
        Dim CMD_Encoding As Encoding
        Dim Sys_Encoding As Encoding
        Dim StdOut As String
        Dim Path As String = My.Application.Info.DirectoryPath
        Dim ExitCode As Boolean = False
        Dim ref As DateTime

        myProcess.EnableRaisingEvents = False
        myProcess.StartInfo.RedirectStandardOutput = True
        myProcess.StartInfo.RedirectStandardError = True
        myProcess.StartInfo.UseShellExecute = False
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.StartInfo.Arguments = "/all"
        myProcess.StartInfo.FileName = "ipconfig.exe"
        myProcess.Start()

Open in new window

(After execution, StandardOutput and StandardError contents could the be found in the repective properties of the myProcess object)

Parse the output line by line for the desired info.

When using Shell(), calling would be a bit more simple, but catching the output would be (a bit) more complicated.
0
WernerVonBraunAuthor Commented:
gawd that's ugly BUT .... if nothing more elegant is presented here the poinks will be yours.
0
frankhelkCommented:
Thanks for the compliments ... ;-)

Please be aware that the example code is just quick-ripped out of some of my code and has not been tested - it's more of a concept. This explains why there are variables declared but not used (sorry ... forgot to rip them out and can't edit anymore). Maybe there are more subtle things I forgot to include ... but at least it's part of code that works well ...
0
WernerVonBraunAuthor Commented:
Don't worry about that - I'll clean it up all nice and pretty [grin]
0
CodeCruiserCommented:
I think you are after the network profiles which can be found in registry at

HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkList
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WernerVonBraunAuthor Commented:
Ok CodeCruiser, I think you're on to something there. I'm especially interested in the key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles

Between the ProfileName and the DateLastConnected I think I'll be able to get the information I need.
0
WernerVonBraunAuthor Commented:
Thank you both!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.