如何获取服务器端的硬盘号,谢谢
解决方案 »
- ASP.Net中上传图片怎么让上传的图片显示在另一个界面中以便管理?
- 非主线程里如何更新控件
- 统计页面PV(访问次数)的问题
- 静态变量 静态对象 静态函数和非静态函数的区别。(我的理解,大家看看对不对)
- 100 关于验证的问题????????????????
- web服务器上xml文件的压力问题.
- asp.net 遇到客户要求表格比较长怎么排版?请求帮助。
- 我发了个外包项目,因为是个人,钱不多,但现在有人接了,我要查看他的资料,系统说要收500块
- 一个紧急问题
- 关于DataGrid的一个问题
- 现在我对Excel文件进行操作,但Excel文件里有两张工作表,我现在操作的只是第一张,如果想操作操作第二张怎么办?
- 小弟要转业了,给点意见吧
using System;
using System.Management;
using System.Collections;
using System.Collections.Specialized;
namespace ACE_Console
{
class ACE_Console
{
[STAThread]
static void Main(string[] args)
{
StringCollection propNames = new StringCollection();
ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
PropertyDataCollection props = driveClass.Properties;
foreach (PropertyData driveProperty in props)
{
propNames.Add(driveProperty.Name);
}
int idx = 0;
ManagementObjectCollection drives = driveClass.GetInstances();
foreach (ManagementObject drv in drives)
{
Console.WriteLine(" Drive({0}) Properties ", idx+1);
foreach (string strProp in propNames)
{
Console.WriteLine("Property: {0}, Value: {1}", strProp, drv[strProp]);
}
}
}
}
}
[C#]using System;using System.Management; // This example demonstrates getting information about a class using the ManagementClass objectclass Sample_ManagementClass{ public static int Main(string[] args) { ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk"); diskClass.Get(); Console.WriteLine("Logical Disk class has " + diskClass.Properties.Count + " properties"); return 0; }}
Imports SystemImports System.Management // This example demonstrates getting information about a class using the ManagementClass Class Sample_ManagementClass
Overloads Public Shared Function Main(args() As String) As IntegerDim diskClass As New ManagementClass("Win32_LogicalDisk")diskClass.Get()Console.WriteLine(("Logical Disk class has " & diskClass.Properties.Count.ToString() & " properties"))Return 0End FunctionEnd Class
http://blog.csdn.net/iwebsms/archive/2004/10/06/126397.aspx
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();
}
}
}