Click here to Skip to main content
15,886,736 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i am trying to identify workstations in network. what are the possible way to identify workstations using c#.



Thanks,
Arshad
Posted

1 solution

i have got the answer:
C#
using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\\CIMV2", 
                    "SELECT * FROM Win32_OperatingSystem WHERE ProductType = 2"); 

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_OperatingSystem instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("ProductType: {0}", queryObj["ProductType"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}


ProductType maps to below table :
Value =Meaning
1 = Work Station
2 = Domain Controller
3 = Server


http://msdn.microsoft.com/en-us/library/windows/desktop/aa394239%28v=vs.85%29.aspx[^]


Thanks,
Arshad
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900