RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
Valeu cara, Obrigado pela ajuda acho que vou usar essa da CPU mesmo. Obrigado. De: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br] Em nome de Willian Jhonnes L. dos Santos Enviada em: quarta-feira, 27 de janeiro de 2010 20:30 Para: delphi-br@yahoogrupos.com.br Assunto: Re: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Em 27/1/2010 18:29, Iran Lima escreveu: Se alguém tiver uma função que retorne o serial físico do HD ou da BIOS , que funcione no D2010 e puder me passar ficarei grato.[ Iran Essa [1] eu testei até o Delphi 2007 e funciona apenas com HDs IDE. Mas abandonei esta idéia a partir do momento em q a maioria dos clientes começou a usar HDs SATA. Passei a usar a CPUID, que não varia, mesmo que o cliente troque o HD. Pra isso uso essa função [2]. [1]-- Function GetIdeSerialNumber:String; const IDENTIFY_BUFFER_SIZE = 512; type TIDERegs = packed record bFeaturesReg : BYTE; // Used for specifying SMART commands. bSectorCountReg : BYTE; // IDE sector count register bSectorNumberReg : BYTE; // IDE sector number register bCylLowReg : BYTE; // IDE low order cylinder value bCylHighReg : BYTE; // IDE high order cylinder value bDriveHeadReg : BYTE; // IDE drive/head register bCommandReg : BYTE; // Actual IDE command. bReserved : BYTE; // reserved for future use. Must be zero. end; TSendCmdInParams = packed record // Buffer size in bytes cBufferSize : DWORD; // Structure with drive register values. irDriveRegs : TIDERegs; // Physical drive number to send command to (0,1,2,3). bDriveNumber : BYTE; bReserved : Array[0..2] of Byte; dwReserved : Array[0..3] of DWORD; bBuffer : Array[0..0] of Byte; // Input buffer. end; TIdSector = packed record wGenConfig : Word; wNumCyls : Word; wReserved : Word; wNumHeads : Word; wBytesPerTrack : Word; wBytesPerSector : Word; wSectorsPerTrack : Word; wVendorUnique : Array[0..2] of Word; sSerialNumber : Array[0..19] of CHAR; wBufferType : Word; wBufferSize : Word; wECCSize : Word; sFirmwareRev : Array[0..7] of Char; sModelNumber : Array[0..39] of Char; wMoreVendorUnique : Word; wDoubleWordIO : Word; wCapabilities : Word; wReserved1 : Word; wPIOTiming : Word; wDMATiming : Word; wBS : Word; wNumCurrentCyls : Word; wNumCurrentHeads : Word; wNumCurrentSectorsPerTrack : Word; ulCurrentSectorCapacity : DWORD; wMultSectorStuff : Word; ulTotalAddressableSectors : DWORD; wSingleWordDMA : Word; wMultiWordDMA : Word; bReserved : Array[0..127] of BYTE; end; PIdSector = ^TIdSector; TDriverStatus = packed record // Error code from driver, or 0 if no error. bDriverError : Byte; // Contents of IDE Error register. Only valid when bDriverError is SMART_IDE_ERROR. bIDEStatus : Byte; bReserved : Array[0..1] of Byte; dwReserved : Array[0..1] of DWORD; end; TSendCmdOutParams = packed record // Size of bBuffer in bytes cBufferSize : DWORD; // Driver status structure. DriverStatus : TDriverStatus; // Buffer of arbitrary length in which to store the data read from the drive. bBuffer : Array[0..0] of BYTE; end; var hDevice : THandle; cbBytesReturned : DWORD; ptr : PChar; SCIP : TSendCmdInParams; aIdOutCmd : Array [0..(SizeOf(TSendCmdOutParams)+IDENTIFY_BUFFER_SIZE-1)-1] of Byte; IdOutCmd : TSendCmdOutParams absolute aIdOutCmd; procedure ChangeByteOrder( var Data; Size : Integer ); var Ptr: PChar; I: Integer; C: Char; Begin Ptr := @Data; For I := 0 to (Size shr 1) - 1 Do Begin C := Ptr^; Ptr^ := (Ptr + 1)^; (Ptr + 1)^ := C; Inc(Ptr, 2); end; end; Begin Result := ''; // return empty String on error If SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then // Windows NT, Windows 2000 begin // warning! change name for other drives: ex.: second drive '\\.\PhysicalDrive1\' hDevice := CreateFile( '\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0 ); end Else // Version Windows 95 OSR2, Windows 98 hDevice := CreateFile( '\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0 ); If hDevice=INVALID_HANDLE_VALUE Then Exit; Try FillChar(SCIP,SizeOf(TSendCmdInParams)-1,#0); FillChar(aIdOutCmd,SizeOf(aIdOutCmd),#0); cbBytesReturned := 0; // Set up data structures for IDENTIFY command. With SCIP Do Begin cBufferSize := IDENTIFY_BUFFER_SIZE; // bDriveNumber := 0; With irDriveRegs Do Begin bSectorCountReg := 1; bSectorNumberReg := 1; // if Win32Platform=VER_PLATFORM_WIN32_NT then bDriveHeadReg := $A0 // else bDriveHeadReg := $A0 or ((bDriveNum and 1) shl 4); bDriveHeadReg := $A0; bCommandReg := $EC; end; end; If not DeviceIoControl( hDevice, $0007c088, @SCIP, SizeOf(TSendCmdInParams) - 1, @aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) Then Exit; Finally CloseHandle(hDevice); end; With PIdSector(@IdOutCmd.bBuffer)^ Do Begin ChangeByteOrder( sSerialNumber, SizeOf(sSerialNumber) ); (PChar(@sSerialNumber)+SizeOf(sSerialNumber))^ := #0; Result := PChar(@sSerialNumber); end; end; [/1]--
Res: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
tem tambem o detalhe do sistema operacional, se for 64 bits tambem não funciona De: Rubem Rocha rubem.ro...@dtmanaus.com.br Para: delphi-br@yahoogrupos.com.br Enviadas: Terça-feira, 26 de Janeiro de 2010 19:50:24 Assunto: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Outras coisas: 1) Vc quer pegar o serial de um HD SCSI ou IDE? Essa daí só funciona pra SCSI. Do mesmo jeito q vc conseguiu essa pra SCSI, vc tb vai conseguir a função pra IDE. 2) Cadê o código dessa rotina ChangeByteOrder? Sds. De: delphi...@yahoogrup os.com.br [mailto:delphi...@yahoogrup os.com.br] Em nome de Iran Lima Enviada em: terça-feira, 26 de janeiro de 2010 16:55 Para: delphi...@yahoogrup os.com.br Assunto: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Gente o que muda na função migrando para o Delphi 2010 ??? Existe AnsiWord e AnsiByte ?? hehe, to botando tudo “ANSI” function GetIdeDiskSerialNum ber : String; type TSrbIoControl = packed record HeaderLength: ULONG; Signature: Array[0..7] of Char; Timeout: ULONG; ControlCode: ULONG; ReturnCode: ULONG; Length: ULONG; end; SRB_IO_CONTROL = TSrbIoControl; PSrbIoControl = ^TSrbIoControl; TIDERegs = packed record bFeaturesReg : Byte; // especificar comandos SMART bSectorCountReg : Byte; // registro de contador de setor bSectorNumberReg : Byte; // registro de número de setores bCylLowReg : Byte; // valor de cilindro (byte mais baixo) bCylHighReg : Byte; // valor de cilindro (byte mais alto) bDriveHeadReg : Byte; // registro de drive/cabeça bCommandReg : Byte; // comando IDE bReserved : Byte; // reservado- tem que ser zero end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs; TSendCmdInParams = packed record cBufferSize : DWORD; irDriveRegs : TIDERegs; bDriveNumber : Byte; bReserved : Array[0..2] of Byte; dwReserved : Array[0..3] of DWORD; bBuffer : Array[0..0] of Byte; end; SENDCMDINPARAMS = TSendCmdInParams; PSendCmdInParams = ^TSendCmdInParams; TIdSector = packed record wGenConfig : Word; wNumCyls : Word; wReserved : Word; wNumHeads : Word; wBytesPerTrack : Word; wBytesPerSector : Word; wSectorsPerTrack : Word; wVendorUnique : Array[0..2] of Word; sSerialNumber : Array[0..19] of Char; wBufferType : Word; wBufferSize : Word; wECCSize : Word; sFirmwareRev : Array[0..7] of Char; sModelNumber : Array[0..39] of Char; wMoreVendorUnique : Word; wDoubleWordIO : Word; wCapabilities : Word; wReserved1 : Word; wPIOTiming : Word; wDMATiming : Word; wBS : Word; wNumCurrentCyls : Word; wNumCurrentHeads : Word; wNumCurrentSectorsP erTrack : Word; ulCurrentSectorCapa city : ULONG; wMultSectorStuff : Word; ulTotalAddressableS ectors : ULONG; wSingleWordDMA : Word; wMultiWordDMA : Word; bReserved : Array[0..127] of Byte; end; PIdSector = ^TIdSector; const IDE_ID_FUNCTION = $EC; IDENTIFY_BUFFER_ SIZE = 512; DFP_RECEIVE_ DRIVE_DATA = $0007c088; IOCTL_SCSI_MINIPORT = $0004d008; IOCTL_SCSI_MINIPORT _IDENTIFY = $001b0501; DataSize = sizeof(TSendCmdInPa rams)-1+IDENTIFY _BUFFER_SIZE; BufferSize = SizeOf(SRB_IO_ CONTROL)+ DataSize; W9xBufferSize = IDENTIFY_BUFFER_ SIZE+16; var hDevice : THandle; cbBytesReturned : DWORD; pInData : PSendCmdInParams; pOutData : Pointer; // PSendCmdOutParams Buffer : Array[0..BufferSize -1] of Byte; srbControl : TSrbIoControl absolute Buffer; begin Result := ''; FillChar(Buffer, BufferSize, #0); if Win32Platform= VER_PLATFORM_ WIN32_NT then // Windows NT, Windows 2000, Windows XP begin // recuperar handle da porta SCSI hDevice := CreateFile(PChar( '\\.\' + GetSysDrive) , // Nota: '\\.\C:' precisa de privilégios administrativos GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hDevice=INVALID_ HANDLE_VALUE then Exit; try srbControl.HeaderLe ngth := SizeOf(SRB_IO_ CONTROL); System.Move( 'SCSIDISK' ,srbControl. Signature, 8); srbControl.Timeout := 2; srbControl.Length := DataSize; srbControl.ControlC ode := IOCTL_SCSI_MINIPORT _IDENTIFY; pInData := PSendCmdInParams( PChar(@Buffer) +SizeOf(SRB_ IO_CONTROL) ); pOutData := pInData; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_ SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT , @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ) then Exit; finally CloseHandle( hDevice); end; end else begin // Windows 95 OSR2, Windows 98, Windows ME hDevice := CreateFile( '\\.\SMARTVSD' , 0, 0, nil, CREATE_NEW, 0, 0 ); if hDevice=INVALID_ HANDLE_VALUE then Exit; try pInData := PSendCmdInParams( @Buffer); pOutData := @pInData^.bBuffer; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_ SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0
RES: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
To querendo migrar pro delphi 2010, mas até agora não consegui fazer a função funcionar Peguei a função no link : http://www.planetadelphi.com.br/dica/6585/Descobrir%20serial%20do%20hd Se alguém tiver uma função que retorne o serial físico do HD ou da BIOS , que funcione no D2010 e puder me passar ficarei grato.[ Iran De: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br] Em nome de Marcelo Enviada em: terça-feira, 26 de janeiro de 2010 19:57 Para: delphi-br@yahoogrupos.com.br Assunto: Res: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 tem tambem o detalhe do sistema operacional, se for 64 bits tambem não funciona De: Rubem Rocha rubem.ro...@dtmanaus.com.br mailto:rubem.rocha%40dtmanaus.com.br Para: delphi-br@yahoogrupos.com.br mailto:delphi-br%40yahoogrupos.com.br Enviadas: Terça-feira, 26 de Janeiro de 2010 19:50:24 Assunto: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Outras coisas: 1) Vc quer pegar o serial de um HD SCSI ou IDE? Essa daí só funciona pra SCSI. Do mesmo jeito q vc conseguiu essa pra SCSI, vc tb vai conseguir a função pra IDE. 2) Cadê o código dessa rotina ChangeByteOrder? Sds. De: delphi...@yahoogrup os.com.br [mailto:delphi...@yahoogrup os.com.br] Em nome de Iran Lima Enviada em: terça-feira, 26 de janeiro de 2010 16:55 Para: delphi...@yahoogrup os.com.br Assunto: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Gente o que muda na função migrando para o Delphi 2010 ??? Existe AnsiWord e AnsiByte ?? hehe, to botando tudo “ANSI” function GetIdeDiskSerialNum ber : String; type TSrbIoControl = packed record HeaderLength: ULONG; Signature: Array[0..7] of Char; Timeout: ULONG; ControlCode: ULONG; ReturnCode: ULONG; Length: ULONG; end; SRB_IO_CONTROL = TSrbIoControl; PSrbIoControl = ^TSrbIoControl; TIDERegs = packed record bFeaturesReg : Byte; // especificar comandos SMART bSectorCountReg : Byte; // registro de contador de setor bSectorNumberReg : Byte; // registro de número de setores bCylLowReg : Byte; // valor de cilindro (byte mais baixo) bCylHighReg : Byte; // valor de cilindro (byte mais alto) bDriveHeadReg : Byte; // registro de drive/cabeça bCommandReg : Byte; // comando IDE bReserved : Byte; // reservado- tem que ser zero end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs; TSendCmdInParams = packed record cBufferSize : DWORD; irDriveRegs : TIDERegs; bDriveNumber : Byte; bReserved : Array[0..2] of Byte; dwReserved : Array[0..3] of DWORD; bBuffer : Array[0..0] of Byte; end; SENDCMDINPARAMS = TSendCmdInParams; PSendCmdInParams = ^TSendCmdInParams; TIdSector = packed record wGenConfig : Word; wNumCyls : Word; wReserved : Word; wNumHeads : Word; wBytesPerTrack : Word; wBytesPerSector : Word; wSectorsPerTrack : Word; wVendorUnique : Array[0..2] of Word; sSerialNumber : Array[0..19] of Char; wBufferType : Word; wBufferSize : Word; wECCSize : Word; sFirmwareRev : Array[0..7] of Char; sModelNumber : Array[0..39] of Char; wMoreVendorUnique : Word; wDoubleWordIO : Word; wCapabilities : Word; wReserved1 : Word; wPIOTiming : Word; wDMATiming : Word; wBS : Word; wNumCurrentCyls : Word; wNumCurrentHeads : Word; wNumCurrentSectorsP erTrack : Word; ulCurrentSectorCapa city : ULONG; wMultSectorStuff : Word; ulTotalAddressableS ectors : ULONG; wSingleWordDMA : Word; wMultiWordDMA : Word; bReserved : Array[0..127] of Byte; end; PIdSector = ^TIdSector; const IDE_ID_FUNCTION = $EC; IDENTIFY_BUFFER_ SIZE = 512; DFP_RECEIVE_ DRIVE_DATA = $0007c088; IOCTL_SCSI_MINIPORT = $0004d008; IOCTL_SCSI_MINIPORT _IDENTIFY = $001b0501; DataSize = sizeof(TSendCmdInPa rams)-1+IDENTIFY _BUFFER_SIZE; BufferSize = SizeOf(SRB_IO_ CONTROL)+ DataSize; W9xBufferSize = IDENTIFY_BUFFER_ SIZE+16; var hDevice : THandle; cbBytesReturned : DWORD; pInData : PSendCmdInParams; pOutData : Pointer; // PSendCmdOutParams Buffer : Array[0..BufferSize -1] of Byte; srbControl : TSrbIoControl absolute Buffer; begin Result := ''; FillChar(Buffer, BufferSize, #0); if Win32Platform= VER_PLATFORM_ WIN32_NT then // Windows NT, Windows 2000, Windows XP begin // recuperar handle da porta SCSI hDevice := CreateFile(PChar( '\\.\' + GetSysDrive) , // Nota: '\\.\C:' precisa de privilégios administrativos GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hDevice=INVALID_ HANDLE_VALUE then Exit; try srbControl.HeaderLe ngth := SizeOf(SRB_IO_ CONTROL); System.Move( 'SCSIDISK' ,srbControl. Signature, 8); srbControl.Timeout := 2; srbControl.Length := DataSize; srbControl.ControlC ode := IOCTL_SCSI_MINIPORT _IDENTIFY; pInData := PSendCmdInParams( PChar(@Buffer) +SizeOf(SRB_ IO_CONTROL) ); pOutData := pInData; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_ SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1
RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
Não ocorre nenhuma exceção apenas não retorna o numero correto. A função retorna um monte de caracteres (Chinês, japonês aparece de tudo). O mais importante você, com certeza, não falou: qual é o erro/exceção que ocorre? Sds. [As partes desta mensagem que não continham texto foram removidas]
RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
Não postei todo o código, achei que dava pra saber pela função principal, já que o problema é de compatibilidade com o D2010. Function GetSysDrive: String; begin Result := ExcludeTrailingPathDelimiter(ExtractFileDrive(GetWindowsDir)); end; Obrigado pela ajuda. De: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br] Em nome de Rubem Rocha Enviada em: terça-feira, 26 de janeiro de 2010 18:55 Para: delphi-br@yahoogrupos.com.br Assunto: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Prioridade: Alta E essa função GetSysDrive()? Cadê? Tá vendo, pressa pra querer as coisa resolvida e esquece de, além de explicar com detalhes a dúvida, pedaços de código! L Sds. [As partes desta mensagem que não continham texto foram removidas]
RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
O mais importante você, com certeza, não falou: qual é o erro/exceção que ocorre? Sds. De: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br] Em nome de Iran Lima Enviada em: terça-feira, 26 de janeiro de 2010 16:55 Para: delphi-br@yahoogrupos.com.br Assunto: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Gente o que muda na função migrando para o Delphi 2010 ??? Existe AnsiWord e AnsiByte ?? hehe, to botando tudo ANSI function GetIdeDiskSerialNumber : String; type TSrbIoControl = packed record HeaderLength: ULONG; Signature: Array[0..7] of Char; Timeout: ULONG; ControlCode: ULONG; ReturnCode: ULONG; Length: ULONG; end; SRB_IO_CONTROL = TSrbIoControl; PSrbIoControl = ^TSrbIoControl; TIDERegs = packed record bFeaturesReg : Byte; // especificar comandos SMART bSectorCountReg : Byte; // registro de contador de setor bSectorNumberReg : Byte; // registro de número de setores bCylLowReg : Byte; // valor de cilindro (byte mais baixo) bCylHighReg : Byte; // valor de cilindro (byte mais alto) bDriveHeadReg : Byte; // registro de drive/cabeça bCommandReg : Byte; // comando IDE bReserved : Byte; // reservado- tem que ser zero end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs; TSendCmdInParams = packed record cBufferSize : DWORD; irDriveRegs : TIDERegs; bDriveNumber : Byte; bReserved : Array[0..2] of Byte; dwReserved : Array[0..3] of DWORD; bBuffer : Array[0..0] of Byte; end; SENDCMDINPARAMS = TSendCmdInParams; PSendCmdInParams = ^TSendCmdInParams; TIdSector = packed record wGenConfig : Word; wNumCyls : Word; wReserved : Word; wNumHeads : Word; wBytesPerTrack : Word; wBytesPerSector : Word; wSectorsPerTrack : Word; wVendorUnique : Array[0..2] of Word; sSerialNumber : Array[0..19] of Char; wBufferType : Word; wBufferSize : Word; wECCSize : Word; sFirmwareRev : Array[0..7] of Char; sModelNumber : Array[0..39] of Char; wMoreVendorUnique : Word; wDoubleWordIO : Word; wCapabilities : Word; wReserved1 : Word; wPIOTiming : Word; wDMATiming : Word; wBS : Word; wNumCurrentCyls : Word; wNumCurrentHeads : Word; wNumCurrentSectorsPerTrack : Word; ulCurrentSectorCapacity : ULONG; wMultSectorStuff : Word; ulTotalAddressableSectors : ULONG; wSingleWordDMA : Word; wMultiWordDMA : Word; bReserved : Array[0..127] of Byte; end; PIdSector = ^TIdSector; const IDE_ID_FUNCTION = $EC; IDENTIFY_BUFFER_SIZE = 512; DFP_RECEIVE_DRIVE_DATA = $0007c088; IOCTL_SCSI_MINIPORT = $0004d008; IOCTL_SCSI_MINIPORT_IDENTIFY = $001b0501; DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE; BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize; W9xBufferSize = IDENTIFY_BUFFER_SIZE+16; var hDevice : THandle; cbBytesReturned : DWORD; pInData : PSendCmdInParams; pOutData : Pointer; // PSendCmdOutParams Buffer : Array[0..BufferSize-1] of Byte; srbControl : TSrbIoControl absolute Buffer; begin Result := ''; FillChar(Buffer,BufferSize,#0); if Win32Platform=VER_PLATFORM_WIN32_NT then // Windows NT, Windows 2000, Windows XP begin // recuperar handle da porta SCSI hDevice := CreateFile(PChar('\\.\' + GetSysDrive), // Nota: '\\.\C:' precisa de privilégios administrativos GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hDevice=INVALID_HANDLE_VALUE then Exit; try srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL); System.Move('SCSIDISK',srbControl.Signature,8); srbControl.Timeout := 2; srbControl.Length := DataSize; srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY; pInData := PSendCmdInParams(PChar(@Buffer) +SizeOf(SRB_IO_CONTROL)); pOutData := pInData; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ) then Exit; finally CloseHandle(hDevice); end; end else begin // Windows 95 OSR2, Windows 98, Windows ME hDevice := CreateFile( '\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0 ); if hDevice=INVALID_HANDLE_VALUE then Exit; try pInData := PSendCmdInParams(@Buffer); pOutData := @pInData^.bBuffer; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA, pInData, SizeOf(TSendCmdInParams)-1, pOutData, W9xBufferSize, cbBytesReturned, nil ) then Exit; finally CloseHandle(hDevice); end; end; with PIdSector(PChar(pOutData)+16)^ do begin ChangeByteOrder(sSerialNumber,SizeOf(sSerialNumber)); SetString(Result,sSerialNumber,SizeOf(sSerialNumber)); end;
RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
Outras coisas: 1) Vc quer pegar o serial de um HD SCSI ou IDE? Essa daí só funciona pra SCSI. Do mesmo jeito q vc conseguiu essa pra SCSI, vc tb vai conseguir a função pra IDE. 2) Cadê o código dessa rotina ChangeByteOrder? Sds. De: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br] Em nome de Iran Lima Enviada em: terça-feira, 26 de janeiro de 2010 16:55 Para: delphi-br@yahoogrupos.com.br Assunto: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Gente o que muda na função migrando para o Delphi 2010 ??? Existe AnsiWord e AnsiByte ?? hehe, to botando tudo ANSI function GetIdeDiskSerialNumber : String; type TSrbIoControl = packed record HeaderLength: ULONG; Signature: Array[0..7] of Char; Timeout: ULONG; ControlCode: ULONG; ReturnCode: ULONG; Length: ULONG; end; SRB_IO_CONTROL = TSrbIoControl; PSrbIoControl = ^TSrbIoControl; TIDERegs = packed record bFeaturesReg : Byte; // especificar comandos SMART bSectorCountReg : Byte; // registro de contador de setor bSectorNumberReg : Byte; // registro de número de setores bCylLowReg : Byte; // valor de cilindro (byte mais baixo) bCylHighReg : Byte; // valor de cilindro (byte mais alto) bDriveHeadReg : Byte; // registro de drive/cabeça bCommandReg : Byte; // comando IDE bReserved : Byte; // reservado- tem que ser zero end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs; TSendCmdInParams = packed record cBufferSize : DWORD; irDriveRegs : TIDERegs; bDriveNumber : Byte; bReserved : Array[0..2] of Byte; dwReserved : Array[0..3] of DWORD; bBuffer : Array[0..0] of Byte; end; SENDCMDINPARAMS = TSendCmdInParams; PSendCmdInParams = ^TSendCmdInParams; TIdSector = packed record wGenConfig : Word; wNumCyls : Word; wReserved : Word; wNumHeads : Word; wBytesPerTrack : Word; wBytesPerSector : Word; wSectorsPerTrack : Word; wVendorUnique : Array[0..2] of Word; sSerialNumber : Array[0..19] of Char; wBufferType : Word; wBufferSize : Word; wECCSize : Word; sFirmwareRev : Array[0..7] of Char; sModelNumber : Array[0..39] of Char; wMoreVendorUnique : Word; wDoubleWordIO : Word; wCapabilities : Word; wReserved1 : Word; wPIOTiming : Word; wDMATiming : Word; wBS : Word; wNumCurrentCyls : Word; wNumCurrentHeads : Word; wNumCurrentSectorsPerTrack : Word; ulCurrentSectorCapacity : ULONG; wMultSectorStuff : Word; ulTotalAddressableSectors : ULONG; wSingleWordDMA : Word; wMultiWordDMA : Word; bReserved : Array[0..127] of Byte; end; PIdSector = ^TIdSector; const IDE_ID_FUNCTION = $EC; IDENTIFY_BUFFER_SIZE = 512; DFP_RECEIVE_DRIVE_DATA = $0007c088; IOCTL_SCSI_MINIPORT = $0004d008; IOCTL_SCSI_MINIPORT_IDENTIFY = $001b0501; DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE; BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize; W9xBufferSize = IDENTIFY_BUFFER_SIZE+16; var hDevice : THandle; cbBytesReturned : DWORD; pInData : PSendCmdInParams; pOutData : Pointer; // PSendCmdOutParams Buffer : Array[0..BufferSize-1] of Byte; srbControl : TSrbIoControl absolute Buffer; begin Result := ''; FillChar(Buffer,BufferSize,#0); if Win32Platform=VER_PLATFORM_WIN32_NT then // Windows NT, Windows 2000, Windows XP begin // recuperar handle da porta SCSI hDevice := CreateFile(PChar('\\.\' + GetSysDrive), // Nota: '\\.\C:' precisa de privilégios administrativos GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hDevice=INVALID_HANDLE_VALUE then Exit; try srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL); System.Move('SCSIDISK',srbControl.Signature,8); srbControl.Timeout := 2; srbControl.Length := DataSize; srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY; pInData := PSendCmdInParams(PChar(@Buffer) +SizeOf(SRB_IO_CONTROL)); pOutData := pInData; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ) then Exit; finally CloseHandle(hDevice); end; end else begin // Windows 95 OSR2, Windows 98, Windows ME hDevice := CreateFile( '\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0 ); if hDevice=INVALID_HANDLE_VALUE then Exit; try pInData := PSendCmdInParams(@Buffer); pOutData := @pInData^.bBuffer; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA, pInData, SizeOf(TSendCmdInParams)-1, pOutData, W9xBufferSize, cbBytesReturned, nil ) then Exit; finally CloseHandle(hDevice); end; end; with
RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010
E essa função GetSysDrive()? Cadê? Tá vendo, pressa pra querer as coisa resolvida e esquece de, além de explicar com detalhes a dúvida, pedaços de código! L Sds. De: Rubem Rocha [mailto:rubem.ro...@dtmanaus.com.br] Enviada em: terça-feira, 26 de janeiro de 2010 17:50 Para: 'delphi-br@yahoogrupos.com.br' Assunto: RES: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Prioridade: Alta Outras coisas: 1) Vc quer pegar o serial de um HD SCSI ou IDE? Essa daí só funciona pra SCSI. Do mesmo jeito q vc conseguiu essa pra SCSI, vc tb vai conseguir a função pra IDE. 2) Cadê o código dessa rotina ChangeByteOrder? Sds. De: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br] Em nome de Iran Lima Enviada em: terça-feira, 26 de janeiro de 2010 16:55 Para: delphi-br@yahoogrupos.com.br Assunto: [delphi-br] Pegar Serial Fisico de HD no Delphi 2010 Gente o que muda na função migrando para o Delphi 2010 ??? Existe AnsiWord e AnsiByte ?? hehe, to botando tudo ANSI function GetIdeDiskSerialNumber : String; type TSrbIoControl = packed record HeaderLength: ULONG; Signature: Array[0..7] of Char; Timeout: ULONG; ControlCode: ULONG; ReturnCode: ULONG; Length: ULONG; end; SRB_IO_CONTROL = TSrbIoControl; PSrbIoControl = ^TSrbIoControl; TIDERegs = packed record bFeaturesReg : Byte; // especificar comandos SMART bSectorCountReg : Byte; // registro de contador de setor bSectorNumberReg : Byte; // registro de número de setores bCylLowReg : Byte; // valor de cilindro (byte mais baixo) bCylHighReg : Byte; // valor de cilindro (byte mais alto) bDriveHeadReg : Byte; // registro de drive/cabeça bCommandReg : Byte; // comando IDE bReserved : Byte; // reservado- tem que ser zero end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs; TSendCmdInParams = packed record cBufferSize : DWORD; irDriveRegs : TIDERegs; bDriveNumber : Byte; bReserved : Array[0..2] of Byte; dwReserved : Array[0..3] of DWORD; bBuffer : Array[0..0] of Byte; end; SENDCMDINPARAMS = TSendCmdInParams; PSendCmdInParams = ^TSendCmdInParams; TIdSector = packed record wGenConfig : Word; wNumCyls : Word; wReserved : Word; wNumHeads : Word; wBytesPerTrack : Word; wBytesPerSector : Word; wSectorsPerTrack : Word; wVendorUnique : Array[0..2] of Word; sSerialNumber : Array[0..19] of Char; wBufferType : Word; wBufferSize : Word; wECCSize : Word; sFirmwareRev : Array[0..7] of Char; sModelNumber : Array[0..39] of Char; wMoreVendorUnique : Word; wDoubleWordIO : Word; wCapabilities : Word; wReserved1 : Word; wPIOTiming : Word; wDMATiming : Word; wBS : Word; wNumCurrentCyls : Word; wNumCurrentHeads : Word; wNumCurrentSectorsPerTrack : Word; ulCurrentSectorCapacity : ULONG; wMultSectorStuff : Word; ulTotalAddressableSectors : ULONG; wSingleWordDMA : Word; wMultiWordDMA : Word; bReserved : Array[0..127] of Byte; end; PIdSector = ^TIdSector; const IDE_ID_FUNCTION = $EC; IDENTIFY_BUFFER_SIZE = 512; DFP_RECEIVE_DRIVE_DATA = $0007c088; IOCTL_SCSI_MINIPORT = $0004d008; IOCTL_SCSI_MINIPORT_IDENTIFY = $001b0501; DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE; BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize; W9xBufferSize = IDENTIFY_BUFFER_SIZE+16; var hDevice : THandle; cbBytesReturned : DWORD; pInData : PSendCmdInParams; pOutData : Pointer; // PSendCmdOutParams Buffer : Array[0..BufferSize-1] of Byte; srbControl : TSrbIoControl absolute Buffer; begin Result := ''; FillChar(Buffer,BufferSize,#0); if Win32Platform=VER_PLATFORM_WIN32_NT then // Windows NT, Windows 2000, Windows XP begin // recuperar handle da porta SCSI hDevice := CreateFile(PChar('\\.\' + GetSysDrive), // Nota: '\\.\C:' precisa de privilégios administrativos GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hDevice=INVALID_HANDLE_VALUE then Exit; try srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL); System.Move('SCSIDISK',srbControl.Signature,8); srbControl.Timeout := 2; srbControl.Length := DataSize; srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY; pInData := PSendCmdInParams(PChar(@Buffer) +SizeOf(SRB_IO_CONTROL)); pOutData := pInData; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ) then Exit; finally CloseHandle(hDevice); end; end else begin // Windows 95 OSR2, Windows 98, Windows ME hDevice := CreateFile( '\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0 ); if hDevice=INVALID_HANDLE_VALUE then Exit; try pInData := PSendCmdInParams(@Buffer); pOutData := @pInData^.bBuffer; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0