大家给我一个在客户机得到服务器网卡号,CPU号,硬盘出厂号的DLL源码! 会VB的参考http://www.csdn.net/expert/topic/496/496943.shtm帮我写一下!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LIBRARY "GetHardWareInfo"EXPORTS GetMacAddress#include <windows.h>#include <string>#include "nb30.h"typedef struct _ASTAT_{ ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30];} ASTAT, * PASTAT;CString _stdcall GetMacAddress(CString sNetBiosName){ ASTAT Adapter; NCB ncb; UCHAR uRetCode; memset(&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBRESET; ncb.ncb_lana_num = 0; uRetCode = Netbios(&ncb); memset(&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBASTAT; ncb.ncb_lana_num = 0; sNetBiosName.MakeUpper(); FillMemory(ncb.ncb_callname, NCBNAMSZ - 1, 0x20); strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName); ncb.ncb_callname[sNetBiosName.GetLength()] = 0x20; ncb.ncb_callname[NCBNAMSZ] = 0x0; ncb.ncb_buffer = (unsigned char *) &Adapter; ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios(&ncb); CString sMacAddress; if (uRetCode == 0) { sMacAddress.Format(_T("%02x%02x%02x%02x%02x%02x"), Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5]); } return sMacAddress;}出現錯誤,怎么會事!--------------------Configuration: GetHardWareInfo - Win32 Debug--------------------Compiling...GetHardWareInfo.cd:\soft\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"Error executing cl.exe.GetHardWareInfo.dll - 1 error(s), 0 warning(s) 获得硬盘ID的我只在98下试过,2000下不行//获得CPU信息void __fastcall TForm1::Button1Click(TObject *Sender){ char OEMString[13]; int iEAXValue,iEBXValue,iECXValue,iEDXValue; _asm { mov eax,0 cpuid mov DWORD PTR OEMString,ebx mov DWORD PTR OEMString+4,edx mov DWORD PTR OEMString+8,ecx mov BYTE PTR OEMString+12,0 } Label1->Caption="This CPU 's OEM String is: "+AnsiString(OEMString); _asm { mov eax,1 cpuid mov iEAXValue,eax mov iEBXValue,ebx mov iECXValue,ecx mov iEDXValue,edx } if(iEDXValue&0x800000) ShowMessage("This is MMX CPU"); else ShowMessage("None MMX Support."); int iCPUFamily=(0xf00 & iEAXValue) >>8; Label2->Caption="CPU Family is: "+IntToStr(iCPUFamily); _asm { mov eax,2 CPUID } if(_AL==1) ShowMessage("Pentium Pro or Pentium II Found");}//硬盘序列号/*+++ HDID.CPP Written by Lu Lin http://lu0.126.com 2000.11.3 ---*/ #include <windows.h> #include <iostream.h> #include <stdio.h> #define DFP_GET_VERSION 0x00074080 #define DFP_SEND_DRIVE_COMMAND 0x0007c084 #define DFP_RECEIVE_DRIVE_DATA 0x0007c088 #pragma pack(1) typedef struct _GETVERSIONOUTPARAMS { BYTE bVersion; // Binary driver version. BYTE bRevision; // Binary driver revision. BYTE bReserved; // Not used. BYTE bIDEDeviceMap; // Bit map of IDE devices. DWORD fCapabilities; // Bit mask of driver capabilities. DWORD dwReserved[4]; // For future use. } GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; typedef struct _IDEREGS { BYTE bFeaturesReg; // Used for specifying SMART "commands". BYTE bSectorCountReg; // IDE sector count register BYTE bSectorNumberReg; // IDE sector number register BYTE bCylLowReg; // IDE low order cylinder value BYTE bCylHighReg; // IDE high order cylinder value BYTE bDriveHeadReg; // IDE drive/head register BYTE bCommandReg; // Actual IDE command. BYTE bReserved; // reserved for future use. Must be zero. } IDEREGS, *PIDEREGS, *LPIDEREGS; typedef struct _SENDCMDINPARAMS { DWORD cBufferSize; // Buffer size in bytes IDEREGS irDriveRegs; // Structure with drive register values. BYTE bDriveNumber; // Physical drive number to send // command to (0,1,2,3). BYTE bReserved[3]; // Reserved for future expansion. DWORD dwReserved[4]; // For future use. //BYTE bBuffer[1]; // Input buffer. } SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; typedef struct _DRIVERSTATUS { BYTE bDriverError; // Error code from driver, // or 0 if no error. BYTE bIDEStatus; // Contents of IDE Error register. // Only valid when bDriverError // is SMART_IDE_ERROR. BYTE bReserved[2]; // Reserved for future expansion. DWORD dwReserved[2]; // Reserved for future expansion. } DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS; typedef struct _SENDCMDOUTPARAMS { DWORD cBufferSize; // Size of bBuffer in bytes DRIVERSTATUS DriverStatus; // Driver status structure. BYTE bBuffer[512]; // Buffer of arbitrary length // in which to store the data read from the drive. } SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS; typedef struct _IDSECTOR { USHORT wGenConfig; USHORT wNumCyls; USHORT wReserved; USHORT wNumHeads; USHORT wBytesPerTrack; USHORT wBytesPerSector; USHORT wSectorsPerTrack; USHORT wVendorUnique[3]; CHAR sSerialNumber[20]; USHORT wBufferType; USHORT wBufferSize; USHORT wECCSize; CHAR sFirmwareRev[8]; CHAR sModelNumber[40]; USHORT wMoreVendorUnique; USHORT wDoubleWordIO; USHORT wCapabilities; USHORT wReserved1; USHORT wPIOTiming; USHORT wDMATiming; USHORT wBS; USHORT wNumCurrentCyls; USHORT wNumCurrentHeads; USHORT wNumCurrentSectorsPerTrack; ULONG ulCurrentSectorCapacity; USHORT wMultSectorStuff; ULONG ulTotalAddressableSectors; USHORT wSingleWordDMA; USHORT wMultiWordDMA; BYTE bReserved[128]; } IDSECTOR, *PIDSECTOR; /*+++ Global vars ---*/ GETVERSIONOUTPARAMS vers; SENDCMDINPARAMS in; SENDCMDOUTPARAMS out; HANDLE h; DWORD i; BYTE j; void CopyRight(){ cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl; cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl; cerr<<"2000.11.3"<<endl<<endl; } VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize) { USHORT i; CHAR temp; for (i = 0; i < uscStrSize; i+=2) { temp = szString[i]; szString[i] = szString[i+1]; szString[i+1] = temp; } } void DetectIDE(BYTE bIDEDeviceMap){ if (bIDEDeviceMap&1){ if (bIDEDeviceMap&16){ cout<<"ATAPI device is attached to primary controller, drive 0."<<endl; }else{ cout<<"IDE device is attached to primary controller, drive 0."<<endl; } } if (bIDEDeviceMap&2){ if (bIDEDeviceMap&32){ cout<<"ATAPI device is attached to primary controller, drive 1."<<endl; }else{ cout<<"IDE device is attached to primary controller, drive 1."<<endl; } } if (bIDEDeviceMap&4){ if (bIDEDeviceMap&64){ cout<<"ATAPI device is attached to secondary controller, drive 0."<<endl; }else{ cout<<"IDE device is attached to secondary controller, drive 0."<<endl; } } if (bIDEDeviceMap&8){ if (bIDEDeviceMap&128){ cout<<"ATAPI device is attached to secondary controller, drive 1."<<endl; }else{ cout<<"IDE device is attached to secondary controller, drive 1."<<endl; } } } void hdid9x(){ ZeroMemory(&vers,sizeof(vers)); //We start in 95/98/Me h=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0); if (!h){ cout<<"open smartvsd.vxd failed"<<endl; exit(0); } if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){ cout<<"DeviceIoControl failed:DFP_GET_VERSION"<<endl; CloseHandle(h); return; } //If IDE identify command not supported, fails if (!(vers.fCapabilities&1)){ cout<<"Error: IDE identify command not supported."; CloseHandle(h); return; } //Display IDE drive number detected DetectIDE(vers.bIDEDeviceMap); //Identify the IDE drives for (j=0;j<4;j++){ PIDSECTOR phdinfo; char s[41]; ZeroMemory(&in,sizeof(in)); ZeroMemory(&out,sizeof(out)); if (j&1){ in.irDriveRegs.bDriveHeadReg=0xb0; }else{ in.irDriveRegs.bDriveHeadReg=0xa0; } if (vers.fCapabilities&(16>>j)){ //We don't detect a ATAPI device. cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl; continue; }else{ in.irDriveRegs.bCommandReg=0xec; } in.bDriveNumber=j; in.irDriveRegs.bSectorCountReg=1; in.irDriveRegs.bSectorNumberReg=1; in.cBufferSize=512; if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){ cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl; CloseHandle(h); return; } phdinfo=(PIDSECTOR)out.bBuffer; memcpy(s,phdinfo->sModelNumber,40); s[40]=0; ChangeByteOrder(s,40); cout<<endl<<"Module Number:"<<s<<endl; memcpy(s,phdinfo->sFirmwareRev,8); s[8]=0; ChangeByteOrder(s,8); cout<<"\tFirmware rev:"<<s<<endl; memcpy(s,phdinfo->sSerialNumber,20); s[20]=0; ChangeByteOrder(s,20); cout<<"\tSerial Number:"<<s<<endl; cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl; } //Close handle before quit CloseHandle(h); CopyRight(); } void hdidnt(){ char hd[80]; PIDSECTOR phdinfo; char s[41]; ZeroMemory(&vers,sizeof(vers)); //We start in NT/Win2000 for (j=0;j<4;j++){ sprintf(hd,"\\\\.\\PhysicalDrive%d",j); h=CreateFile(hd,GENERIC_READ¦GENERIC_WRITE, FILE_SHARE_READ¦FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0); if (!h){ continue; } if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){ CloseHandle(h); continue; } //If IDE identify command not supported, fails if (!(vers.fCapabilities&1)){ cout<<"Error: IDE identify command not supported."; CloseHandle(h); return; } //Identify the IDE drives ZeroMemory(&in,sizeof(in)); ZeroMemory(&out,sizeof(out)); if (j&1){ in.irDriveRegs.bDriveHeadReg=0xb0; }else{ in.irDriveRegs.bDriveHeadReg=0xa0; } if (vers.fCapabilities&(16>>j)){ //We don't detect a ATAPI device. cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl; continue; }else{ in.irDriveRegs.bCommandReg=0xec; } in.bDriveNumber=j; in.irDriveRegs.bSectorCountReg=1; in.irDriveRegs.bSectorNumberReg=1; in.cBufferSize=512; if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){ cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl; CloseHandle(h); return; } phdinfo=(PIDSECTOR)out.bBuffer; memcpy(s,phdinfo->sModelNumber,40); s[40]=0; ChangeByteOrder(s,40); cout<<endl<<"Module Number:"<<s<<endl; memcpy(s,phdinfo->sFirmwareRev,8); s[8]=0; ChangeByteOrder(s,8); cout<<"\tFirmware rev:"<<s<<endl; memcpy(s,phdinfo->sSerialNumber,20); s[20]=0; ChangeByteOrder(s,20); cout<<"\tSerial Number:"<<s<<endl; cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl; CloseHandle(h); } CopyRight(); } void main(){ OSVERSIONINFO VersionInfo; ZeroMemory(&VersionInfo,sizeof(VersionInfo)); VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo); GetVersionEx(&VersionInfo); switch (VersionInfo.dwPlatformId){ case VER_PLATFORM_WIN32s: cout<<"Win32s is not supported by this programm."<<endl; return; case VER_PLATFORM_WIN32_WINDOWS: hdid9x(); return; case VER_PLATFORM_WIN32_NT: hdidnt(); return; } } //硬盘2// GetDiskId.h: interface for the CGetDiskId class.// HardDisk ID的取得// 作成日:2001年06月09日 VeryBigBug// //////////////////////////////////////////////////////////////////////#if !defined(AFX_GETDISKID_H__30A82D41_5CBD_11D5_A82B_E4FBC888FB91__INCLUDED_)#define AFX_GETDISKID_H__30A82D41_5CBD_11D5_A82B_E4FBC888FB91__INCLUDED_class CGetDiskId {// IOCTL commands#define DFP_GET_VERSION 0x00074080#define DFP_SEND_DRIVE_COMMAND 0x0007c084#define DFP_RECEIVE_DRIVE_DATA 0x0007c088#define FILE_DEVICE_SCSI 0x0000001b#define IOCTL_SCSI_MINIPORT_IDENTIFY ((FILE_DEVICE_SCSI << 16) + 0x0501)#define IOCTL_SCSI_MINIPORT 0x0004D008 // see NTDDSCSI.H for definition#define IDENTIFY_BUFFER_SIZE 512// Valid values for the bCommandReg member of IDEREGS.#define IDE_ATAPI_IDENTIFY 0xA1 // Returns ID sector for ATAPI.#define IDE_ATA_IDENTIFY 0xEC // Returns ID sector for ATA.#pragma pack(push,1)struct CALLGATE_DESCRIPTOR{WORD Offset_0_15;WORD Selector;WORD ParamCount : 5;WORD Unused : 3;WORD Type : 4;WORD System : 1;WORD DPL : 2;WORD Present : 1;WORD Offset_16_31;};struct GDT_DESCRIPTOR{WORD Limit_0_15;WORD Base_0_15;BYTE Base_16_23;BYTE Type : 4;BYTE System : 1;BYTE DPL : 2;BYTE Present : 1;BYTE Limit_16_19 : 4;BYTE Available : 1;BYTE Reserved : 1;BYTE D_B : 1;BYTE Granularity : 1;BYTE Base_24_31;};struct GDTR{WORD wGDTLimit;DWORD dwGDTBase;};// GETVERSIONOUTPARAMS contains the data returned from the // Get Driver Version function.typedef struct _GETVERSIONOUTPARAMS{BYTE bVersion; // Binary driver version.BYTE bRevision; // Binary driver revision.BYTE bReserved; // Not used.BYTE bIDEDeviceMap; // Bit map of IDE devices.DWORD fCapabilities; // Bit mask of driver capabilities.DWORD dwReserved[4]; // For future use.} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; // IDE registerstypedef struct _IDEREGS{BYTE bFeaturesReg; // Used for specifying SMART "commands".BYTE bSectorCountReg; // IDE sector count registerBYTE bSectorNumberReg; // IDE sector number registerBYTE bCylLowReg; // IDE low order cylinder valueBYTE bCylHighReg; // IDE high order cylinder valueBYTE bDriveHeadReg; // IDE drive/head registerBYTE bCommandReg; // Actual IDE command.BYTE bReserved; // reserved for future use. Must be zero.} IDEREGS, *PIDEREGS, *LPIDEREGS;// SENDCMDINPARAMS contains the input parameters for the // Send Command to Drive function.typedef struct _SENDCMDINPARAMS{DWORD cBufferSize; // Buffer size in bytesIDEREGS irDriveRegs; // Structure with drive register values.BYTE bDriveNumber; // Physical drive number to send // command to (0,1,2,3).BYTE bReserved[3]; // Reserved for future expansion.DWORD dwReserved[4]; // For future use.BYTE bBuffer[1]; // Input buffer.} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; // Status returned from drivertypedef struct _DRIVERSTATUS{BYTE bDriverError; // Error code from driver, or 0 if no error.BYTE bIDEStatus; // Contents of IDE Error register.// Only valid when bDriverError is SMART_IDE_ERROR.BYTE bReserved[2]; // Reserved for future expansion.DWORD dwReserved[2]; // Reserved for future expansion.} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;// Structure returned by PhysicalDrive IOCTL for several commandstypedef struct _SENDCMDOUTPARAMS{DWORD cBufferSize; // Size of bBuffer in bytesDRIVERSTATUS DriverStatus; // Driver status structure.BYTE bBuffer[1]; // Buffer of arbitrary length in which to store the data read from the // drive.} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;// The following struct defines the interesting part of the IDENTIFY// buffer:typedef struct _IDSECTOR{USHORT wGenConfig;USHORT wNumCyls;USHORT wReserved;USHORT wNumHeads;USHORT wBytesPerTrack;USHORT wBytesPerSector;USHORT wSectorsPerTrack;USHORT wVendorUnique[3];CHAR sSerialNumber[20];USHORT wBufferType;USHORT wBufferSize;USHORT wECCSize;CHAR sFirmwareRev[8];CHAR sModelNumber[40];USHORT wMoreVendorUnique;USHORT wDoubleWordIO;USHORT wCapabilities;USHORT wReserved1;USHORT wPIOTiming;USHORT wDMATiming;USHORT wBS;USHORT wNumCurrentCyls;USHORT wNumCurrentHeads;USHORT wNumCurrentSectorsPerTrack;ULONG ulCurrentSectorCapacity;USHORT wMultSectorStuff;ULONG ulTotalAddressableSectors;USHORT wSingleWordDMA;USHORT wMultiWordDMA;BYTE bReserved[128];} IDSECTOR, *PIDSECTOR;typedef struct _SRB_IO_CONTROL{ULONG HeaderLength;UCHAR Signature[8];ULONG Timeout;ULONG ControlCode;ULONG ReturnCode;ULONG Length;} SRB_IO_CONTROL, *PSRB_IO_CONTROL;#pragma pack(pop, 1)#define SENDIDLENGTH sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZEpublic:BOOL GetDiskID(char* szIdBuf, int nLen, BOOL bNT);CGetDiskId();virtual ~CGetDiskId();protected:BOOL DoIDENTIFY (HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum, PDWORD lpcbBytesReturned);BOOL ReadIdeDriveAsScsiDriveInNT();void GetDiskId9X();BOOL ReadPhysicalDriveInNT();void GetDiskIdNT();BOOL CallRing09X(PVOID pvRing0FuncAddr, WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);BOOL SetPortVal9X(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);BOOL GetPortVal9X(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);private:static void Ring0SetPortVal9X();static void Ring0GetPortVal9X();char* ConvertToString (DWORD diskdata [256], int firstIndex, int lastIndex);char m_szHardInfo[1024];};#endif // !defined(AFX_GETDISKID_H__30A82D41_5CBD_11D5_A82B_E4FBC888FB91__INCLUDED_)// CPP File// GetDiskId.cpp: implementation of the CGetDiskId class.//// HardDisk ID的取得// 作成日:2001年06月09日 VeryBigBug////////////////////////////////////////////////////////////////////////#include <windows.h>#include "GetDiskId.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CGetDiskId::CGetDiskId(){*m_szHardInfo = 0;}CGetDiskId::~CGetDiskId(){}void CGetDiskId::GetDiskId9X(){DWORD diskdata [256];WORD baseAddress = 0; // Base address of drive controller DWORD portValue = 0;int waitLoop = 0;int index = 0;baseAddress = 0x1f0; // Wait for controller not busy waitLoop = 100000;while (--waitLoop > 0){GetPortVal9X ((WORD) (baseAddress + 7), &portValue, (BYTE) 1);// drive is readyif ((portValue & 0x40) == 0x40) break;// previous drive command ended in errorif ((portValue & 0x01) == 0x01) break;}// Set Master or Slave driveSetPortVal9X ((WORD) (baseAddress + 6), 0xA0, 1);// Get drive info dataSetPortVal9X ((WORD) (baseAddress + 7), 0xEC, 1);// Wait for data ready waitLoop = 100000;while (--waitLoop > 0){GetPortVal9X ((WORD) (baseAddress + 7), &portValue, 1);// see if the drive is ready and has it's info ready for usif ((portValue & 0x48) == 0x48) break;// see if there is a drive errorif ((portValue & 0x01) == 0x01) break;}// read drive id informationfor (index = 0; index < 256; index++){diskdata [index] = 0; // init the spaceGetPortVal9X (baseAddress, &(diskdata [index]), 2);}strcpy (m_szHardInfo, ConvertToString (diskdata, 10, 19));}BOOL CGetDiskId::GetPortVal9X(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize){BOOL rc = FALSE;rc = CallRing09X((PVOID)Ring0GetPortVal9X, wPortAddr, pdwPortVal, bSize);return rc;}BOOL CGetDiskId::SetPortVal9X(WORD wPortAddr, DWORD dwPortVal, BYTE bSize){return CallRing09X((PVOID)Ring0SetPortVal9X, wPortAddr, &dwPortVal, bSize);}BOOL CGetDiskId::CallRing09X(PVOID pvRing0FuncAddr, WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize){struct GDT_DESCRIPTOR *pGDTDescriptor;struct GDTR gdtr;WORD CallgateAddr[3];WORD wGDTIndex = 1;_asm Sgdt [gdtr]// Skip the null descriptorpGDTDescriptor = (struct GDT_DESCRIPTOR *)(gdtr.dwGDTBase + 8);// Search for a free GDT descriptorfor (wGDTIndex = 1; wGDTIndex < (gdtr.wGDTLimit / 8); wGDTIndex++){if (pGDTDescriptor->Type == 0 &&pGDTDescriptor->System == 0 &&pGDTDescriptor->DPL == 0 &&pGDTDescriptor->Present == 0){// Found one !// Now we need to transform this descriptor into a callgate.// Note that we're using selector 0x28 since it corresponds// to a ring 0 segment which spans the entire linear address// space of the processor (0-4GB).struct CALLGATE_DESCRIPTOR *pCallgate;pCallgate = (struct CALLGATE_DESCRIPTOR *) pGDTDescriptor;pCallgate->Offset_0_15 = LOWORD(pvRing0FuncAddr);pCallgate->Selector = 0x28;pCallgate->ParamCount = 0;pCallgate->Unused = 0;pCallgate->Type = 0xc;pCallgate->System = 0;pCallgate->DPL = 3;pCallgate->Present = 1;pCallgate->Offset_16_31 = HIWORD(pvRing0FuncAddr);// Prepare the far call parametersCallgateAddr[0] = 0x0;CallgateAddr[1] = 0x0;CallgateAddr[2] = (wGDTIndex << 3) | 3;// Please fasten your seat belts!// We're about to make a hyperspace jump into RING 0._asm Mov DX, [wPortAddr]_asm Mov EBX, [pdwPortVal]_asm Mov CL, [bSize]_asm Call FWORD PTR [CallgateAddr]// We have made it !// Now free the GDT descriptormemset(pGDTDescriptor, 0, 8);// Our journey was successful. Seeya.return true;}// Advance to the next GDT descriptorpGDTDescriptor++; }// Whoops, the GDT is fullreturn false;}__declspec(naked) void CGetDiskId::Ring0GetPortVal9X(){_asm{Cmp CL, 1Je ByteValCmp CL, 2Je WordValCmp CL, 4Je DWordValByteVal:In AL, DXMov [EBX], ALRetfWordVal:In AX, DXMov [EBX], AXRetfDWordVal:In EAX, DXMov [EBX], EAXRetf}}__declspec(naked) void CGetDiskId::Ring0SetPortVal9X(){_asm{Cmp CL, 1Je ByteValCmp CL, 2Je WordValCmp CL, 4Je DWordValByteVal:Mov AL, [EBX]Out DX, ALRetfWordVal:Mov AX, [EBX]Out DX, AXRetfDWordVal:Mov EAX, [EBX]Out DX, EAXRetf}}char* CGetDiskId::ConvertToString(DWORD diskdata[], int firstIndex, int lastIndex){static char string [1024];int index = 0;int position = 0;// each integer has two characters stored in it backwardsfor (index = firstIndex; index <= lastIndex; index++){// get high byte for 1st characterstring [position] = (char) (diskdata [index] / 256);position++;// get low byte for 2nd characterstring [position] = (char) (diskdata [index] % 256);position++;}// end the string string [position] = '\0';// cut off the trailing blanksfor (index = position - 1; index > 0 && ' ' == string [index]; index--)string [index] = '\0';return string;}void CGetDiskId::GetDiskIdNT(){BOOL rc = FALSE;// this works under WinNT4 or Win2K if you have admin rightsrc = ReadPhysicalDriveInNT ();// this should work in WinNT or Win2K if previous did not work// this is kind of a backdoor via the SCSI mini port driver into// the IDE drivesif ( ! rc) rc = ReadIdeDriveAsScsiDriveInNT ();}BOOL CGetDiskId::ReadPhysicalDriveInNT(){int rc = FALSE;BYTE IdOutCmd [sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];HANDLE hPhysicalDriveIOCTL = 0;// Try to get a handle to PhysicalDrive IOCTL, report failure// and exit if can't.char driveName [256];strcpy (driveName, "\\\\.\\PhysicalDrive0");// Windows NT, Windows 2000, must have admin rightshPhysicalDriveIOCTL = CreateFile (driveName,GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING, 0, NULL);// if (hPhysicalDriveIOCTL == INVALID_HANDLE_VALUE)// printf ("Unable to open physical drive %d, error code: 0x%lX\n",// drive, GetLastError ());if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE){GETVERSIONOUTPARAMS VersionParams;DWORD cbBytesReturned = 0;// Get the version, etc of PhysicalDrive IOCTLmemset ((void*) &VersionParams, 0, sizeof(VersionParams));if ( ! DeviceIoControl (hPhysicalDriveIOCTL, DFP_GET_VERSION,NULL, 0,&VersionParams,sizeof(VersionParams),&cbBytesReturned, NULL) ){ // printf ("DFP_GET_VERSION failed for drive %d\n", i); // continue;}// If there is a IDE device at number "i" issue commands// to the deviceif (VersionParams.bIDEDeviceMap > 0){ BYTE bIDCmd = 0; // IDE or ATAPI IDENTIFY cmd SENDCMDINPARAMS scip; //SENDCMDOUTPARAMS OutCmd;// Now, get the ID sector for all IDE devices in the system.// If the device is ATAPI use the IDE_ATAPI_IDENTIFY command,// otherwise use the IDE_ATA_IDENTIFY command bIDCmd = IDE_ATAPI_IDENTIFY;// (VersionParams.bIDEDeviceMap >> drive & 0x10) ? //IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY; memset (&scip, 0, sizeof(scip)); memset (IdOutCmd, 0, sizeof(IdOutCmd)); if ( DoIDENTIFY (hPhysicalDriveIOCTL, &scip, (PSENDCMDOUTPARAMS)&IdOutCmd, (BYTE) bIDCmd,(BYTE) 0,&cbBytesReturned)) {DWORD diskdata [256];int ijk = 0;USHORT *pIdSector = (USHORT *)((PSENDCMDOUTPARAMS) IdOutCmd) -> bBuffer;for (ijk = 0; ijk < 256; ijk++)diskdata [ijk] = pIdSector [ijk];//PrintIdeInfo (drive, diskdata);strcpy (m_szHardInfo, ConvertToString (diskdata, 10, 19));rc = TRUE; }}CloseHandle (hPhysicalDriveIOCTL);}return rc;}BOOL CGetDiskId::GetDiskID(char *szIdBuf, int nLen, BOOL bNT){*m_szHardInfo = 0;if(bNT)GetDiskIdNT();elseGetDiskId9X();if(*m_szHardInfo){strncpy(szIdBuf, m_szHardInfo, nLen);return TRUE;}return FALSE;}BOOL CGetDiskId::ReadIdeDriveAsScsiDriveInNT(){BOOL rc = FALSE;// int controller = 0;// for (controller = 0; controller < 2; controller++){HANDLE hScsiDriveIOCTL = 0;char driveName [256];// Try to get a handle to PhysicalDrive IOCTL, report failure// and exit if can't.strcpy (driveName, "\\\\.\\Scsi0:");// Windows NT, Windows 2000, any rights should dohScsiDriveIOCTL = CreateFile (driveName,GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING, 0, NULL);// if (hScsiDriveIOCTL == INVALID_HANDLE_VALUE)// printf ("Unable to open SCSI controller %d, error code: 0x%lX\n",// controller, GetLastError ());if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE){int drive = 0;for (drive = 0; drive < 2; drive++){char buffer [sizeof (SRB_IO_CONTROL) + SENDIDLENGTH];SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer;SENDCMDINPARAMS *pin =(SENDCMDINPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));DWORD dummy;memset (buffer, 0, sizeof (buffer));p -> HeaderLength = sizeof (SRB_IO_CONTROL);p -> Timeout = 10000;p -> Length = SENDIDLENGTH;p -> ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;strncpy ((char *) p -> Signature, "SCSIDISK", 8);pin -> irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;pin -> bDriveNumber = drive;if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT, buffer,sizeof (SRB_IO_CONTROL) +sizeof (SENDCMDINPARAMS) - 1,buffer,sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,&dummy, NULL)){SENDCMDOUTPARAMS *pOut =(SENDCMDOUTPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));IDSECTOR *pId = (IDSECTOR *) (pOut -> bBuffer);if (pId -> sModelNumber [0]){DWORD diskdata [256];int ijk = 0;USHORT *pIdSector = (USHORT *) pId;for (ijk = 0; ijk < 256; ijk++)diskdata [ijk] = pIdSector [ijk];//PrintIdeInfo (controller * 2 + drive, diskdata);strcpy (m_szHardInfo, ConvertToString (diskdata, 10, 19));rc = TRUE;}}}CloseHandle (hScsiDriveIOCTL);}}return rc;}BOOL CGetDiskId::DoIDENTIFY(HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum, PDWORD lpcbBytesReturned){// Set up data structures for IDENTIFY command.pSCIP -> cBufferSize = IDENTIFY_BUFFER_SIZE;pSCIP -> irDriveRegs.bFeaturesReg = 0;pSCIP -> irDriveRegs.bSectorCountReg = 1;pSCIP -> irDriveRegs.bSectorNumberReg = 1;pSCIP -> irDriveRegs.bCylLowReg = 0;pSCIP -> irDriveRegs.bCylHighReg = 0;// Compute the drive number.pSCIP -> irDriveRegs.bDriveHeadReg = 0xA0 | ((bDriveNum & 1) << 4);// The command can either be IDE identify or ATAPI identify.pSCIP -> irDriveRegs.bCommandReg = bIDCmd;pSCIP -> bDriveNumber = bDriveNum;pSCIP -> cBufferSize = IDENTIFY_BUFFER_SIZE;return ( DeviceIoControl (hPhysicalDriveIOCTL, DFP_RECEIVE_DRIVE_DATA,(LPVOID) pSCIP,sizeof(SENDCMDINPARAMS) - 1,(LPVOID) pSCOP,sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,lpcbBytesReturned, NULL) );}//网卡#include <nb30.h>//---------------------------------------------------------------------------// 因为是通过NetAPI来获取网卡信息,所以需要包含其题头文件nb30.htypedef struct _ASTAT_{ ADAPTER_STATUS adapt; NAME_BUFFER NameBuff [30];}ASTAT, * PASTAT;ASTAT Adapter; // 定义一个存放返回网卡信息的变量// 输入参数:lana_num为网卡编号,一般地,从0开始,但在Windows 2000中并不一定是连续分配的AnsiString getmac_one (int lana_num){ NCB ncb; UCHAR uRetCode; memset( &ncb, 0, sizeof(ncb) ); ncb.ncb_command = NCBRESET; ncb.ncb_lana_num = lana_num; // 指定网卡号 // 首先对选定的网卡发送一个NCBRESET命令,以便进行初始化 uRetCode = Netbios( &ncb ); //printf( "The NCBRESET return code is:0x%x \n", uRetCode ); memset( &ncb, 0, sizeof(ncb) ); ncb.ncb_command = NCBASTAT; ncb.ncb_lana_num = lana_num; // 指定网卡号 strcpy( (char *)ncb.ncb_callname,"* " ); ncb.ncb_buffer = (unsigned char *) &Adapter; // 指定返回的信息存放的变量 ncb.ncb_length = sizeof(Adapter); // 接着,可以发送NCBASTAT命令以获取网卡的信息 uRetCode = Netbios( &ncb ); //printf( "The NCBASTAT is: 0x%x \n", uRetCode ); //printf( "The NCBASTAT return code is: 0x%x \n", uRetCode ); if ( uRetCode == 0 ) { // 把网卡MAC地址格式化成常用的16进制形式,如0010-A4E4-5802 AnsiString NetSn=""; for (int i=0;i<6;i++) { NetSn+=IntToHex(Adapter.adapt.adapter_address[i],2); } return NetSn; /* printf( "The Ethernet Number[%d]is: %02X%02X-%02X%02X-%02X%02X\n",lana_num, Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5] ); */ }}void __fastcall TForm1::Button1Click(TObject *Sender){ NCB ncb; UCHAR uRetCode; LANA_ENUM lana_enum; memset( &ncb, 0, sizeof(ncb) ); ncb.ncb_command = NCBENUM; ncb.ncb_buffer = (unsigned char *) &lana_enum; ncb.ncb_length = sizeof(lana_enum); // 向网卡发送NCBENUM命令,以获取当前机器的网卡信息,如有多少个网卡、每张网卡的编号等 uRetCode = Netbios( &ncb ); //printf( "The NCBENUM returncode is:0x%x \n", uRetCode ); if ( uRetCode == 0 ) { //printf( "Ethernet Count is : %d\n\n", lana_enum.length); // 对每一张网卡,以其网卡编号为输入编号,获取其MAC地址 //for ( int i=0; i< lana_enum.length; ++i) Label1->Caption=getmac_one( lana_enum.lana[0]); }}//映射网络驱动器 DWORD Error; LPTSTR Local[22]={"Z:","Y:","X:","W:","V:","U:", "T:","S:","R:","Q:","P:","O:","N:","M:", "L:","K:","J:","I:","H:","G:","F:","E:"}; for (int i=0;i<22;i++) { Error=WNetAddConnection("\\\\MAIN\\wen","",Local[i]); if (Error==NO_ERROR) return; ch--; if (Error==ERROR_ALREADY_ASSIGNED) continue; ShowMessage("无法映射网络驱动器,请确定确定您有访问此目录的权限或有空闲的盘可以映射。"); }//IP Address#include <winsock.h>void __fastcall TForm1::Button1Click(TObject *Sender){ char *buffer=new char[65]; struct hostent FAR * phe; struct in_addr *pptr; WSADATA GInitData; WORD wVersionRequested; wVersionRequested = MAKEWORD( 2, 0 ); AnsiString temp; if(WSAStartup(wVersionRequested, &GInitData)!=0) { ShowMessage("init winsock error!"); delete []buffer; return; } if(gethostname(buffer, 64)==SOCKET_ERROR) { ShowMessage("gethostname error"); delete []buffer; return; } phe =gethostbyname(buffer); if (phe == NULL) { ShowMessage("gerhostbyname error"); delete [] buffer; return; } else pptr =(struct in_addr *)*(phe->h_addr_list); temp=inet_ntoa(*pptr); ShowMessage(temp); WSACleanup;} 再贴一个,直接从RING3获取硬盘序列号(1)[ 作者: 陆麟 添加时间: 2001-6-2 0:04:28 ] 通常情况下,我们通过0XEC命令对IDE端口进行监测.获取硬盘信息. 一般情况下,我们就写个VXD或者DRIVER来完成.但是现在,通过MS的S.M.A.R.T.接口,我们可以直接从RING3调用API DeviceIoControl()来获取硬盘信息.下面乃是我的例程: 另外,也有编译好的版本供大家平时使用.欢迎下载. *注:在WIN98SE,WINDOWS ME中,S.M.A.R.T并不缺省安装.请将SMARTVSD.VXD拷贝到%SYSTEM%IOSUBSYS目录下. 在WINDOWS2000下,由于非ADMINISTRATORS组的用户对硬盘连GENERIC_READ的权限也没有,所以请以ADMINISTRATOR登录后使用#include <windows.h> #include <iostream.h> #include <stdio.h> #define DFP_GET_VERSION 0x00074080 #define DFP_SEND_DRIVE_COMMAND 0x0007c084 #define DFP_RECEIVE_DRIVE_DATA 0x0007c088 #pragma pack(1) typedef struct _GETVERSIONOUTPARAMS { BYTE bVersion; // Binary driver version. BYTE bRevision; // Binary driver revision. BYTE bReserved; // Not used. BYTE bIDEDeviceMap; // Bit map of IDE devices. DWORD fCapabilities; // Bit mask of driver capabilities. DWORD dwReserved[4]; // For future use. } GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; typedef struct _IDEREGS { BYTE bFeaturesReg; // Used for specifying SMART "commands". BYTE bSectorCountReg; // IDE sector count register BYTE bSectorNumberReg; // IDE sector number register BYTE bCylLowReg; // IDE low order cylinder value BYTE bCylHighReg; // IDE high order cylinder value BYTE bDriveHeadReg; // IDE drive/head register BYTE bCommandReg; // Actual IDE command. BYTE bReserved; // reserved for future use. Must be zero. } IDEREGS, *PIDEREGS, *LPIDEREGS; typedef struct _SENDCMDINPARAMS { DWORD cBufferSize; // Buffer size in bytes IDEREGS irDriveRegs; // Structure with drive register values. BYTE bDriveNumber; // Physical drive number to send // command to (0,1,2,3). BYTE bReserved[3]; // Reserved for future expansion. DWORD dwReserved[4]; // For future use. //BYTE bBuffer[1]; // Input buffer. } SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; typedef struct _DRIVERSTATUS { BYTE bDriverError; // Error code from driver, // or 0 if no error. BYTE bIDEStatus; // Contents of IDE Error register. // Only valid when bDriverError // is SMART_IDE_ERROR. BYTE bReserved[2]; // Reserved for future expansion. DWORD dwReserved[2]; // Reserved for future expansion. } DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS; typedef struct _SENDCMDOUTPARAMS { DWORD cBufferSize; // Size of bBuffer in bytes DRIVERSTATUS DriverStatus; // Driver status structure. BYTE bBuffer[512]; // Buffer of arbitrary length // in which to store the data read from the drive. } SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS; typedef struct _IDSECTOR { USHORT wGenConfig; USHORT wNumCyls; USHORT wReserved; USHORT wNumHeads; USHORT wBytesPerTrack; USHORT wBytesPerSector; USHORT wSectorsPerTrack; USHORT wVendorUnique[3]; CHAR sSerialNumber[20]; USHORT wBufferType; USHORT wBufferSize; USHORT wECCSize; CHAR sFirmwareRev[8]; CHAR sModelNumber[40]; USHORT wMoreVendorUnique; USHORT wDoubleWordIO; USHORT wCapabilities; USHORT wReserved1; USHORT wPIOTiming; USHORT wDMATiming; USHORT wBS; USHORT wNumCurrentCyls; USHORT wNumCurrentHeads; USHORT wNumCurrentSectorsPerTrack; ULONG ulCurrentSectorCapacity; USHORT wMultSectorStuff; ULONG ulTotalAddressableSectors; USHORT wSingleWordDMA; USHORT wMultiWordDMA; BYTE bReserved[128]; } IDSECTOR, *PIDSECTOR; /*+++ Global vars ---*/ GETVERSIONOUTPARAMS vers; SENDCMDINPARAMS in; SENDCMDOUTPARAMS out; HANDLE h; DWORD i; BYTE j; void CopyRight(){ cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl; cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl; cerr<<"2000.11.3"<<endl<<endl; } VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize) { USHORT i; CHAR temp; for (i = 0; i < uscStrSize; i+=2) { temp = szString[i]; szString[i] = szString[i+1]; szString[i+1] = temp; } } void DetectIDE(BYTE bIDEDeviceMap){ if (bIDEDeviceMap&1){ if (bIDEDeviceMap&16){ cout<<"ATAPI device is attached to primary controller, drive 0."<<endl; }else{ cout<<"IDE device is attached to primary controller, drive 0."<<endl; } } if (bIDEDeviceMap&2){ if (bIDEDeviceMap&32){ cout<<"ATAPI device is attached to primary controller, drive 1."<<endl; }else{ cout<<"IDE device is attached to primary controller, drive 1."<<endl; } } if (bIDEDeviceMap&4){ if (bIDEDeviceMap&64){ cout<<"ATAPI device is attached to secondary controller, drive 0."<<endl; }else{ cout<<"IDE device is attached to secondary controller, drive 0."<<endl; } } if (bIDEDeviceMap&8){ if (bIDEDeviceMap&128){ cout<<"ATAPI device is attached to secondary controller, drive 1."<<endl; }else{ cout<<"IDE device is attached to secondary controller, drive 1."<<endl; } } } void hdid9x(){ ZeroMemory(&vers,sizeof(vers)); //We start in 95/98/Me h=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0); if (!h){ cout<<"open smartvsd.vxd failed"<<endl; exit(0); } if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){ cout<<"DeviceIoControl failed:DFP_GET_VERSION"<<endl; CloseHandle(h); return; } //If IDE identify command not supported, fails if (!(vers.fCapabilities&1)){ cout<<"Error: IDE identify command not supported."; CloseHandle(h); return; } //Display IDE drive number detected DetectIDE(vers.bIDEDeviceMap); //Identify the IDE drives for (j=0;j<4;j++){ PIDSECTOR phdinfo; char s[41]; ZeroMemory(&in,sizeof(in)); ZeroMemory(&out,sizeof(out)); if (j&1){ in.irDriveRegs.bDriveHeadReg=0xb0; }else{ in.irDriveRegs.bDriveHeadReg=0xa0; } if (vers.fCapabilities&(16>>j)){ //We don't detect a ATAPI device. cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl; continue; }else{ in.irDriveRegs.bCommandReg=0xec; } in.bDriveNumber=j; in.irDriveRegs.bSectorCountReg=1; in.irDriveRegs.bSectorNumberReg=1; in.cBufferSize=512; if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){ cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl; CloseHandle(h); return; } phdinfo=(PIDSECTOR)out.bBuffer; memcpy(s,phdinfo->sModelNumber,40); s[40]=0; ChangeByteOrder(s,40); cout<<endl<<"Module Number:"<<s<<endl; memcpy(s,phdinfo->sFirmwareRev,8); s[8]=0; ChangeByteOrder(s,8); cout<<"\tFirmware rev:"<<s<<endl; memcpy(s,phdinfo->sSerialNumber,20); s[20]=0; ChangeByteOrder(s,20); cout<<"\tSerial Number:"<<s<<endl; cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl; } //Close handle before quit CloseHandle(h); CopyRight(); } void hdidnt(){ char hd[80]; PIDSECTOR phdinfo; char s[41]; ZeroMemory(&vers,sizeof(vers)); //We start in NT/Win2000 for (j=0;j<4;j++){ sprintf(hd,"\\\\.\\PhysicalDrive%d",j); h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0); if (!h){ continue; } if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){ CloseHandle(h); continue; } //If IDE identify command not supported, fails if (!(vers.fCapabilities&1)){ cout<<"Error: IDE identify command not supported."; CloseHandle(h); return; } //Identify the IDE drives ZeroMemory(&in,sizeof(in)); ZeroMemory(&out,sizeof(out)); if (j&1){ in.irDriveRegs.bDriveHeadReg=0xb0; }else{ in.irDriveRegs.bDriveHeadReg=0xa0; } if (vers.fCapabilities&(16>>j)){ //We don't detect a ATAPI device. cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl; continue; }else{ in.irDriveRegs.bCommandReg=0xec; } in.bDriveNumber=j; in.irDriveRegs.bSectorCountReg=1; in.irDriveRegs.bSectorNumberReg=1; in.cBufferSize=512; if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){ cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl; CloseHandle(h); return; } phdinfo=(PIDSECTOR)out.bBuffer; memcpy(s,phdinfo->sModelNumber,40); s[40]=0; ChangeByteOrder(s,40); cout<<endl<<"Module Number:"<<s<<endl; memcpy(s,phdinfo->sFirmwareRev,8); s[8]=0; ChangeByteOrder(s,8); cout<<"\tFirmware rev:"<<s<<endl; memcpy(s,phdinfo->sSerialNumber,20); s[20]=0; ChangeByteOrder(s,20); cout<<"\tSerial Number:"<<s<<endl; cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl; CloseHandle(h); } CopyRight(); } void main(){ OSVERSIONINFO VersionInfo; ZeroMemory(&VersionInfo,sizeof(VersionInfo)); VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo); GetVersionEx(&VersionInfo); switch (VersionInfo.dwPlatformId){ case VER_PLATFORM_WIN32s: cout<<"Win32s is not supported by this programm."<<endl; return; case VER_PLATFORM_WIN32_WINDOWS: hdid9x(); return; case VER_PLATFORM_WIN32_NT: hdidnt(); return; } } 上面的人有没有看清楚别人的问题啊?是得到远程机器的MAC,CPUID我只知道得到MAC的。是shotgun写的 #include "stdio.h"#include "stdlib.h"#include "Winsock2.h"#include "iphlpapi.h" #pragma comment ( lib, "ws2_32.lib" )#pragma comment ( lib, "Iphlpapi.lib" ) void main( int argc, char ** argv ){ //处理命令行参数 if ( argc != 2 ) { printf( "RmtHost v0.1 - Get remote HostName / MacAddress\n" ); printf( "by ShotgunLabs ( [email protected] )\n\n" ); printf( "Usage :\n\tRmtHost.exe [RemoteIP]\n\n" ); printf( "Example:\n\tRmtHost.exe 192.168.0.3\n\n" ); exit( 0 ); } printf( "\nIpAddress : %s\n", argv[1] ); //初始化SOCKET WSADATA wsaData; int iRet = WSAStartup(MAKEWORD(2,1), &wsaData); if ( iRet != 0 ) { printf( "WSAStartup Error:%d\n", GetLastError() ); exit( 0 ); } //获取远程机器名 hostent * remoteHostent = (hostent*)malloc( sizeof( hostent ) ); int nRemoteAddr = inet_addr( argv[1] ); remoteHostent = gethostbyaddr( (char*)&nRemoteAddr, sizeof( in_addr ), AF_INET ); if ( remoteHostent ) printf( "HostName : %s\n", remoteHostent->h_name ); else printf( "gethostbyaddr Error:%d\n", GetLastError() ); //发送ARP查询包获得远程MAC地址 unsigned char macAddress[6]; ULONG macAddLen = 6; iRet = SendARP( nRemoteAddr, NULL, (PULONG)&macAddress, &macAddLen ); if ( iRet == NO_ERROR ) { printf( "MacAddress: " ); for( int i =0; i<6; i++ ) { printf( "%.2x", macAddress[i] ); if ( i<5 ) printf( "-" ); } } else printf( "SendARP Error:%d\n", GetLastError() ); printf( "\n" );} 还有,上面那个code只能在2000下面使用,9x/me不支持 Kevin_qing():抓mac作成dll发给我!mail:[email protected](最好為vc的) 幫小弟作一下!老出錯!小弟一定給分!mail:[email protected]--------------------Configuration: GetHardWareInfo - Win32 Debug--------------------Compiling...GetHardWareInfo.cd:\soft\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"Error executing cl.exe. 你上面的代码处问题是因为你的源码文件使用了.c作为扩展名,改成.cpp就好了 BOOL ReadIdeDriveAsScsiDriveInNT();该函数我发现在2000下有问题,老是告诉我“设备未连接“(用GetLastError()测试的),事实上我的Scsi硬盘都在用。请问有谁真正的测试过该函数。 远程机器的CPUID和硬盘ID无法得到,只能在那机器上装个木马 BOOL ReadIdeDriveAsScsiDriveInNT();该函数我发现在2000下有问题,老是告诉我“设备未连接“(用GetLastError()测试的),事实上我的Scsi硬盘都在用。请问有谁真正的测试过该函数。 BOOL ReadIdeDriveAsScsiDriveInNT();该函数我发现在2000下有问题,老是告诉我“设备未连接“(用GetLastError()测试的),事实上我的Scsi硬盘都在用。请问有谁真正的测试过该函数。 BOOL ReadIdeDriveAsScsiDriveInNT();该函数我发现在2000下有问题,老是告诉我“设备未连接“(用GetLastError()测试的),事实上我的Scsi硬盘都在用。请问有谁真正的测试过该函数。 我也觉得willii(willii) 说得不错你发给我我也不能帮你什么! 求异步UDP例子 com怎么返回自定义的类型 按键精灵插件制作的问题 【调查+散分】除了MFC ,你还使用其他的库吗? 散分 顺便问个令我头痛的问题 请问在已经知道窗口句柄的情况下,如何判断一个窗口是 button,edit ? 串行通讯时用来显示的数据的视不断闪烁的问题如何解决?! 为什么我定义的_ConnectionPtr m_pConnection;_RecordsetPtr m_pUserSet;不能放到头文件中! vc学不下去了,怎么办? 如何动态添加菜单 一个虚拟函数的问题? 关于速度的问题
EXPORTS
GetMacAddress#include <windows.h>
#include <string>
#include "nb30.h"typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
} ASTAT, * PASTAT;CString _stdcall GetMacAddress(CString sNetBiosName)
{
ASTAT Adapter; NCB ncb;
UCHAR uRetCode; memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0; uRetCode = Netbios(&ncb); memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0; sNetBiosName.MakeUpper(); FillMemory(ncb.ncb_callname, NCBNAMSZ - 1, 0x20); strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName); ncb.ncb_callname[sNetBiosName.GetLength()] = 0x20;
ncb.ncb_callname[NCBNAMSZ] = 0x0; ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios(&ncb);
CString sMacAddress; if (uRetCode == 0)
{
sMacAddress.Format(_T("%02x%02x%02x%02x%02x%02x"),
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5]);
} return sMacAddress;
}出現錯誤,怎么會事!--------------------Configuration: GetHardWareInfo - Win32 Debug--------------------
Compiling...
GetHardWareInfo.c
d:\soft\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
Error executing cl.exe.GetHardWareInfo.dll - 1 error(s), 0 warning(s)
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char OEMString[13];
int iEAXValue,iEBXValue,iECXValue,iEDXValue; _asm
{
mov eax,0
cpuid
mov DWORD PTR OEMString,ebx
mov DWORD PTR OEMString+4,edx
mov DWORD PTR OEMString+8,ecx
mov BYTE PTR OEMString+12,0
}
Label1->Caption="This CPU 's OEM String is: "+AnsiString(OEMString); _asm
{
mov eax,1
cpuid
mov iEAXValue,eax
mov iEBXValue,ebx
mov iECXValue,ecx
mov iEDXValue,edx
} if(iEDXValue&0x800000) ShowMessage("This is MMX CPU");
else ShowMessage("None MMX Support.");
int iCPUFamily=(0xf00 & iEAXValue) >>8;
Label2->Caption="CPU Family is: "+IntToStr(iCPUFamily); _asm
{
mov eax,2
CPUID
} if(_AL==1) ShowMessage("Pentium Pro or Pentium II Found");
}
//硬盘序列号
/*+++
HDID.CPP
Written by Lu Lin
http://lu0.126.com
2000.11.3
---*/
#include <windows.h>
#include <iostream.h>
#include <stdio.h> #define DFP_GET_VERSION 0x00074080
#define DFP_SEND_DRIVE_COMMAND 0x0007c084
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088 #pragma pack(1)
typedef struct _GETVERSIONOUTPARAMS {
BYTE bVersion; // Binary driver version.
BYTE bRevision; // Binary driver revision.
BYTE bReserved; // Not used.
BYTE bIDEDeviceMap; // Bit map of IDE devices.
DWORD fCapabilities; // Bit mask of driver capabilities.
DWORD dwReserved[4]; // For future use.
} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; typedef struct _IDEREGS {
BYTE bFeaturesReg; // Used for specifying SMART "commands".
BYTE bSectorCountReg; // IDE sector count register
BYTE bSectorNumberReg; // IDE sector number register
BYTE bCylLowReg; // IDE low order cylinder value
BYTE bCylHighReg; // IDE high order cylinder value
BYTE bDriveHeadReg; // IDE drive/head register
BYTE bCommandReg; // Actual IDE command.
BYTE bReserved; // reserved for future use. Must be zero.
} IDEREGS, *PIDEREGS, *LPIDEREGS; typedef struct _SENDCMDINPARAMS {
DWORD cBufferSize; // Buffer size in bytes
IDEREGS irDriveRegs; // Structure with drive register values.
BYTE bDriveNumber; // Physical drive number to send
// command to (0,1,2,3).
BYTE bReserved[3]; // Reserved for future expansion.
DWORD dwReserved[4]; // For future use.
//BYTE bBuffer[1]; // Input buffer.
} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; typedef struct _DRIVERSTATUS {
BYTE bDriverError; // Error code from driver,
// or 0 if no error.
BYTE bIDEStatus; // Contents of IDE Error register.
// Only valid when bDriverError
// is SMART_IDE_ERROR.
BYTE bReserved[2]; // Reserved for future expansion.
DWORD dwReserved[2]; // Reserved for future expansion.
} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS; typedef struct _SENDCMDOUTPARAMS {
DWORD cBufferSize; // Size of bBuffer in bytes
DRIVERSTATUS DriverStatus; // Driver status structure.
BYTE bBuffer[512]; // Buffer of arbitrary length
// in which to store the data read from the drive.
} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS; typedef struct _IDSECTOR {
USHORT wGenConfig;
USHORT wNumCyls;
USHORT wReserved;
USHORT wNumHeads;
USHORT wBytesPerTrack;
USHORT wBytesPerSector;
USHORT wSectorsPerTrack;
USHORT wVendorUnique[3];
CHAR sSerialNumber[20];
USHORT wBufferType;
USHORT wBufferSize;
USHORT wECCSize;
CHAR sFirmwareRev[8];
CHAR sModelNumber[40];
USHORT wMoreVendorUnique;
USHORT wDoubleWordIO;
USHORT wCapabilities;
USHORT wReserved1;
USHORT wPIOTiming;
USHORT wDMATiming;
USHORT wBS;
USHORT wNumCurrentCyls;
USHORT wNumCurrentHeads;
USHORT wNumCurrentSectorsPerTrack;
ULONG ulCurrentSectorCapacity;
USHORT wMultSectorStuff;
ULONG ulTotalAddressableSectors;
USHORT wSingleWordDMA;
USHORT wMultiWordDMA;
BYTE bReserved[128];
} IDSECTOR, *PIDSECTOR; /*+++
Global vars
---*/
GETVERSIONOUTPARAMS vers;
SENDCMDINPARAMS in;
SENDCMDOUTPARAMS out;
HANDLE h;
DWORD i;
BYTE j; void CopyRight(){
cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl;
cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl;
cerr<<"2000.11.3"<<endl<<endl;
}
VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
{ USHORT i;
CHAR temp; for (i = 0; i < uscStrSize; i+=2)
{
temp = szString[i];
szString[i] = szString[i+1];
szString[i+1] = temp;
}
} void DetectIDE(BYTE bIDEDeviceMap){
if (bIDEDeviceMap&1){
if (bIDEDeviceMap&16){
cout<<"ATAPI device is attached to primary controller, drive 0."<<endl;
}else{
cout<<"IDE device is attached to primary controller, drive 0."<<endl;
}
}
if (bIDEDeviceMap&2){
if (bIDEDeviceMap&32){
cout<<"ATAPI device is attached to primary controller, drive 1."<<endl;
}else{
cout<<"IDE device is attached to primary controller, drive 1."<<endl;
}
}
if (bIDEDeviceMap&4){
if (bIDEDeviceMap&64){
cout<<"ATAPI device is attached to secondary controller, drive 0."<<endl;
}else{
cout<<"IDE device is attached to secondary controller, drive 0."<<endl;
}
}
if (bIDEDeviceMap&8){
if (bIDEDeviceMap&128){
cout<<"ATAPI device is attached to secondary controller, drive 1."<<endl;
}else{
cout<<"IDE device is attached to secondary controller, drive 1."<<endl;
}
}
} void hdid9x(){
ZeroMemory(&vers,sizeof(vers));
//We start in 95/98/Me
h=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0);
if (!h){
cout<<"open smartvsd.vxd failed"<<endl;
exit(0);
} if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
cout<<"DeviceIoControl failed:DFP_GET_VERSION"<<endl;
CloseHandle(h);
return;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Display IDE drive number detected
DetectIDE(vers.bIDEDeviceMap);
//Identify the IDE drives
for (j=0;j<4;j++){
PIDSECTOR phdinfo;
char s[41]; ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;
} //Close handle before quit
CloseHandle(h);
CopyRight(); } void hdidnt(){
char hd[80];
PIDSECTOR phdinfo;
char s[41]; ZeroMemory(&vers,sizeof(vers));
//We start in NT/Win2000
for (j=0;j<4;j++){
sprintf(hd,"\\\\.\\PhysicalDrive%d",j);
h=CreateFile(hd,GENERIC_READ¦GENERIC_WRITE,
FILE_SHARE_READ¦FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (!h){
continue;
}
if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
CloseHandle(h);
continue;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Identify the IDE drives
ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;
CloseHandle(h);
}
CopyRight();
} void main(){
OSVERSIONINFO VersionInfo; ZeroMemory(&VersionInfo,sizeof(VersionInfo));
VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);
GetVersionEx(&VersionInfo); switch (VersionInfo.dwPlatformId){
case VER_PLATFORM_WIN32s:
cout<<"Win32s is not supported by this programm."<<endl;
return;
case VER_PLATFORM_WIN32_WINDOWS:
hdid9x();
return;
case VER_PLATFORM_WIN32_NT:
hdidnt();
return;
}
}
//硬盘2
// GetDiskId.h: interface for the CGetDiskId class.
// HardDisk ID的取得
// 作成日:2001年06月09日 VeryBigBug
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_GETDISKID_H__30A82D41_5CBD_11D5_A82B_E4FBC888FB91__INCLUDED_)
#define AFX_GETDISKID_H__30A82D41_5CBD_11D5_A82B_E4FBC888FB91__INCLUDED_class CGetDiskId
{// IOCTL commands
#define DFP_GET_VERSION 0x00074080
#define DFP_SEND_DRIVE_COMMAND 0x0007c084
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088#define FILE_DEVICE_SCSI 0x0000001b
#define IOCTL_SCSI_MINIPORT_IDENTIFY ((FILE_DEVICE_SCSI << 16) + 0x0501)
#define IOCTL_SCSI_MINIPORT 0x0004D008 // see NTDDSCSI.H for definition#define IDENTIFY_BUFFER_SIZE 512// Valid values for the bCommandReg member of IDEREGS.
#define IDE_ATAPI_IDENTIFY 0xA1 // Returns ID sector for ATAPI.
#define IDE_ATA_IDENTIFY 0xEC // Returns ID sector for ATA.#pragma pack(push,1)
struct CALLGATE_DESCRIPTOR
{
WORD Offset_0_15;
WORD Selector;
WORD ParamCount : 5;
WORD Unused : 3;
WORD Type : 4;
WORD System : 1;
WORD DPL : 2;
WORD Present : 1;
WORD Offset_16_31;
};struct GDT_DESCRIPTOR
{
WORD Limit_0_15;
WORD Base_0_15;
BYTE Base_16_23;
BYTE Type : 4;
BYTE System : 1;
BYTE DPL : 2;
BYTE Present : 1;
BYTE Limit_16_19 : 4;
BYTE Available : 1;
BYTE Reserved : 1;
BYTE D_B : 1;
BYTE Granularity : 1;
BYTE Base_24_31;
};struct GDTR
{
WORD wGDTLimit;
DWORD dwGDTBase;
};
// GETVERSIONOUTPARAMS contains the data returned from the
// Get Driver Version function.
typedef struct _GETVERSIONOUTPARAMS
{
BYTE bVersion; // Binary driver version.
BYTE bRevision; // Binary driver revision.
BYTE bReserved; // Not used.
BYTE bIDEDeviceMap; // Bit map of IDE devices.
DWORD fCapabilities; // Bit mask of driver capabilities.
DWORD dwReserved[4]; // For future use.
} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; // IDE registers
typedef struct _IDEREGS
{
BYTE bFeaturesReg; // Used for specifying SMART "commands".
BYTE bSectorCountReg; // IDE sector count register
BYTE bSectorNumberReg; // IDE sector number register
BYTE bCylLowReg; // IDE low order cylinder value
BYTE bCylHighReg; // IDE high order cylinder value
BYTE bDriveHeadReg; // IDE drive/head register
BYTE bCommandReg; // Actual IDE command.
BYTE bReserved; // reserved for future use. Must be zero.
} IDEREGS, *PIDEREGS, *LPIDEREGS;
// SENDCMDINPARAMS contains the input parameters for the
// Send Command to Drive function.
typedef struct _SENDCMDINPARAMS
{
DWORD cBufferSize; // Buffer size in bytes
IDEREGS irDriveRegs; // Structure with drive register values.
BYTE bDriveNumber; // Physical drive number to send
// command to (0,1,2,3).
BYTE bReserved[3]; // Reserved for future expansion.
DWORD dwReserved[4]; // For future use.
BYTE bBuffer[1]; // Input buffer.
} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; // Status returned from driver
typedef struct _DRIVERSTATUS
{
BYTE bDriverError; // Error code from driver, or 0 if no error.
BYTE bIDEStatus; // Contents of IDE Error register.
// Only valid when bDriverError is SMART_IDE_ERROR.
BYTE bReserved[2]; // Reserved for future expansion.
DWORD dwReserved[2]; // Reserved for future expansion.
} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;// Structure returned by PhysicalDrive IOCTL for several commands
typedef struct _SENDCMDOUTPARAMS
{
DWORD cBufferSize; // Size of bBuffer in bytes
DRIVERSTATUS DriverStatus; // Driver status structure.
BYTE bBuffer[1]; // Buffer of arbitrary length in which to store the data read from the // drive.
} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;
// The following struct defines the interesting part of the IDENTIFY
// buffer:
typedef struct _IDSECTOR
{
USHORT wGenConfig;
USHORT wNumCyls;
USHORT wReserved;
USHORT wNumHeads;
USHORT wBytesPerTrack;
USHORT wBytesPerSector;
USHORT wSectorsPerTrack;
USHORT wVendorUnique[3];
CHAR sSerialNumber[20];
USHORT wBufferType;
USHORT wBufferSize;
USHORT wECCSize;
CHAR sFirmwareRev[8];
CHAR sModelNumber[40];
USHORT wMoreVendorUnique;
USHORT wDoubleWordIO;
USHORT wCapabilities;
USHORT wReserved1;
USHORT wPIOTiming;
USHORT wDMATiming;
USHORT wBS;
USHORT wNumCurrentCyls;
USHORT wNumCurrentHeads;
USHORT wNumCurrentSectorsPerTrack;
ULONG ulCurrentSectorCapacity;
USHORT wMultSectorStuff;
ULONG ulTotalAddressableSectors;
USHORT wSingleWordDMA;
USHORT wMultiWordDMA;
BYTE bReserved[128];
} IDSECTOR, *PIDSECTOR;
typedef struct _SRB_IO_CONTROL
{
ULONG HeaderLength;
UCHAR Signature[8];
ULONG Timeout;
ULONG ControlCode;
ULONG ReturnCode;
ULONG Length;
} SRB_IO_CONTROL, *PSRB_IO_CONTROL;
#pragma pack(pop, 1)#define SENDIDLENGTH sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZEpublic:
BOOL GetDiskID(char* szIdBuf, int nLen, BOOL bNT);
CGetDiskId();
virtual ~CGetDiskId();protected:
BOOL DoIDENTIFY (HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum, PDWORD lpcbBytesReturned);
BOOL ReadIdeDriveAsScsiDriveInNT();
void GetDiskId9X();
BOOL ReadPhysicalDriveInNT();
void GetDiskIdNT();
BOOL CallRing09X(PVOID pvRing0FuncAddr, WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
BOOL SetPortVal9X(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);
BOOL GetPortVal9X(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);private:
static void Ring0SetPortVal9X();
static void Ring0GetPortVal9X();
char* ConvertToString (DWORD diskdata [256], int firstIndex, int lastIndex);
char m_szHardInfo[1024];};#endif // !defined(AFX_GETDISKID_H__30A82D41_5CBD_11D5_A82B_E4FBC888FB91__INCLUDED_)// CPP File// GetDiskId.cpp: implementation of the CGetDiskId class.
//
// HardDisk ID的取得
// 作成日:2001年06月09日 VeryBigBug
//
//////////////////////////////////////////////////////////////////////
#include <windows.h>
#include "GetDiskId.h"//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////CGetDiskId::CGetDiskId()
{
*m_szHardInfo = 0;
}CGetDiskId::~CGetDiskId()
{}void CGetDiskId::GetDiskId9X()
{
DWORD diskdata [256];
WORD baseAddress = 0; // Base address of drive controller
DWORD portValue = 0;
int waitLoop = 0;
int index = 0;baseAddress = 0x1f0; // Wait for controller not busy
waitLoop = 100000;
while (--waitLoop > 0)
{
GetPortVal9X ((WORD) (baseAddress + 7), &portValue, (BYTE) 1);
// drive is ready
if ((portValue & 0x40) == 0x40) break;
// previous drive command ended in error
if ((portValue & 0x01) == 0x01) break;
}// Set Master or Slave drive
SetPortVal9X ((WORD) (baseAddress + 6), 0xA0, 1);// Get drive info data
SetPortVal9X ((WORD) (baseAddress + 7), 0xEC, 1);// Wait for data ready
waitLoop = 100000;
while (--waitLoop > 0)
{
GetPortVal9X ((WORD) (baseAddress + 7), &portValue, 1);
// see if the drive is ready and has it's info ready for us
if ((portValue & 0x48) == 0x48) break;
// see if there is a drive error
if ((portValue & 0x01) == 0x01) break;
}// read drive id information
for (index = 0; index < 256; index++)
{
diskdata [index] = 0; // init the space
GetPortVal9X (baseAddress, &(diskdata [index]), 2);
}strcpy (m_szHardInfo, ConvertToString (diskdata, 10, 19));
}BOOL CGetDiskId::GetPortVal9X(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize)
{
BOOL rc = FALSE;rc = CallRing09X((PVOID)Ring0GetPortVal9X, wPortAddr, pdwPortVal, bSize);return rc;
}BOOL CGetDiskId::SetPortVal9X(WORD wPortAddr, DWORD dwPortVal, BYTE bSize)
{
return CallRing09X((PVOID)Ring0SetPortVal9X, wPortAddr, &dwPortVal, bSize);
}BOOL CGetDiskId::CallRing09X(PVOID pvRing0FuncAddr, WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize)
{struct GDT_DESCRIPTOR *pGDTDescriptor;
struct GDTR gdtr;
WORD CallgateAddr[3];
WORD wGDTIndex = 1;_asm Sgdt [gdtr]// Skip the null descriptorpGDTDescriptor = (struct GDT_DESCRIPTOR *)(gdtr.dwGDTBase + 8);// Search for a free GDT descriptorfor (wGDTIndex = 1; wGDTIndex < (gdtr.wGDTLimit / 8); wGDTIndex++)
{
if (pGDTDescriptor->Type == 0 &&
pGDTDescriptor->System == 0 &&
pGDTDescriptor->DPL == 0 &&
pGDTDescriptor->Present == 0)
{
// Found one !
// Now we need to transform this descriptor into a callgate.
// Note that we're using selector 0x28 since it corresponds
// to a ring 0 segment which spans the entire linear address
// space of the processor (0-4GB).struct CALLGATE_DESCRIPTOR *pCallgate;pCallgate = (struct CALLGATE_DESCRIPTOR *) pGDTDescriptor;
pCallgate->Offset_0_15 = LOWORD(pvRing0FuncAddr);
pCallgate->Selector = 0x28;
pCallgate->ParamCount = 0;
pCallgate->Unused = 0;
pCallgate->Type = 0xc;
pCallgate->System = 0;
pCallgate->DPL = 3;
pCallgate->Present = 1;
pCallgate->Offset_16_31 = HIWORD(pvRing0FuncAddr);// Prepare the far call parametersCallgateAddr[0] = 0x0;
CallgateAddr[1] = 0x0;
CallgateAddr[2] = (wGDTIndex << 3) | 3;// Please fasten your seat belts!
// We're about to make a hyperspace jump into RING 0._asm Mov DX, [wPortAddr]
_asm Mov EBX, [pdwPortVal]
_asm Mov CL, [bSize]
_asm Call FWORD PTR [CallgateAddr]// We have made it !
// Now free the GDT descriptormemset(pGDTDescriptor, 0, 8);// Our journey was successful. Seeya.return true;
}// Advance to the next GDT descriptorpGDTDescriptor++;
}// Whoops, the GDT is fullreturn false;
}__declspec(naked) void CGetDiskId::Ring0GetPortVal9X()
{
_asm
{
Cmp CL, 1
Je ByteVal
Cmp CL, 2
Je WordVal
Cmp CL, 4
Je DWordValByteVal:In AL, DX
Mov [EBX], AL
RetfWordVal:In AX, DX
Mov [EBX], AX
RetfDWordVal:In EAX, DX
Mov [EBX], EAX
Retf
}
}
__declspec(naked) void CGetDiskId::Ring0SetPortVal9X()
{
_asm
{
Cmp CL, 1
Je ByteVal
Cmp CL, 2
Je WordVal
Cmp CL, 4
Je DWordValByteVal:Mov AL, [EBX]
Out DX, AL
RetfWordVal:Mov AX, [EBX]
Out DX, AX
RetfDWordVal:Mov EAX, [EBX]
Out DX, EAX
Retf
}
}
char* CGetDiskId::ConvertToString(DWORD diskdata[], int firstIndex, int lastIndex)
{
static char string [1024];
int index = 0;
int position = 0;// each integer has two characters stored in it backwards
for (index = firstIndex; index <= lastIndex; index++)
{
// get high byte for 1st character
string [position] = (char) (diskdata [index] / 256);
position++;// get low byte for 2nd character
string [position] = (char) (diskdata [index] % 256);
position++;
}// end the string
string [position] = '\0';// cut off the trailing blanks
for (index = position - 1; index > 0 && ' ' == string [index]; index--)
string [index] = '\0';return string;
}void CGetDiskId::GetDiskIdNT()
{
BOOL rc = FALSE;// this works under WinNT4 or Win2K if you have admin rights
rc = ReadPhysicalDriveInNT ();// this should work in WinNT or Win2K if previous did not work
// this is kind of a backdoor via the SCSI mini port driver into
// the IDE drives
if ( ! rc) rc = ReadIdeDriveAsScsiDriveInNT ();}BOOL CGetDiskId::ReadPhysicalDriveInNT()
{
int rc = FALSE;
BYTE IdOutCmd [sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];HANDLE hPhysicalDriveIOCTL = 0;// Try to get a handle to PhysicalDrive IOCTL, report failure
// and exit if can't.
char driveName [256];strcpy (driveName, "\\\\.\\PhysicalDrive0");// Windows NT, Windows 2000, must have admin rights
hPhysicalDriveIOCTL = CreateFile (driveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
// if (hPhysicalDriveIOCTL == INVALID_HANDLE_VALUE)
// printf ("Unable to open physical drive %d, error code: 0x%lX\n",
// drive, GetLastError ());if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)
{
GETVERSIONOUTPARAMS VersionParams;
DWORD cbBytesReturned = 0;// Get the version, etc of PhysicalDrive IOCTL
memset ((void*) &VersionParams, 0, sizeof(VersionParams));if ( ! DeviceIoControl (hPhysicalDriveIOCTL, DFP_GET_VERSION,
NULL,
0,
&VersionParams,
sizeof(VersionParams),
&cbBytesReturned, NULL) )
{
// printf ("DFP_GET_VERSION failed for drive %d\n", i);
// continue;
}// If there is a IDE device at number "i" issue commands
// to the device
if (VersionParams.bIDEDeviceMap > 0)
{
BYTE bIDCmd = 0; // IDE or ATAPI IDENTIFY cmd
SENDCMDINPARAMS scip;
//SENDCMDOUTPARAMS OutCmd;// Now, get the ID sector for all IDE devices in the system.
// If the device is ATAPI use the IDE_ATAPI_IDENTIFY command,
// otherwise use the IDE_ATA_IDENTIFY command
bIDCmd = IDE_ATAPI_IDENTIFY;// (VersionParams.bIDEDeviceMap >> drive & 0x10) ? //IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY; memset (&scip, 0, sizeof(scip));
memset (IdOutCmd, 0, sizeof(IdOutCmd)); if ( DoIDENTIFY (hPhysicalDriveIOCTL,
&scip,
(PSENDCMDOUTPARAMS)&IdOutCmd,
(BYTE) bIDCmd,
(BYTE) 0,
&cbBytesReturned))
{
DWORD diskdata [256];
int ijk = 0;
USHORT *pIdSector = (USHORT *)
((PSENDCMDOUTPARAMS) IdOutCmd) -> bBuffer;for (ijk = 0; ijk < 256; ijk++)
diskdata [ijk] = pIdSector [ijk];//PrintIdeInfo (drive, diskdata);
strcpy (m_szHardInfo, ConvertToString (diskdata, 10, 19));
rc = TRUE;
}
}CloseHandle (hPhysicalDriveIOCTL);
}return rc;
}BOOL CGetDiskId::GetDiskID(char *szIdBuf, int nLen, BOOL bNT)
{
*m_szHardInfo = 0;
if(bNT)
GetDiskIdNT();
else
GetDiskId9X();
if(*m_szHardInfo)
{
strncpy(szIdBuf, m_szHardInfo, nLen);
return TRUE;
}
return FALSE;
}BOOL CGetDiskId::ReadIdeDriveAsScsiDriveInNT()
{
BOOL rc = FALSE;
// int controller = 0;// for (controller = 0; controller < 2; controller++)
{
HANDLE hScsiDriveIOCTL = 0;
char driveName [256];// Try to get a handle to PhysicalDrive IOCTL, report failure
// and exit if can't.
strcpy (driveName, "\\\\.\\Scsi0:");// Windows NT, Windows 2000, any rights should do
hScsiDriveIOCTL = CreateFile (driveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
// if (hScsiDriveIOCTL == INVALID_HANDLE_VALUE)
// printf ("Unable to open SCSI controller %d, error code: 0x%lX\n",
// controller, GetLastError ());if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE)
{
int drive = 0;for (drive = 0; drive < 2; drive++)
{
char buffer [sizeof (SRB_IO_CONTROL) + SENDIDLENGTH];
SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer;
SENDCMDINPARAMS *pin =
(SENDCMDINPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
DWORD dummy;memset (buffer, 0, sizeof (buffer));
p -> HeaderLength = sizeof (SRB_IO_CONTROL);
p -> Timeout = 10000;
p -> Length = SENDIDLENGTH;
p -> ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
strncpy ((char *) p -> Signature, "SCSIDISK", 8);pin -> irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
pin -> bDriveNumber = drive;if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT,
buffer,
sizeof (SRB_IO_CONTROL) +
sizeof (SENDCMDINPARAMS) - 1,
buffer,
sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,
&dummy, NULL))
{
SENDCMDOUTPARAMS *pOut =
(SENDCMDOUTPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
IDSECTOR *pId = (IDSECTOR *) (pOut -> bBuffer);
if (pId -> sModelNumber [0])
{
DWORD diskdata [256];
int ijk = 0;
USHORT *pIdSector = (USHORT *) pId;for (ijk = 0; ijk < 256; ijk++)
diskdata [ijk] = pIdSector [ijk];//PrintIdeInfo (controller * 2 + drive, diskdata);
strcpy (m_szHardInfo, ConvertToString (diskdata, 10, 19));rc = TRUE;
}
}
}
CloseHandle (hScsiDriveIOCTL);
}
}return rc;}
BOOL CGetDiskId::DoIDENTIFY(HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum, PDWORD lpcbBytesReturned)
{
// Set up data structures for IDENTIFY command.
pSCIP -> cBufferSize = IDENTIFY_BUFFER_SIZE;
pSCIP -> irDriveRegs.bFeaturesReg = 0;
pSCIP -> irDriveRegs.bSectorCountReg = 1;
pSCIP -> irDriveRegs.bSectorNumberReg = 1;
pSCIP -> irDriveRegs.bCylLowReg = 0;
pSCIP -> irDriveRegs.bCylHighReg = 0;// Compute the drive number.
pSCIP -> irDriveRegs.bDriveHeadReg = 0xA0 | ((bDriveNum & 1) << 4);// The command can either be IDE identify or ATAPI identify.
pSCIP -> irDriveRegs.bCommandReg = bIDCmd;
pSCIP -> bDriveNumber = bDriveNum;
pSCIP -> cBufferSize = IDENTIFY_BUFFER_SIZE;return ( DeviceIoControl (hPhysicalDriveIOCTL, DFP_RECEIVE_DRIVE_DATA,
(LPVOID) pSCIP,
sizeof(SENDCMDINPARAMS) - 1,
(LPVOID) pSCOP,
sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
lpcbBytesReturned, NULL) );}
//网卡
#include <nb30.h>
//---------------------------------------------------------------------------
// 因为是通过NetAPI来获取网卡信息,所以需要包含其题头文件nb30.htypedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;ASTAT Adapter; // 定义一个存放返回网卡信息的变量
// 输入参数:lana_num为网卡编号,一般地,从0开始,但在Windows 2000中并不一定是连续分配的AnsiString getmac_one (int lana_num)
{
NCB ncb;
UCHAR uRetCode; memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_num;
// 指定网卡号 // 首先对选定的网卡发送一个NCBRESET命令,以便进行初始化
uRetCode = Netbios( &ncb );
//printf( "The NCBRESET return code is:0x%x \n", uRetCode ); memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_num; // 指定网卡号 strcpy( (char *)ncb.ncb_callname,"* " );
ncb.ncb_buffer = (unsigned char *) &Adapter; // 指定返回的信息存放的变量
ncb.ncb_length = sizeof(Adapter); // 接着,可以发送NCBASTAT命令以获取网卡的信息
uRetCode = Netbios( &ncb );
//printf( "The NCBASTAT is: 0x%x \n", uRetCode );
//printf( "The NCBASTAT return code is: 0x%x \n", uRetCode ); if ( uRetCode == 0 )
{
// 把网卡MAC地址格式化成常用的16进制形式,如0010-A4E4-5802
AnsiString NetSn="";
for (int i=0;i<6;i++)
{
NetSn+=IntToHex(Adapter.adapt.adapter_address[i],2);
}
return NetSn;
/*
printf( "The Ethernet Number[%d]is: %02X%02X-%02X%02X-%02X%02X\n",lana_num,
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
*/
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lana_enum; memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBENUM; ncb.ncb_buffer = (unsigned char *) &lana_enum;
ncb.ncb_length = sizeof(lana_enum); // 向网卡发送NCBENUM命令,以获取当前机器的网卡信息,如有多少个网卡、每张网卡的编号等
uRetCode = Netbios( &ncb );
//printf( "The NCBENUM returncode is:0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
//printf( "Ethernet Count is : %d\n\n", lana_enum.length); // 对每一张网卡,以其网卡编号为输入编号,获取其MAC地址
//for ( int i=0; i< lana_enum.length; ++i)
Label1->Caption=getmac_one( lana_enum.lana[0]);
}
}//映射网络驱动器
DWORD Error;
LPTSTR Local[22]={"Z:","Y:","X:","W:","V:","U:",
"T:","S:","R:","Q:","P:","O:","N:","M:",
"L:","K:","J:","I:","H:","G:","F:","E:"};
for (int i=0;i<22;i++)
{
Error=WNetAddConnection("\\\\MAIN\\wen","",Local[i]);
if (Error==NO_ERROR) return;
ch--;
if (Error==ERROR_ALREADY_ASSIGNED) continue;
ShowMessage("无法映射网络驱动器,请确定确定您有访问此目录的权限或有空闲的盘可以映射。");
}//IP Address
#include <winsock.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *buffer=new char[65];
struct hostent FAR * phe;
struct in_addr *pptr;
WSADATA GInitData;
WORD wVersionRequested;
wVersionRequested = MAKEWORD( 2, 0 );
AnsiString temp;
if(WSAStartup(wVersionRequested, &GInitData)!=0)
{
ShowMessage("init winsock error!");
delete []buffer;
return;
}
if(gethostname(buffer, 64)==SOCKET_ERROR)
{
ShowMessage("gethostname error");
delete []buffer;
return;
}
phe =gethostbyname(buffer);
if (phe == NULL)
{
ShowMessage("gerhostbyname error");
delete [] buffer;
return;
}
else
pptr =(struct in_addr *)*(phe->h_addr_list);
temp=inet_ntoa(*pptr);
ShowMessage(temp);
WSACleanup;
}
直接从RING3获取硬盘序列号(1)[ 作者: 陆麟 添加时间: 2001-6-2 0:04:28 ]
通常情况下,我们通过0XEC命令对IDE端口进行监测.获取硬盘信息.
一般情况下,我们就写个VXD或者DRIVER来完成.但是现在,通过MS的S.M.A.R.T.接口,我们可以
直接从RING3调用API DeviceIoControl()来获取硬盘信息.下面乃是我的例程:
另外,也有编译好的版本供大家平时使用.欢迎下载.
*注:在WIN98SE,WINDOWS ME中,S.M.A.R.T并不缺省安装.请将SMARTVSD.VXD拷贝到%SYSTEM%IOSUBSYS目录下.
在WINDOWS2000下,由于非ADMINISTRATORS组的用户对硬盘连GENERIC_READ的权限也没有,所以
请以ADMINISTRATOR登录后使用
#include <windows.h>
#include <iostream.h>
#include <stdio.h> #define DFP_GET_VERSION 0x00074080
#define DFP_SEND_DRIVE_COMMAND 0x0007c084
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088 #pragma pack(1)
typedef struct _GETVERSIONOUTPARAMS {
BYTE bVersion; // Binary driver version.
BYTE bRevision; // Binary driver revision.
BYTE bReserved; // Not used.
BYTE bIDEDeviceMap; // Bit map of IDE devices.
DWORD fCapabilities; // Bit mask of driver capabilities.
DWORD dwReserved[4]; // For future use.
} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; typedef struct _IDEREGS {
BYTE bFeaturesReg; // Used for specifying SMART "commands".
BYTE bSectorCountReg; // IDE sector count register
BYTE bSectorNumberReg; // IDE sector number register
BYTE bCylLowReg; // IDE low order cylinder value
BYTE bCylHighReg; // IDE high order cylinder value
BYTE bDriveHeadReg; // IDE drive/head register
BYTE bCommandReg; // Actual IDE command.
BYTE bReserved; // reserved for future use. Must be zero.
} IDEREGS, *PIDEREGS, *LPIDEREGS; typedef struct _SENDCMDINPARAMS {
DWORD cBufferSize; // Buffer size in bytes
IDEREGS irDriveRegs; // Structure with drive register values.
BYTE bDriveNumber; // Physical drive number to send
// command to (0,1,2,3).
BYTE bReserved[3]; // Reserved for future expansion.
DWORD dwReserved[4]; // For future use.
//BYTE bBuffer[1]; // Input buffer.
} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; typedef struct _DRIVERSTATUS {
BYTE bDriverError; // Error code from driver,
// or 0 if no error.
BYTE bIDEStatus; // Contents of IDE Error register.
// Only valid when bDriverError
// is SMART_IDE_ERROR.
BYTE bReserved[2]; // Reserved for future expansion.
DWORD dwReserved[2]; // Reserved for future expansion.
} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS; typedef struct _SENDCMDOUTPARAMS {
DWORD cBufferSize; // Size of bBuffer in bytes
DRIVERSTATUS DriverStatus; // Driver status structure.
BYTE bBuffer[512]; // Buffer of arbitrary length
// in which to store the data read from the drive.
} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS; typedef struct _IDSECTOR {
USHORT wGenConfig;
USHORT wNumCyls;
USHORT wReserved;
USHORT wNumHeads;
USHORT wBytesPerTrack;
USHORT wBytesPerSector;
USHORT wSectorsPerTrack;
USHORT wVendorUnique[3];
CHAR sSerialNumber[20];
USHORT wBufferType;
USHORT wBufferSize;
USHORT wECCSize;
CHAR sFirmwareRev[8];
CHAR sModelNumber[40];
USHORT wMoreVendorUnique;
USHORT wDoubleWordIO;
USHORT wCapabilities;
USHORT wReserved1;
USHORT wPIOTiming;
USHORT wDMATiming;
USHORT wBS;
USHORT wNumCurrentCyls;
USHORT wNumCurrentHeads;
USHORT wNumCurrentSectorsPerTrack;
ULONG ulCurrentSectorCapacity;
USHORT wMultSectorStuff;
ULONG ulTotalAddressableSectors;
USHORT wSingleWordDMA;
USHORT wMultiWordDMA;
BYTE bReserved[128];
} IDSECTOR, *PIDSECTOR; /*+++
Global vars
---*/
GETVERSIONOUTPARAMS vers;
SENDCMDINPARAMS in;
SENDCMDOUTPARAMS out;
HANDLE h;
DWORD i;
BYTE j; void CopyRight(){
cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<en
dl;
cerr<<"For more information, please visit Inside Programming: http://lu0.126.com"<<endl;
cerr<<"2000.11.3"<<endl<<endl;
}
VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
{ USHORT i;
CHAR temp; for (i = 0; i < uscStrSize; i+=2)
{
temp = szString[i];
szString[i] = szString[i+1];
szString[i+1] = temp;
}
} void DetectIDE(BYTE bIDEDeviceMap){
if (bIDEDeviceMap&1){
if (bIDEDeviceMap&16){
cout<<"ATAPI device is attached to primary controller, drive 0."<<endl;
}else{
cout<<"IDE device is attached to primary controller, drive 0."<<endl;
}
}
if (bIDEDeviceMap&2){
if (bIDEDeviceMap&32){
cout<<"ATAPI device is attached to primary controller, drive 1."<<endl;
}else{
cout<<"IDE device is attached to primary controller, drive 1."<<endl;
}
}
if (bIDEDeviceMap&4){
if (bIDEDeviceMap&64){
cout<<"ATAPI device is attached to secondary controller, drive 0."<<endl;
}else{
cout<<"IDE device is attached to secondary controller, drive 0."<<endl;
}
}
if (bIDEDeviceMap&8){
if (bIDEDeviceMap&128){
cout<<"ATAPI device is attached to secondary controller, drive 1."<<endl;
}else{
cout<<"IDE device is attached to secondary controller, drive 1."<<endl;
}
}
} void hdid9x(){
ZeroMemory(&vers,sizeof(vers));
//We start in 95/98/Me
h=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0);
if (!h){
cout<<"open smartvsd.vxd failed"<<endl;
exit(0);
} if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
cout<<"DeviceIoControl failed:DFP_GET_VERSION"<<endl;
CloseHandle(h);
return;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Display IDE drive number detected
DetectIDE(vers.bIDEDeviceMap);
//Identify the IDE drives
for (j=0;j<4;j++){
PIDSECTOR phdinfo;
char s[41]; ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&
i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl
;
} //Close handle before quit
CloseHandle(h);
CopyRight(); } void hdidnt(){
char hd[80];
PIDSECTOR phdinfo;
char s[41]; ZeroMemory(&vers,sizeof(vers));
//We start in NT/Win2000
for (j=0;j<4;j++){
sprintf(hd,"\\\\.\\PhysicalDrive%d",j);
h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (!h){
continue;
}
if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
CloseHandle(h);
continue;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Identify the IDE drives
ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device. cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&
i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl
;
CloseHandle(h);
}
CopyRight();
} void main(){
OSVERSIONINFO VersionInfo; ZeroMemory(&VersionInfo,sizeof(VersionInfo));
VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);
GetVersionEx(&VersionInfo); switch (VersionInfo.dwPlatformId){
case VER_PLATFORM_WIN32s:
cout<<"Win32s is not supported by this programm."<<endl;
return;
case VER_PLATFORM_WIN32_WINDOWS:
hdid9x();
return;
case VER_PLATFORM_WIN32_NT:
hdidnt();
return;
}
}
是shotgun写的
#include "stdio.h"
#include "stdlib.h"
#include "Winsock2.h"
#include "iphlpapi.h"
#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )
void main( int argc, char ** argv )
{
//处理命令行参数
if ( argc != 2 )
{
printf( "RmtHost v0.1 - Get remote HostName / MacAddress\n" );
printf( "by ShotgunLabs ( [email protected] )\n\n" );
printf( "Usage :\n\tRmtHost.exe [RemoteIP]\n\n" );
printf( "Example:\n\tRmtHost.exe 192.168.0.3\n\n" );
exit( 0 );
}
printf( "\nIpAddress : %s\n", argv[1] );
//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d\n", GetLastError() );
exit( 0 );
}
//获取远程机器名
hostent * remoteHostent = (hostent*)malloc( sizeof( hostent ) );
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr, sizeof( in_addr ), AF_INET );
if ( remoteHostent )
printf( "HostName : %s\n", remoteHostent->h_name );
else
printf( "gethostbyaddr Error:%d\n", GetLastError() );
//发送ARP查询包获得远程MAC地址
unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet = SendARP( nRemoteAddr, NULL, (PULONG)&macAddress, &macAddLen );
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i<6; i++ )
{
printf( "%.2x", macAddress[i] );
if ( i<5 ) printf( "-" );
}
}
else
printf( "SendARP Error:%d\n", GetLastError() );
printf( "\n" );
}
mail:[email protected]
(最好為vc的)
老出錯!
小弟一定給分!
mail:[email protected]
--------------------Configuration: GetHardWareInfo - Win32 Debug--------------------
Compiling...
GetHardWareInfo.c
d:\soft\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
Error executing cl.exe.
你发给我我也不能帮你什么!