Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-10-2016
buenarquero buenarquero is offline
Miembro
 
Registrado: feb 2008
Posts: 33
Poder: 0
buenarquero Va por buen camino
Muchas gracias escafandra, voy a probarlo. Ya os digo como fue.
Responder Con Cita
  #2  
Antiguo 21-10-2016
buenarquero buenarquero is offline
Miembro
 
Registrado: feb 2008
Posts: 33
Poder: 0
buenarquero Va por buen camino
Bueno, pues parece que no hay suerte. El código que me has puesto, escafandra, no funciona. es posible que falte poner algo en el uses, pero desconozco el que. Me da todos estos errores:

[Error] Unit1.pas(34): Incompatible types: 'ShortString' and 'PAnsiChar'
[Error] Unit1.pas(34): Types of actual and formal var parameters must be identical
[Error] Unit1.pas(35): Undeclared identifier: 'Device'
[Error] Unit1.pas(44): Function needs result type
[Error] Unit1.pas(52): Undeclared identifier: 'ValueName'
[Error] Unit1.pas(52): Undeclared identifier: 'Drive'
[Error] Unit1.pas(54): Undeclared identifier: 'Device'
[Error] Unit1.pas(54): Types of actual and formal var parameters must be identical
[Error] Unit1.pas(62): Undeclared identifier: 'SerialNumber'
[Error] Unit1.pas(64): Operator not applicable to this operand type
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
Responder Con Cita
  #3  
Antiguo 21-10-2016
buenarquero buenarquero is offline
Miembro
 
Registrado: feb 2008
Posts: 33
Poder: 0
buenarquero Va por buen camino
Intento corregir los errores que da el código al compilarlo, pero con mis conocimientos no lo consigo.
También deduzco revisando el código que el número de serie pretende obtenerlo del registro de Windows, ¿me equivoco?. Si es así, no es esto lo que pretendo, sino leerlo directamente del pendrive.
De todas formas gracias por vuestra aportación. A ver si hay alguien que pueda desfacer el entuerto.
Responder Con Cita
  #4  
Antiguo 23-10-2016
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.210
Poder: 22
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Cita:
Empezado por buenarquero Ver Mensaje
Intento corregir los errores que da el código al compilarlo, pero con mis conocimientos no lo consigo.
También deduzco revisando el código que el número de serie pretende obtenerlo del registro de Windows, ¿me equivoco?. Si es así, no es esto lo que pretendo, sino leerlo directamente del pendrive.
De todas formas gracias por vuestra aportación. A ver si hay alguien que pueda desfacer el entuerto.
Windows cuando instala un nuevo dispositivo USB guarda su número de serie en el registro y es por eso que el código lo busca en el registro de Windows.


El código de cHackAll es un poco antiguo. Lo he reformado para un Win10 64 bits en una unit de un proyecto simple de ejemplo compilado en delphi 7:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function  StrStrI(s1: PCHAR; s2: PCHAR): PCHAR; stdcall; external 'Shlwapi.dll' name 'StrStrIA';

var
  Form1: TForm1;

implementation
{$R *.dfm}
var
 Device: ShortString;
 ValueName: array [0..15] of Char = '\DosDevices\\:';


function Search(hParent: HKEY; var SubKey: ShortString): LongBool;
var
 hChild: HKEY;
 Index: Cardinal;
 Data: ShortString;
 Size: integer;
 ValueType: DWORD;
begin
 Result:= false;
 Index := 0;
 Size:= sizeof(Data);
 ValueType:=0;
 RegOpenKey(hParent, @SubKey[1], hChild);
 repeat
   RegEnumKey(hChild, Index, @SubKey[1], SizeOf(SubKey) - 1);
   Inc(Index);
 until StrStrI(@SubKey[1], @Device) <> nil;
 hParent:= hChild;
 RegOpenKey(hParent, @SubKey[1], hChild);
 Result:= (0 = RegEnumKey(hChild, 0, @SubKey[1], SizeOf(SubKey) - 1));
 RegCloseKey(hChild);
 RegCloseKey(hParent);
end;

function usbGetSerial(Drive: Char; var SerialNumber: ShortString): LongBool;
var
 lpSerialNumber: PChar;
 hKey: Windows.HKEY;
 Index: Integer;
 Value: Char;
 Size: DWORD;
 b: array[0..8024] of char;
 i: integer;
 ValueType: DWORD;
begin
 ValueType:= 3;
 Size:= SizeOf(Device);
 Result := False;
 ValueName[12] := Drive;
 i:= RegOpenKey(HKEY_LOCAL_MACHINE, 'SYSTEM\MountedDevices', hKey);
 RegQueryValueEx(hKey, @ValueName, nil, @ValueType{REG_BINARY}, @Device, @Size);
 RegCloseKey(hKey);

 Index := 0;
 repeat if Device[(Index + 3) * 2 + 54] <> '#' then
  Value := Device[Index * 2 + 54] else Value := #0;
  Device[Index] := Value;
  Inc(Index);
 until Value = #0;
 SerialNumber[0] := #0;
 lstrcpy(@SerialNumber[1], 'SYSTEM\CurrentControlSet\Enum\USBSTOR');
 if (Device[0] <> #0) and Search(HKEY_LOCAL_MACHINE, SerialNumber) then
  begin
   lpSerialNumber := @SerialNumber[1];
   repeat Inc(SerialNumber[0]);
    Inc(lpSerialNumber);
    if lpSerialNumber[0] = '&' then
     lpSerialNumber[0] := #0;
   until lpSerialNumber[0] = #0;
   Result := True;
  end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  SerialNumber: ShortString;
begin
  usbGetSerial(Key, SerialNumber);
  Label1.Caption:= SerialNumber;
end;

end.


Saludos.

Última edición por escafandra fecha: 23-10-2016 a las 03:35:34.
Responder Con Cita
  #5  
Antiguo 23-10-2016
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.210
Poder: 22
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Adjunto de nuevo el código por presentar un bug.
Aún así, en algunos pendrives antiguos no encuentra bien el número de serie.

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function  StrStrI(s1: PCHAR; s2: PCHAR): PCHAR; stdcall; external 'Shlwapi.dll' name 'StrStrIA';

var
  Form1: TForm1;

implementation
{$R *.dfm}
var
 Device: ShortString;
 ValueName: array [0..15] of Char = '\DosDevices\\:';


function Search(hParent: HKEY; var SubKey: ShortString): LongBool;
var
 hChild: HKEY;
 Index: Cardinal;
 Data: ShortString;
 Size: integer;
 ValueType: DWORD;
 Error: DWORD;
begin
 Result:= false;
 Index := 0;
 Size:= sizeof(Data);
 ValueType:=0;
 RegOpenKey(hParent, @SubKey[1], hChild);
 repeat
   Error:= RegEnumKey(hChild, Index, @SubKey[1], SizeOf(SubKey) - 1);
   Inc(Index);
 until (StrStrI(@SubKey[1], @Device) <> nil) or (Error = ERROR_NO_MORE_ITEMS);
 hParent:= hChild;
 RegOpenKey(hParent, @SubKey[1], hChild);
 Result:= (0 = RegEnumKey(hChild, 0, @SubKey[1], SizeOf(SubKey) - 1));
 RegCloseKey(hChild);
 RegCloseKey(hParent);
end;

function usbGetSerial(Drive: Char; var SerialNumber: ShortString): LongBool;
var
 lpSerialNumber: PChar;
 hKey: Windows.HKEY;
 Index: Integer;
 Value: Char;
 Size: DWORD;
 b: array[0..8024] of char;
 i: integer;
 ValueType: DWORD;
begin
 ValueType:= 3;
 Size:= SizeOf(Device);
 Result := False;
 ValueName[12] := Drive;
 i:= RegOpenKey(HKEY_LOCAL_MACHINE, 'SYSTEM\MountedDevices', hKey);
 RegQueryValueEx(hKey, @ValueName, nil, @ValueType{REG_BINARY}, @Device, @Size);
 RegCloseKey(hKey);

 Index := 0;
 repeat if Device[(Index + 3) * 2 + 54] <> '#' then
  Value := Device[Index * 2 + 54] else Value := #0;
  Device[Index] := Value;
  Inc(Index);
 until Value = #0;
 SerialNumber[0] := #0;
 lstrcpy(@SerialNumber[1], 'SYSTEM\CurrentControlSet\Enum\USBSTOR');
 if (Device[0] <> #0) and Search(HKEY_LOCAL_MACHINE, SerialNumber) then
  begin
   lpSerialNumber := @SerialNumber[1];
   repeat Inc(SerialNumber[0]);
    Inc(lpSerialNumber);
    if lpSerialNumber[0] = '&' then
     lpSerialNumber[0] := #0;
   until lpSerialNumber[0] = #0;
   Result := True;
  end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  SerialNumber: ShortString;
begin
  Edit1.Text:='';
  Label1.Caption:= '';
  usbGetSerial(Key, SerialNumber);
  Label1.Caption:= SerialNumber;
end;

end.


Saludos.
Responder Con Cita
  #6  
Antiguo 23-10-2016
buenarquero buenarquero is offline
Miembro
 
Registrado: feb 2008
Posts: 33
Poder: 0
buenarquero Va por buen camino
Gracias escafandra. Aunque sigue pareciéndome que se obtiene el número de serie a partir del registro, como no encuentro nada que me sirva, lo voy a probar. Al menos, si funciona en windows XP y siguientes, será un buen complemento de protección para lo que ya tenia implementado en la aplicación.
Muchas gracias.
Responder Con Cita
  #7  
Antiguo 23-10-2016
buenarquero buenarquero is offline
Miembro
 
Registrado: feb 2008
Posts: 33
Poder: 0
buenarquero Va por buen camino
Bueno, pues, una vez probado el código en Windows XP y en Windows 7, resulta que en Windows XP siempre da el mismo número sea cual sea la letra de unidad que se introduzca en el edit y en Windows 7, da un número diferente dependiendo de la unidad que se introduzca, pero dicho número es igual siempre para esa unidad, aunque cambie el pendrive o incluso sin tener ningún pendrive conectado, lo cual no sirve para hacer que un programa no funcione si no tiene conectada el pendrive correspondiente.
Imagino que esto ocurre por que lee el número del registro y no del pendrive directamente.
Desgraciadamente no sirve, pero gracias.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Obtener el Número Serie de Fabrica USB MAXIUM Varios 10 04-11-2014 01:29:00
Obtener el numero de serie del disco giulichajari C++ Builder 6 30-07-2013 18:58:25
obtener el número de serie de un disco duro serial ATA mgc API de Windows 4 27-03-2009 15:54:18
Número de serie de un PenDrive Rudi Varios 2 05-09-2007 13:59:17
Como obtener el número de serie de la mother board saul_fg API de Windows 1 11-03-2007 07:49:51


La franja horaria es GMT +2. Ahora son las 10:13:24.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi