Ver Mensaje Individual
  #133  
Antiguo 24-04-2023
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.734
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Yo creo el fichero ToSign.xml, que es la factura a firmar.
Luego creo el bat como te muestro en el mensaje anterior con todo rellenado.
Este bat ejecuta AutorimaCommandLine.exe redirigido a un fichero llamado sign_result.txt.
Código:
"C:\...\AutoFirma\AutoFirmaCommandLine.exe" -i "C:\...\ToSign.xml" -o "C:\...\ToSign.xsig" -store windows -filter "subject.contains: EMPRESA SL" -format facturae > "C:\...\sign_result.txt"
Ejecuto el bat con un procedimiento que espera a que termine para evitar leer antes de tiempo:
Código Delphi [-]
function RunAndWait(Handle: THandle; Ejecutable, Argumentos: string; const RunDirectory: PChar = nil; const Visibilidad: integer = SW_SHOWNORMAL; MensajeSiCorrecto: boolean = True): DWORD;
var
  Info : TShellExecuteInfo;
  pInfo : PShellExecuteInfo;
  ExitCode : word;
  P : PChar;
begin
  { Puntero a Info }
  { Pointer to Info }
  pInfo := @Info;
  { Rellenamos Info }
  { Fill info }
  with Info do
  begin
     cbSize := SizeOf(Info);
     fMask := SEE_MASK_NOCLOSEPROCESS;
     wnd := Handle;
     lpVerb := nil;
     lpFile := PChar(Ejecutable);
     { Parametros al ejecutable }
     { Executable parameters }
     lpParameters := PChar(Argumentos + #0);
     if RunDirectory = '' then
        lpDirectory := nil
     else
        lpDirectory := PChar(RunDirectory + #0);
     nShow := Visibilidad;
     hInstApp := 0;
  end;
  { Ejecutamos }
  { Execute }
  if not ShellExecuteEx(pInfo) then
  begin
     Result := GetLastError;
     if FormatMessage(Format_Message_Allocate_Buffer + Format_Message_From_System,
        nil,
        Result,
        0, @P,
        0,
        nil) <> 0 then
     begin
        // Display the string.
        ShowMessage(P);
        // Free the buffer.
        LocalFree(integer(P));
     end;
  end
  else
     Result := 0; // Info.hInstApp;

  { Esperamos que termine }
  { Wait to finish }
  repeat
     ExitCode := WaitForSingleObject(Info.hProcess, 500);
     Application.ProcessMessages;
  until (ExitCode <> WAIT_TIMEOUT);
  ExitCode := GetLastError;

  GetExitCodeProcess(Info.hProcess, Result);
  if ((Result < 32) and (ExitCode = 0)) then
  begin
     ExitCode := GetLastError;
     if FormatMessage(Format_Message_Allocate_Buffer + Format_Message_From_System,
        nil,
        ExitCode,
        0, @P,
        0,
        nil) <> 0 then
     begin
        // Display the string.
        if MensajeSiCorrecto or (ExitCode <> 0) then
           ShowMessage(P);
        // Free the buffer.
        LocalFree(integer(P));
     end;
  end
  else
     Result := 0; // Info.hInstApp;
end;

Finalmente miro si el fichero sign_result.txt tiene el texto "La operacion ha terminado corectamente"
Código Delphi [-]
if ((SysUtils.FileExists(DameTempPath + 'sign_result.txt')) and (Pos('ha terminado correctamente', MemoRead(DameTempPath + 'sign_result.txt')) > 0)) then

Si es así guardo el fichero ToSign.xsig con un nombre acorde (Pro ejemplo: Factura_A-123.xsig) en la carpera de ficheros firmados para seguir con el resto de procesos.
Responder Con Cita