Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
RemoveUsb.cpp
Package: GetHardDiskId.rar [view]
Upload User: posgewe
Upload Date: 2022-07-05
Package Size: 164k
Code Size: 3k
Category:
Windows Kernel
Development Platform:
Visual C++
- #include "stdafx.h"
- #include <windows.h>
- #include <winioctl.h>
- #include <process.h>
- #include <tchar.h>
- #include <stdio.h>
- #include "DoStorageEnum.h"
- #include <stdlib.h>
- #include <string.h>
- #define MAX_DEVICE 16
- DEFINE_GUID(DiskClassGuid, 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- DEFINE_GUID(CdRomClassGuid, 0x53f56308L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(PartitionClassGuid, 0x53f5630aL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- DEFINE_GUID(TapeClassGuid, 0x53f5630bL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(WriteOnceDiskClassGuid, 0x53f5630cL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(VolumeClassGuid, 0x53f5630dL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(MediumChangerClassGuid, 0x53f56310L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(FloppyClassGuid, 0x53f56311L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(CdChangerClassGuid, 0x53f56312L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- //DEFINE_GUID(StoragePortClassGuid, 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
- char * MakeDriveInfo(LPCTSTR pszDevicePath, PDISK_GEOMETRY pGeometry, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc);
- char * MakeDriveInfo(LPCTSTR pszDevicePath, PDISK_GEOMETRY pGeometry, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc)
- {
- char* p;
- char* strTmp;
- p= (char*)pDevDesc;
- strTmp = (pDevDesc->ProductIdOffset ? &p[pDevDesc->ProductIdOffset] : "");
- return strTmp;
- }
- /*-------------------------------------------------------------------------*/
- char* WINAPI GetDiskId(int index)
- {
- char* strInfo;
- HANDLE hDevice;
- PDISK_GEOMETRY pGeometry;
- PSTORAGE_DEVICE_DESCRIPTOR pDevDesc;
- int nDevice;
- int i,j;
- char* szDevicePath[MAX_DEVICE]; // 设备路径
- LPGUID lpGuid[] = {
- (LPGUID)&DiskClassGuid,
- (LPGUID)&CdRomClassGuid,
- // (LPGUID)&TapeClassGuid,
- }; // 一些存储设备的GUID
- // 分配需要的空间
- for(i=0;i<MAX_DEVICE;i++) szDevicePath[i]=new char[256];
- pGeometry = new DISK_GEOMETRY;
- pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR)new BYTE[sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1];
- pDevDesc->Size = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1;
- // 对感兴趣的类型的存储设备,逐一获取设备信息
- for(i=0; i<sizeof(lpGuid)/sizeof(LPGUID); i++)
- {
- // 取设备路径
- nDevice=::GetDevicePath(lpGuid[i], szDevicePath);
- // 对同一类的存储设备,逐一获取设备信息
- for(j=0; j<nDevice; j++)
- {
- // 打开设备
- hDevice=OpenDevice(szDevicePath[j]);
- if(hDevice != INVALID_HANDLE_VALUE)
- {
- // 取设备信息
- GetDriveGeometry(hDevice, pGeometry);
- GetDriveProperty(hDevice, pDevDesc);
- // 制作显示信息串
- if(j==index)
- {
- strInfo = MakeDriveInfo(szDevicePath[j], pGeometry, pDevDesc);
- }
- // 关闭设备
- CloseHandle(hDevice);
- }
- }
- }
- // 释放空间
- delete pDevDesc;
- delete pGeometry;
- for(i=0;i<MAX_DEVICE;i++) delete []szDevicePath[i];
- return strInfo;
- }