How to get workgroup of the computer?

hello

i want to get workgroup of the computer without using unmanaged code

i try this

System.Environment.UserDomainName

but its giving me the COMPUTER NAME not the workgroup ... is there any way to find out using System.NET or WMI

 

thanx any way ..

 



Answer this question

How to get workgroup of the computer?

  • Big_Al

    Try this, or something like it:

    My.Computer.Registry.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\Tcpip\Parameters\", False).GetValue("Domain")


  • false420

    You are sure you are not joined to a domain

  • viki

    If that doesn't work, you should be able to use the WMI tools in the System.Management namespace (located in system.management.dll).

    sample code.


    SelectQuery query = new SelectQuery("Win32_ComputerSystem");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

    foreach (ManagementObject mo in searcher.Get())
    {
         workGroupName = mo[
    "Workgroup"] as string;
    }


     



  • smartinz

    I do not beleive there is a way to get this information using System.Net.

  • Little Shell

    Both examples don't want to work in my application. Result is null.Maybe there is another way to get workgroup
  • How to get workgroup of the computer?