Cita:
Empezado por Neftali [Germán.Estévez]
Estoy revisando el proyecto (hasta ahora no lo había hecho por falta de tiempo y porque tampoco lo necesitaba) y me he encontrado con lo siguiente.
(Perdonad si ya lo habéis hablado)
Resulta que ejecuto la aplicación y siempre me devuelve que Autofirma no está instalado, aunque realmente si está en mi máquina.
Por lo que he visto (o eso me parece) es porque la clave a la que intenta acceder requiere permisos de administrador (al menos en mi caso):
Código Delphi [-]RootKey := HKEY_CLASSES_ROOT;
if OpenKey('\afirma\shell\open\command',false) then
De forma, que si no ejecuto como administrador, siempre me devuelve vacía y no lo detecta.
Como sugerencia propondría que eso se pueda cargar desde el fichero de configuración, para no obligar a ejecutar como Administrador.
|
En la 5.7 esto ira cambiado:
Sustituye en uTVerifactu.pas la funcion: function autoFirmaPath:string;
Por estas dos.
Y nos comentas que tal.
Saludos !
Código:
procedure GetProgramFilesPathsFromRegistry(out Path32, Path64: string);
const
KEY_WOW64_64KEY = $0100;
KEY_READ = $20019;
var
_hKey: HKEY;
Data: array[0..MAX_PATH] of Char;
DataSize: DWORD;
RegType: DWORD;
begin
Path32 := '';
Path64 := '';
// 1. Leer la vista de 64 bits del registro (ProgramFilesDir y ProgramFilesDir (x86))
if RegOpenKeyEx(HKEY_LOCAL_MACHINE,
'SOFTWARE\Microsoft\Windows\CurrentVersion',
0,
KEY_READ or KEY_WOW64_64KEY,
_hKey) = ERROR_SUCCESS then
begin
// Obtener ProgramFilesDir (64 bits)
DataSize := SizeOf(Data);
RegType := REG_SZ;
if RegQueryValueEx(_hKey, 'ProgramFilesDir', nil, @RegType, @Data, @DataSize) = ERROR_SUCCESS then
Path64 := Data;
// Obtener ProgramFilesDir (x86) ? ruta de 32 bits
DataSize := SizeOf(Data);
if RegQueryValueEx(_hKey, 'ProgramFilesDir (x86)', nil, @RegType, @Data, @DataSize) = ERROR_SUCCESS then
Path32 := Data;
RegCloseKey(_hKey);
end;
// 2. Si estamos en Windows de 32 bits, solo existe ProgramFilesDir
if (Path32 = '') and (Path64 = '') then
begin
if RegOpenKeyEx(HKEY_LOCAL_MACHINE,
'SOFTWARE\Microsoft\Windows\CurrentVersion',
0,
KEY_READ,
_hKey) = ERROR_SUCCESS then
begin
DataSize := SizeOf(Data);
RegType := REG_SZ;
if RegQueryValueEx(_hKey, 'ProgramFilesDir', nil, @RegType, @Data, @DataSize) = ERROR_SUCCESS then
Path32 := Data; // En 32 bits, esta es la única ruta
RegCloseKey(_hKey);
end;
end;
end;
function autoFirmaPath:string;
var
Reg: TRegistry;
i: integer;
PosiblesRutas: array[0..1] of string;
ruta32, ruta64:string;
begin
result:='';
try
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_CLASSES_ROOT;
if OpenKey('\afirma\shell\open\command',false) then
begin
if ValueExists('') then
Result := Readstring('')
else
result:='';
end
else
result:='';
CloseKey;
end;
except
result:='';
end;
if result<>'' then exit;
GetProgramFilesPathsFromRegistry(ruta32, ruta64);
PosiblesRutas[0] := ruta32+'\AutoFirma\AutoFirma\AutoFirma.exe';
PosiblesRutas[1] := ruta64+'\AutoFirma\AutoFirma\AutoFirma.exe';
for i := Low(PosiblesRutas) to High(PosiblesRutas) do
begin
if FileExists(PosiblesRutas[i]) then
begin
Result := extractFilePath(PosiblesRutas[i]);
Exit;
end;
end;
end;