怎么样能得到局域网里一台机器上的硬盘号????????????????/
http://blog.sunmast.com/sunmast/articles/1003.aspx这个网页挂了。现在指向哪了。有人知道不

解决方案 »

  1.   

    硬盘序列号(Serial Number)不等于卷标号(Volume Name),后者虽然很容易得到,但是格式化分区后就会重写,不可靠。遗憾的是很多朋友往往分不清这一点。要得到硬盘的物理序列号,可以通过WMI,也就是Win32_PhysicalMedia.SerialNumber。可惜的是Windows 98/ME的WMI并不支持这个类,访问时会出现异常。
      

  2.   

    下面是全部代码
    using System;
    using System.Runtime.InteropServices;
    using System.Text;namespace Sunmast.Hardware
    {
    [Serializable]
    public struct HardDiskInfo
    {
    /// <summary>
    /// 型号
    /// </summary>
    public string ModuleNumber;
    /// <summary>
    /// 固件版本
    /// </summary>
    public string Firmware;
    /// <summary>
    /// 序列号
    /// </summary>
    public string SerialNumber;
    /// <summary>
    /// 容量,以M为单位
    /// </summary>
    public uint Capacity;
    } #region Internal Structs [StructLayout(LayoutKind.Sequential, Pack=1)]
    internal struct GetVersionOutParams
    {
    public byte bVersion;
    public byte bRevision;
    public byte bReserved;
    public byte bIDEDeviceMap;
    public uint fCapabilities;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
    public uint[] dwReserved; // For future use.
    } [StructLayout(LayoutKind.Sequential, Pack=1)]
    internal struct IdeRegs
    {
    public byte bFeaturesReg;
    public byte bSectorCountReg;
    public byte bSectorNumberReg;
    public byte bCylLowReg;
    public byte bCylHighReg;
    public byte bDriveHeadReg;
    public byte bCommandReg;
    public byte bReserved;
    } [StructLayout(LayoutKind.Sequential, Pack=1)]
    internal struct SendCmdInParams
    {
    public uint cBufferSize;
    public IdeRegs irDriveRegs;
    public byte bDriveNumber;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=3)]
    public byte[] bReserved;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
    public uint[] dwReserved;
    public byte bBuffer;
    } [StructLayout(LayoutKind.Sequential, Pack=1)]
    internal struct DriverStatus
    {
    public byte bDriverError;
    public byte bIDEStatus;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
    public byte[] bReserved;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
    public uint[] dwReserved;
    } [StructLayout(LayoutKind.Sequential, Pack=1)]
    internal struct SendCmdOutParams
    {
    public uint cBufferSize;
    public DriverStatus DriverStatus;
    public IdSector bBuffer;
    } [StructLayout(LayoutKind.Sequential, Pack=1, Size=512)]
    internal struct IdSector
    {
    public ushort wGenConfig;
    public ushort wNumCyls;
    public ushort wReserved;
    public ushort wNumHeads;
    public ushort wBytesPerTrack;
    public ushort wBytesPerSector;
    public ushort wSectorsPerTrack;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=3)]
    public ushort[] wVendorUnique;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=20)]
    public byte[] sSerialNumber;
    public ushort wBufferType;
    public ushort wBufferSize;
    public ushort wECCSize;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
    public byte[] sFirmwareRev;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=40)]
    public byte[] sModelNumber;
    public ushort wMoreVendorUnique;
    public ushort wDoubleWordIO;
    public ushort wCapabilities;
    public ushort wReserved1;
    public ushort wPIOTiming;
    public ushort wDMATiming;
    public ushort wBS;
    public ushort wNumCurrentCyls;
    public ushort wNumCurrentHeads;
    public ushort wNumCurrentSectorsPerTrack;
    public uint ulCurrentSectorCapacity;
    public ushort wMultSectorStuff;
    public uint ulTotalAddressableSectors;
    public ushort wSingleWordDMA;
    public ushort wMultiWordDMA;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=128)]
    public byte[] bReserved;
    } #endregion
      

  3.   

    /// <summary>
    /// ATAPI驱动器相关
    /// </summary>
    public class AtapiDevice
    { #region DllImport [DllImport("kernel32.dll", SetLastError=true)]
    static extern int CloseHandle(IntPtr hObject); [DllImport("kernel32.dll", SetLastError=true)]
    static extern IntPtr CreateFile(
    string lpFileName,
    uint dwDesiredAccess,
    uint dwShareMode,
    IntPtr lpSecurityAttributes,
    uint dwCreationDisposition,
    uint dwFlagsAndAttributes,
    IntPtr hTemplateFile); [DllImport("kernel32.dll")]
    static extern int DeviceIoControl(
    IntPtr hDevice,
    uint dwIoControlCode,
    IntPtr lpInBuffer,
    uint nInBufferSize,
    ref GetVersionOutParams lpOutBuffer,
    uint nOutBufferSize,
    ref uint lpBytesReturned,
    [Out] IntPtr lpOverlapped); [DllImport("kernel32.dll")]
    static extern int DeviceIoControl(
    IntPtr hDevice,
    uint dwIoControlCode,
    ref SendCmdInParams lpInBuffer,
    uint nInBufferSize,
    ref SendCmdOutParams lpOutBuffer,
    uint nOutBufferSize,
    ref uint lpBytesReturned,
    [Out] IntPtr lpOverlapped); const uint DFP_GET_VERSION = 0x00074080;
    const uint DFP_SEND_DRIVE_COMMAND = 0x0007c084;
    const uint DFP_RECEIVE_DRIVE_DATA = 0x0007c088; const uint GENERIC_READ = 0x80000000;
    const uint GENERIC_WRITE = 0x40000000;
    const uint FILE_SHARE_READ = 0x00000001;
    const uint FILE_SHARE_WRITE = 0x00000002;
    const uint CREATE_NEW = 1;
    const uint OPEN_EXISTING = 3; #endregion #region GetHddInfo /// <summary>
    /// 获得硬盘信息
    /// </summary>
    /// <param name="driveIndex">硬盘序号</param>
    /// <returns>硬盘信息</returns>
    /// <res>
    /// 参考lu0的文章:http://lu0s1.3322.org/App/2k1103.html
    /// by sunmast for everyone
    /// thanks lu0 for his great works
    /// 在Windows 98/ME中,S.M.A.R.T并不缺省安装,请将SMARTVSD.VXD拷贝到%SYSTEM%\IOSUBSYS目录下。
    /// 在Windows 2000/2003下,需要Administrators组的权限。
    /// </res>
    /// <example>
    /// AtapiDevice.GetHddInfo()
    /// </example>
    public static HardDiskInfo GetHddInfo(byte driveIndex)
    {
    switch(Environment.OSVersion.Platform)
    {
    case PlatformID.Win32Windows:
    return GetHddInfo9x(driveIndex);
    case PlatformID.Win32NT:
    return GetHddInfoNT(driveIndex);
    case PlatformID.Win32S:
    throw new NotSupportedException("Win32s is not supported.");
    case PlatformID.WinCE:
    throw new NotSupportedException("WinCE is not supported.");
    default:
    throw new NotSupportedException("Unknown Platform.");
    }
    } #region GetHddInfo9x private static HardDiskInfo GetHddInfo9x(byte driveIndex)
    {
    GetVersionOutParams vers = new GetVersionOutParams();
    SendCmdInParams inParam = new SendCmdInParams();
    SendCmdOutParams outParam = new SendCmdOutParams();
    uint bytesReturned = 0; IntPtr hDevice = CreateFile(
    @"\\.\Smartvsd",
    0,
    0,
    IntPtr.Zero,
    CREATE_NEW,
    0,
    IntPtr.Zero);
    if (hDevice == IntPtr.Zero)
    {
    throw new Exception("Open smartvsd.vxd failed.");
    }
    if (0 == DeviceIoControl(
    hDevice,
    DFP_GET_VERSION,
    IntPtr.Zero,
    0,
    ref vers,
    (uint)Marshal.SizeOf(vers),
    ref bytesReturned,
    IntPtr.Zero))
    {
    CloseHandle(hDevice);
    throw new Exception("DeviceIoControl failed:DFP_GET_VERSION");
    }
    // If IDE identify command not supported, fails
    if (0 == (vers.fCapabilities & 1))
    {
    CloseHandle(hDevice);
    throw new Exception("Error: IDE identify command not supported.");
    }
    if (0 != (driveIndex & 1))
    {
    inParam.irDriveRegs.bDriveHeadReg = 0xb0;
    }
    else
    {
    inParam.irDriveRegs.bDriveHeadReg = 0xa0;
    }
    if (0 != (vers.fCapabilities & (16 >> driveIndex)))
    {
    // We don't detect a ATAPI device.
    CloseHandle(hDevice);
    throw new Exception(string.Format("Drive {0} is a ATAPI device, we don't detect it",driveIndex + 1));
    }
    else
    {
    inParam.irDriveRegs.bCommandReg = 0xec;
    }
    inParam.bDriveNumber = driveIndex;
    inParam.irDriveRegs.bSectorCountReg = 1;
    inParam.irDriveRegs.bSectorNumberReg = 1;
    inParam.cBufferSize = 512;
    if (0 == DeviceIoControl(
    hDevice,
    DFP_RECEIVE_DRIVE_DATA,
    ref inParam,
    (uint)Marshal.SizeOf(inParam),
    ref outParam,
    (uint)Marshal.SizeOf(outParam),
    ref bytesReturned,
    IntPtr.Zero))
    {
    CloseHandle(hDevice);
    throw new Exception("DeviceIoControl failed: DFP_RECEIVE_DRIVE_DATA");
    }
    CloseHandle(hDevice); return GetHardDiskInfo(outParam.bBuffer);
    } #endregion
      

  4.   

    #region GetHddInfoNT private static HardDiskInfo GetHddInfoNT(byte driveIndex)
    {
    GetVersionOutParams vers = new GetVersionOutParams();
    SendCmdInParams inParam = new SendCmdInParams();
    Sen</span>
                    </td>
                  </tr>
      <tr>
        <td>
              <div><span class="unnamed3"><table bgcolor=#FFFFFF><form action=/html/4/39487.htm method=post name=REG><tr><td><br><input type=hidden name=act value=Reg><input type="hidden" name="regid" value="53c3cea9978c176025528368e6fa5908"><fieldset class="Text2"><legend><b>验证码确认</b></legend><table cellspacing=0><tr><td width=1%>确认验证码<div class=Text2>请输入图片上的 6 位数字.</div><input type=text size=25 maxlength=32 name=reg_code></td><td align=center><img src="http://www.zahui.com/show_image.php?rc=53c3cea9978c176025528368e6fa5908"></td></tr></table></td></tr><tr><td><input type=submit value="提交验证查看全部文章"></td></tr></form></table></span></div>
                    </td>
                  </tr>
                </table>
                <table width="100%" border="0" cellpadding="9" cellspacing="0" align="center" bgcolor="#FFFFFF">
                  <tr>
                    <td><span class="unnamed2"><table><tr><td><fieldset class="Text2"><legend><b>相关文章</b></legend><a href= http://www.zahui.com/html/4/39477.htm>在Asp.Net中使用SmtpMail发送邮件的方法</a><br><a href= http://www.zahui.com/html/4/39478.htm>利用Cache存储访问记录,然后每隔一段时间写入数据库。</a><br><a href= http://www.zahui.com/html/4/39479.htm>关于ASP访问ACCESS数据的“不能打开注册表关键字”80004005错误的探讨</a><br><a href= http://www.zahui.com/html/4/39480.htm>学习的asp.net的办法 [转论坛]</a><br><a href= http://www.zahui.com/html/4/39481.htm>取时一个时间的年月日+调用CSS用link,调用JS用script,调用ASP用include+表格变色效果</a><br><a href= http://www.zahui.com/html/4/39482.htm>超链接的文字说明+链接打开确定大小和样式页面</a><br><a href= http://www.zahui.com/html/4/39483.htm>加快 DHTML 的一组技巧(zt)</a><br><a href= http://www.zahui.com/html/4/39484.htm>找不到好的方法,如何通过HttpWebRequest获取页面的Encoding。(转)</a><br><a href= http://www.zahui.com/html/4/39485.htm>Serialize the world?</a><br><a href= http://www.zahui.com/html/4/39486.htm>.NET程序内,访问私有或者保护成员的技巧</a><br><a href= http://www.zahui.com/html/4/39488.htm>Visual Studio.Net如何使用CVS管理源代码</a><br><a href= http://www.zahui.com/html/4/39489.htm>用javascript获取传入参数</a><br><a href= http://www.zahui.com/html/4/39490.htm>利用CSS控制打印</a><br><a href= http://www.zahui.com/html/4/39491.htm>在.NET程序截获所有未处理的Exception</a><br><a href= http://www.zahui.com/html/4/39492.htm>郁闷的System.Web.Mail</a><br><a href= http://www.zahui.com/html/4/39493.htm>网站左右两边浮动广告(网易摘选-效果不错)l(再贴)</a><br><a href= http://www.zahui.com/html/4/39494.htm>网站左右两边浮动广告(网易摘选-效果不错)</a><br><a href= http://www.zahui.com/html/6/39495.htm>Tomcat5的数据库连接池配置</a><br><a href= http://www.zahui.com/html/6/39496.htm>自由自在的给上传图片打水印</a><br><a href= http://www.zahui.com/html/6/39497.htm>验证码(session存取)</a><br></td></tr></table>
    </span></td>
                  </tr>
                  <tr>
                    <td>
      <span class="unnamed2">
      <table><tr><td><fieldset class="Text2"><legend><b>所有分类</b></legend><a href= http://www.zahui.com/html/1/>Visual C++</a><br><a href= http://www.zahui.com/html/2/>Delphi</a><br><a href= http://www.zahui.com/html/3/>Visual Basic</a><br><a href= http://www.zahui.com/html/4/>ASP</a><br><a href= http://www.zahui.com/html/5/>Perl</a><br><a href= http://www.zahui.com/html/6/>Java</a><br><a href= http://www.zahui.com/html/7/>Javascript</a><br><a href= http://www.zahui.com/html/8/>数据库开发</a><br><a href= http://www.zahui.com/html/9/>其他开发语言</a><br><a href= http://www.zahui.com/html/10/>游戏开发</a><br><a href= http://www.zahui.com/html/11/>文件格式</a><br><a href= http://www.zahui.com/html/12/>网站制作技术</a><br><a href= http://www.zahui.com/html/13/>其他</a><br><a href= http://www.zahui.com/html/14/>.NET</a><br></td></tr></table>   <br>
      <table><tr><td><fieldset class="Text2"><legend><b>相关网站</b></legend><a href="http://www.zahui.com/">技术大杂烩 </a><br><a href="http://linuxsir.zahui.net/">linuxsir技术文档</a><br><a href="http://freebsdforums.zahui.net/">freebsdforums技术文档</a><br><a href="http://51js.zahui.net/">51js技术文档</a><br><a href="http://cnoug.zahui.net/">cnoug技术文档</a></td></tr></table>   </span>
    </td>
                  </tr>
                </table>
                <div align="center">
                  <script language=JavaScript src="../../foot.js"></script>
                </div>
                <table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF" align="center">
                  <tr align="center" bgcolor="#006633"> 
                    <td height="27"> <span><font color="#FFFFFF">合作事项</font> <font color="#FFFFFF">| 
                      业务联系</font> <font color="#FFFFFF">|</font> <font color="#FFFFFF">广告刊登</font> 
                      <font color="#FFFFFF">|</font> <a href=http://www.zhaocount.com><font color="#FFFFFF">计数器</font></a>
                      <font color="#FFFFFF">|</font> <a href="javascript:window.external.AddFavorite('http://www.ZaHui.com/','技术大杂烩')"><font color="#FFFFFF">加入收藏</font></a></span></td>
                  </tr>
                  <tr bgcolor="#F6F6F6" align="center" valign="bottom"> 
                    <td height="29">[ <a href="http://www.zahui.com">www.ZaHui.com</a> 
                      ] 
                    </td>
                  </tr>
                  <tr bgcolor="#F6F6F6" align="center"> 
                    <td height="29">Copyright &copy; 2000-2004 <a href="http://www.zahui.com">www.ZaHui.com</a> 
                       All rights reserved
    </td>
                  </tr>
                </table>
                
              </td>
            </tr>
            </tbody> 
          </table>
        </td>
        <td valign=top align=left width=10 background="../../images/bg_right.gif" height="231"><img src="../../images/blank.gif" width="8" height="1"></td>
      </tr>
      </tbody> 
    </table><script>var a="zahui";</script>
    <script src="http://www.zahui.com/stat.js"></script>
    </body>
    </html>
      

  5.   


    ------------------------------------
    我的团队:www.51team.com欢迎访问,有志者共谋事,每天都有惊喜,SOHO