获取U盘ID

落然 2013-03-12 04:41:00
我想用VC获取U盘ID,查了很多资料都是Delphi和VB的,似乎可以通过查注册表或使用API获取U盘ID,可是不知道具体该怎么做。希望有人能解释下,谢谢了!
...全文
816 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
guozizheng001 2015-07-23
  • 打赏
  • 举报
回复
哦 我自己找到了一份 如果楼主下载的里面有一个USBPhysic.dll要引用的话,那就一样了 我能找到的网上实现方式都是用这个DLL (当然也有封装成类的) 用Dependency Walker查出来它只导出两个函数 Init 和 GetUSBPhysicInfo 不过它调用了N多API 这是他调用的kernel32.dll的 CloseHandle CreateFileA DeleteCriticalSection DeviceIoControl EnterCriticalSection ExitProcess FlushFileBuffers FreeEnvironmentStringsA FreeEnvironmentStringsW GetACP GetCPInfo GetCommandLineA GetConsoleCP GetConsoleMode GetConsoleOutputCP GetCurrentProcess GetCurrentProcessId GetCurrentThreadId GetDriveTypeA GetEnvironmentStrings GetEnvironmentStringsW GetFileType GetLastError GetLocaleInfoA GetLogicalDriveStringsA GetModuleFileNameA GetModuleHandleA GetOEMCP GetProcAddress GetProcessHeap GetStartupInfoA GetStdHandle GetStringTypeA GetStringTypeW GetSystemTimeAsFileTime GetTickCount GetVersionExA HeapAlloc HeapCreate HeapDestroy HeapFree HeapReAlloc HeapSize InitializeCriticalSection InterlockedDecrement InterlockedIncrement IsDebuggerPresent LCMapStringA LCMapStringW LeaveCriticalSection LoadLibraryA MultiByteToWideChar QueryPerformanceCounter RaiseException RtlUnwind SetErrorMode SetFilePointer SetHandleCount SetLastError SetStdHandle SetUnhandledExceptionFilter Sleep TerminateProcess TlsAlloc TlsFree TlsGetValue TlsSetValue UnhandledExceptionFilter VirtualAlloc VirtualFree WideCharToMultiByte WriteConsoleA WriteConsoleW WriteFile 由此推断核心功能实现貌似不太简单,还是老老实实用DLL吧 楼主的水平应该知道如何引用外部DLL中的导出函数吧 Public Declare Function Init Lib "USBPhysic.dll" (ByVal sUser As String, ByVal sRegCode As String) As Long Public Declare Function GetUSBPhysicInfo Lib "USBPhysic.dll" (ByVal diskIndex As Long, ByVal InfoType As Long, ByVal pHddInfo As String) As Long 我就不帮忙转成C了。。
guozizheng001 2015-07-23
  • 打赏
  • 举报
回复
楼主发一个VB的吧 需要用
落然 2013-03-15
  • 打赏
  • 举报
回复
引用 5 楼 ksrsoft 的回复:
GetUSBDiskID这个是dll函数,有没有这个函数的定义 运行程序需要dll支持
我是从CSDN下载资里下的,对delphi不了解,能把整个文件发夹给你吗?
缘中人 2013-03-15
  • 打赏
  • 举报
回复
GetUSBDiskID这个是dll函数,有没有这个函数的定义 运行程序需要dll支持
落然 2013-03-15
  • 打赏
  • 举报
回复
引用 3 楼 ksrsoft 的回复:
把你找到delphi的代码贴出来,给你翻译一下,编程cb的
unit GetUSBID; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses USB; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var Drv, Pid: string; begin Drv := ExtractFileDrive(ParamStr(0)); if GetDriveType(PChar(Drv + '\')) <> DRIVE_REMOVABLE then Application.MessageBox('对不起,请把本程序放至到优盘上使用!', 'Error', MB_ICONHAND) else if GetUSBDiskID(Drv, Pid) then ShowMessage(Pid); end; end.
缘中人 2013-03-15
  • 打赏
  • 举报
回复
把你找到delphi的代码贴出来,给你翻译一下,编程cb的
落然 2013-03-15
  • 打赏
  • 举报
回复
引用 7 楼 ksrsoft 的回复:
刚做了个例子,73B60084B0 就是pid吧,不过win7不行,xp可以获取到
是,那老师你是使用什么方式获取的呢,能细说下吗?
缘中人 2013-03-15
  • 打赏
  • 举报
回复
刚做了个例子,73B60084B0 就是pid吧,不过win7不行,xp可以获取到
落然 2013-03-14
  • 打赏
  • 举报
回复
还是木人理啊
落然 2013-03-13
  • 打赏
  • 举报
回复
木人理,木人理
获取U盘ID序列号 VS2005编译通过,源码源自CSDN。已经测试好用。 可以获得U盘名称,制造商ID号 版本号 U盘序列号及容量 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Management; namespace UDiskTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { DriveInfo[] s = DriveInfo.GetDrives(); foreach (DriveInfo drive in s) { if (drive.DriveType == DriveType.Removable) { pf.Text = drive.Name.ToString(); break; } } ManagementClass cimobject = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc = cimobject.GetInstances(); foreach (ManagementObject mo in moc) { if (mo.Properties["InterfaceType"].Value.ToString() == "USB") { try { //产品名称 Caption.Text = mo.Properties["Caption"].Value.ToString(); //总容量 Size.Text = mo.Properties["Size"].Value.ToString(); string[] info = mo.Properties["PNPDeviceID"].Value.ToString().Split('&'); string[] xx = info[3].Split('\\'); //序列号 MessageBox.Show("U盘序列号:" + xx[1]); PNPDeviceID.Text = xx[1]; xx = xx[0].Split('_'); //版本号 REV.Text = xx[1]; //制造商ID xx = info[1].Split('_'); VID.Text = xx[1]; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } } 如果编译遇到问题是using System.Management;无法找到引用找到, 项目(p)->添加引用(R)->找到.NET标签页 列表中下部位找到System.Management 双击点确定

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧