I want to get the seriel number of the local hardrive, now I know some people are going to say this is not possible and client side vs server side, But i read this post and it seems this person got it to work.
Now when I try and implement this in Visual Studio 2010, I cannot find the "ManagementObject". I am using the System.Management; in my code as you can see. All I want to do is get the c: drive seriel number when my app is loaded in the browser of that computer.
The code below gets the PC NAME and the MAC ADDRESS, all I need now is the c:\ drive seriel number.
using System;
using System.Management;
using System.Net;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Blueprints.PC_Name_MacAddress
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//get the computer name
string pc_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;
//get the computers mac address
string mac_addr = GetMACAddress();
//print the pc name and mac address to the screen
Response.Write("pc_name :- " + pc_name + "------" + "Mac Addr :- " + mac_addr);
Response.Write(HardDiskSerialNumber(""));
}
//get the mac address of the client
public string GetMACAddress()
{
System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (System.Net.NetworkInformation.NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty) // only return MAC Address from first card
{
System.Net.NetworkInformation.IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
} return sMacAddress;
}
public string HardDiskSerialNumber(string driveName)
{
if (driveName == "" || driveName == null)
{
driveName = "C";
}
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + driveName +":\"");
disk.Get();
}
}
}
Remember to click “Mark as Answer” on the post, if it helps you. Because It helps others to find the solution
You can only get information of the server. Never the clients.
The client could be a Macintosh, a Linus box, a mobile device...which do not have .Net stuff installed. And, it would be a huge security violation to allow websites access to a client machine's hardware.
I can totaly understand what you mean, but I am trying to find ways to authenticate users of my application. Like if there computer is not registered to use this application then it must prompt them to register.
Remember to click “Mark as Answer” on the post, if it helps you. Because It helps others to find the solution
so how did the person in this post get this to work?
He may have gotten it to compile but it is not getting information from the client machines. Authenticating users is usually done with the good-old-fashioned name/password paradigm.
Nivash
Participant
1542 Points
409 Posts
Visual Studio 2010, I cannot find the "ManagementObject".
Sep 02, 2010 11:21 AM|LINK
Hi
I want to get the seriel number of the local hardrive, now I know some people are going to say this is not possible and client side vs server side, But i read this post and it seems this person got it to work.
http://forums.asp.net/t/46697.aspx
Now when I try and implement this in Visual Studio 2010, I cannot find the "ManagementObject". I am using the System.Management; in my code as you can see. All I want to do is get the c: drive seriel number when my app is loaded in the browser of that computer. The code below gets the PC NAME and the MAC ADDRESS, all I need now is the c:\ drive seriel number.
using System; using System.Management; using System.Net; using System.Collections; using System.Collections.Specialized; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Blueprints.PC_Name_MacAddress { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //get the computer name string pc_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName; //get the computers mac address string mac_addr = GetMACAddress(); //print the pc name and mac address to the screen Response.Write("pc_name :- " + pc_name + "------" + "Mac Addr :- " + mac_addr); Response.Write(HardDiskSerialNumber("")); } //get the mac address of the client public string GetMACAddress() { System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); String sMacAddress = string.Empty; foreach (System.Net.NetworkInformation.NetworkInterface adapter in nics) { if (sMacAddress == String.Empty) // only return MAC Address from first card { System.Net.NetworkInformation.IPInterfaceProperties properties = adapter.GetIPProperties(); sMacAddress = adapter.GetPhysicalAddress().ToString(); } } return sMacAddress; } public string HardDiskSerialNumber(string driveName) { if (driveName == "" || driveName == null) { driveName = "C"; } ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + driveName +":\""); disk.Get(); } } }SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: Visual Studio 2010, I cannot find the "ManagementObject".
Sep 02, 2010 12:51 PM|LINK
You can only get information of the server. Never the clients.
The client could be a Macintosh, a Linus box, a mobile device...which do not have .Net stuff installed. And, it would be a huge security violation to allow websites access to a client machine's hardware.
My blog
Nivash
Participant
1542 Points
409 Posts
Re: Visual Studio 2010, I cannot find the "ManagementObject".
Sep 02, 2010 12:58 PM|LINK
so how did the person in this post get this to work? http://forums.asp.net/t/46697.aspx
I can totaly understand what you mean, but I am trying to find ways to authenticate users of my application. Like if there computer is not registered to use this application then it must prompt them to register.
SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: Visual Studio 2010, I cannot find the "ManagementObject".
Sep 02, 2010 02:20 PM|LINK
He may have gotten it to compile but it is not getting information from the client machines. Authenticating users is usually done with the good-old-fashioned name/password paradigm.
My blog