SoFunction
Updated on 2025-03-07

C# to obtain client-related information example summary

This article describes the method of obtaining client-related information in C#. Share it for your reference. The details are as follows:

【Native IP address】

The first method:

IPHostEntry hostentry = (());
IPAddress address=[0];

The second method:

Copy the codeThe code is as follows:
(())[0].ToString();

【Direction whether the current user is connected to the Internet】

PingReply reply = new Ping().Send(address);
if ( == )
 ("Ping successfully.");
else
 ("Ping failure.");

【Get the current client hard drive letter】

Copy the codeThe code is as follows:
string[] mydrivers = ();

【Judge client mobile hard disk and hard disk】
SelectQuery select = new SelectQuery("select * from win32_logicaldisk");
ManagementObjectSearcher mos = new ManagementObjectSearcher(select);
foreach (ManagementObject disk in ())
{
  string msg = disk["Name"].ToString();
  DriveInfo info = new DriveInfo(msg);
  switch (())
  {
   case "Unknown":
     += msg + "This is an unknown device__";
    break;
   case "NoRootDirectory":
     += msg + "This is unpartitioned__";
    break;
   case "Removable":
     += msg + "This is a moving disk__";
    break;
   case "Fixed":
     += msg + "This is a hard drive__";
    break;
   case "Network":
     += msg + "This is a network drive__";
    break;
   case "CDRom":
     += msg + "This is an optical drive__";
    break;
  }
}

【Get the current displayed length and width】
Width:

Copy the codeThe code is as follows:

long:
Copy the codeThe code is as follows:

【Get client process information】

Copy the codeThe code is as follows:
[] processes = ();

【Close process information】
foreach ( p in processes)
{
  if ( == "IntelliTrace")
  {
   ();
  }
}

【Direction whether the client has a sound card installed】

[DllImport("", EntryPoint = "waveOutGetNumDevs")]
public static extern int waveOutGetNumDevs();
private void button1_Click(object sender, EventArgs e)
{
 if (waveOutGetNumDevs() != 0)
 {
  ("Sound card installed");
 }
 else {
  ("No sound card installed");
 }
}

【Get computer name and current logged-in user】
Computer name:

Copy the codeThe code is as follows:
();

Current logged in user:
Copy the codeThe code is as follows:
("UserName");

I hope this article will be helpful to everyone's C# programming.