Serial do HD! Como fazer funcionar corretamente??
Enviado: 14 Nov 2006 13:49
Olá amigos!
Estou bolando uma maneira de "proteção" via nr. de série do HD (não o nr. físico, mas aquele criado na formatação). Testei as duas rotinas abaixo que extrai acho que deste fórum mesmo e do grupo news, mas em alguns micros retornam valores incompatíveis com a série gravada no disco. Alguém teria uma rotina confiável em C compatível com o Harbour/Minigui para me passar? Desde agora fico grato por qualquer ajuda.
{}s
Antonio Carlos
ALGUNS TESTES/RETORNOS:
1) Retorno do decimal -531280383 sendo que o hd em hexa é E055-4E01
2) Retorno do decimal -796240570 sendo que o hd em hexa é D08A-5546
3) Retorno do decimal ********** sendo que o hd em hexa é A072-BEF0
PRIMEIRA ROTINA TESTADA (testei em vários micros XP e Windows 98)
#pragma begindump
#define HB_OS_WIN_32_USED
#include "windows.h"
#include "winbase.h"
#include "winuser.h"
#include "item.api"
#include "hbapi.h"
HB_FUNC( HDGETSERIAL)
{
unsigned long SerialNumber;
GetVolumeInformation(hb_parc(1), NULL, 0, &SerialNumber, NULL,
NULL, NULL, 0);
hb_retnl( SerialNumber );
}
#pragma enddump
SEGUNDA ROTINA:
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
#include "hbapiitm.h"
// Code From WHAT32 by AJ Wos <andrwos@aust1.net>
HB_FUNC(GETVOLUMEINFORMATION)
{
char *VolumeNameBuffer = (char *) hb_xgrab( MAX_PATH ) ;
DWORD VolumeSerialNumber ;
DWORD MaximumComponentLength ;
DWORD FileSystemFlags ;
char *FileSystemNameBuffer = (char *) hb_xgrab( MAX_PATH ) ;
BOOL bRet;
bRet = GetVolumeInformation( ISNIL(1) ? NULL : (LPCTSTR) hb_parc(1) ,
(LPTSTR) VolumeNameBuffer ,
MAX_PATH ,
&VolumeSerialNumber ,
&MaximumComponentLength ,
&FileSystemFlags ,
(LPTSTR)FileSystemNameBuffer ,
MAX_PATH ) ;
if ( bRet )
{
if ( ISBYREF( 2 ) ) hb_storc ((char *) VolumeNameBuffer, 2 ) ;
if ( ISBYREF( 3 ) ) hb_stornl( (LONG) VolumeSerialNumber, 3 ) ;
if ( ISBYREF( 4 ) ) hb_stornl( (LONG) MaximumComponentLength, 4 ) ;
if ( ISBYREF( 5 ) ) hb_stornl( (LONG) FileSystemFlags, 5 );
if ( ISBYREF( 6 ) ) hb_storc ((char *) FileSystemNameBuffer, 6 );
}
hb_retl(bRet);
hb_xfree( VolumeNameBuffer );
hb_xfree( FileSystemNameBuffer );
}
#pragma ENDDUMP
Estou bolando uma maneira de "proteção" via nr. de série do HD (não o nr. físico, mas aquele criado na formatação). Testei as duas rotinas abaixo que extrai acho que deste fórum mesmo e do grupo news, mas em alguns micros retornam valores incompatíveis com a série gravada no disco. Alguém teria uma rotina confiável em C compatível com o Harbour/Minigui para me passar? Desde agora fico grato por qualquer ajuda.
{}s
Antonio Carlos
ALGUNS TESTES/RETORNOS:
1) Retorno do decimal -531280383 sendo que o hd em hexa é E055-4E01
2) Retorno do decimal -796240570 sendo que o hd em hexa é D08A-5546
3) Retorno do decimal ********** sendo que o hd em hexa é A072-BEF0
PRIMEIRA ROTINA TESTADA (testei em vários micros XP e Windows 98)
#pragma begindump
#define HB_OS_WIN_32_USED
#include "windows.h"
#include "winbase.h"
#include "winuser.h"
#include "item.api"
#include "hbapi.h"
HB_FUNC( HDGETSERIAL)
{
unsigned long SerialNumber;
GetVolumeInformation(hb_parc(1), NULL, 0, &SerialNumber, NULL,
NULL, NULL, 0);
hb_retnl( SerialNumber );
}
#pragma enddump
SEGUNDA ROTINA:
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
#include "hbapiitm.h"
// Code From WHAT32 by AJ Wos <andrwos@aust1.net>
HB_FUNC(GETVOLUMEINFORMATION)
{
char *VolumeNameBuffer = (char *) hb_xgrab( MAX_PATH ) ;
DWORD VolumeSerialNumber ;
DWORD MaximumComponentLength ;
DWORD FileSystemFlags ;
char *FileSystemNameBuffer = (char *) hb_xgrab( MAX_PATH ) ;
BOOL bRet;
bRet = GetVolumeInformation( ISNIL(1) ? NULL : (LPCTSTR) hb_parc(1) ,
(LPTSTR) VolumeNameBuffer ,
MAX_PATH ,
&VolumeSerialNumber ,
&MaximumComponentLength ,
&FileSystemFlags ,
(LPTSTR)FileSystemNameBuffer ,
MAX_PATH ) ;
if ( bRet )
{
if ( ISBYREF( 2 ) ) hb_storc ((char *) VolumeNameBuffer, 2 ) ;
if ( ISBYREF( 3 ) ) hb_stornl( (LONG) VolumeSerialNumber, 3 ) ;
if ( ISBYREF( 4 ) ) hb_stornl( (LONG) MaximumComponentLength, 4 ) ;
if ( ISBYREF( 5 ) ) hb_stornl( (LONG) FileSystemFlags, 5 );
if ( ISBYREF( 6 ) ) hb_storc ((char *) FileSystemNameBuffer, 6 );
}
hb_retl(bRet);
hb_xfree( VolumeNameBuffer );
hb_xfree( FileSystemNameBuffer );
}
#pragma ENDDUMP