tutorial studio setup script org jrsoftware isdl inno for descargar inno-setup

inno-setup - studio - inno setup tutorial



¿Cómo obtener un resultado de un programa ejecutado en Inno Setup? (2)

¿Es posible obtener un resultado de un ejecutable ejecutado?

Quiero mostrar al usuario una página de consulta de información, pero mostrar el valor predeterminado de la dirección MAC en el cuadro de entrada. ¿Hay alguna otra forma de lograr esto?


Sí, use la redirección del resultado estándar a un archivo:

[Code] function NextButtonClick(CurPage: Integer): Boolean; var TmpFileName, ExecStdout: string; ResultCode: integer; begin if CurPage = wpWelcome then begin TmpFileName := ExpandConstant(''{tmp}'') + ''/ipconfig_results.txt''; Exec(''cmd.exe'', ''/C ipconfig /ALL > "'' + TmpFileName + ''"'', '''', SW_HIDE, ewWaitUntilTerminated, ResultCode); if LoadStringFromFile(TmpFileName, ExecStdout) then begin MsgBox(ExecStdout, mbInformation, MB_OK); { do something with contents of file... } end; DeleteFile(TmpFileName); end; Result := True; end;

Tenga en cuenta que puede haber más de un adaptador de red y, en consecuencia, varias direcciones MAC para elegir.


Tuve que hacer lo mismo (ejecutar llamadas de línea de comando y obtener el resultado) y se me ocurrió una solución más general.

También corrige errores extraños si las rutas citadas se usan en las llamadas reales usando el indicador /S para cmd.exe .

{ Exec with output stored in result. } { ResultString will only be altered if True is returned. } function ExecWithResult(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer; var ResultString: String): Boolean; var TempFilename: String; Command: String; begin TempFilename := ExpandConstant(''{tmp}/~execwithresult.txt''); { Exec via cmd and redirect output to file. Must use special string-behavior to work. } Command := Format(''"%s" /S /C ""%s" %s > "%s""'', [ ExpandConstant(''{cmd}''), Filename, Params, TempFilename]); Result := Exec(ExpandConstant(''{cmd}''), Command, WorkingDir, ShowCmd, Wait, ResultCode); if not Result then Exit; LoadStringFromFile(TempFilename, ResultString); { Cannot fail } DeleteFile(TempFilename); { Remove new-line at the end } if (Length(ResultString) >= 2) and (ResultString[Length(ResultString) - 1] = #13) and (ResultString[Length(ResultString)] = #10) then Delete(ResultString, Length(ResultString) - 1, 2); end;

Uso:

Success := ExecWithResult(''ipconfig'', ''/all'', '''', SW_HIDE, ewWaitUntilTerminated, ResultCode, ExecStdout) or (ResultCode <> 0);

El resultado también se puede cargar en un objeto TStringList para obtener todas las líneas:

Lines := TStringList.Create; Lines.Text := ExecStdout; { ... some code ... } Lines.Free;