1.c#中怎样获得硬盘卷标?
2.如果用UserHostAddress,得到的是客户端的Ip,问题是如果是通过公共上网,假设一台服务器连的是外部ADSL,里面又通过路由有10台机器上网,那用UserHostAddress得到的是ADSL的ip,还是客户端的Ip呢?
2.如果用UserHostAddress,得到的是客户端的Ip,问题是如果是通过公共上网,假设一台服务器连的是外部ADSL,里面又通过路由有10台机器上网,那用UserHostAddress得到的是ADSL的ip,还是客户端的Ip呢?
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;namespace Wjb.ReadOrWriteIniAndReg
{
/// <summary>
/// HardDiskVal 的摘要说明。
/// 读取指定盘符的硬盘序列号
/// 功能:读取指定盘符的硬盘序列号
/// </summary>
public class HardDiskVal
{
[DllImport("kernel32.dll")]
private static extern int GetVolumeInformation( string lpRootPathName, string lpVolumeNameBuffer, int nVolumeNameSize, ref int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags, string lpFileSystemNameBuffer, int nFileSystemNameSize ); /// <summary> /// 获得盘符为drvID的硬盘序列号,缺省为C /// </summary> /// <param name="drvID"></param> /// <returns></returns> public string HDVal(string drvID) { const int MAX_FILENAME_LEN = 256; int retVal = 0; int a =0; int b =0; string str1 = null; string str2 = null; int i = GetVolumeInformation( drvID + @":\", str1, MAX_FILENAME_LEN, ref retVal, a, b, str2, MAX_FILENAME_LEN ); return retVal.ToString(); } public string HDVal() { const int MAX_FILENAME_LEN = 256; int retVal = 0; int a =0; int b =0; string str1 = null; string str2 = null; int i = GetVolumeInformation( "c:\\", str1, MAX_FILENAME_LEN, ref retVal, a, b, str2, MAX_FILENAME_LEN ); return retVal.ToString(); } } }第二个问题,我没作过,你可以试验一下,就知道答案了啊
序列号的取得可以看这个文章,很长,不便贴出来,出处:http://www.265it.com/ArticleShow.aspx?Qarea=30&Tid=208&Qtype=119
using System.Management;
...
...
ManagementObject mo=new ManagementObject("Win32_LogicalDisk.DeviceID=\"C:\"");
string serialno=mo["VolumeSerialNumber"].ToString();