Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Comprobar puerto 80 desde inno setup (https://www.clubdelphi.com/foros/showthread.php?t=41717)

smartlog 23-03-2007 13:18:19

Comprobar puerto 80 desde inno setup
 
Hola soy nuevo en este hilo y queria explicaros mi caso, quizá no esté dando con el hilo adecuado, pero tengo que empezar por algun sitio.

Estoy haciendo un instalador con inno setup 5.11 que utiliza pascal scripting y necesitaría comprobar si el puerto 80 , ya está ocupado. Esto viene porque también instalaré apache con el instalador y claro si el puerto ya está ocupado...

Muchas gracias por vuestra atención...

Ñuño Martínez 26-03-2007 11:35:26

Inno Setup permite cargar y utilizar una DLL. Mira en la ayuda del mismo, en la sección "Pascal Scripting: Using DLLs" para más información.

seoane 26-03-2007 15:07:19

Bueno, la dll para comprobar si el puerto esta ocupado te la doy yo.
Código Delphi [-]
library Puertos;

uses
  Windows, Winsock;

{$R *.res}

type
  MIB_TCPROW = record
    dwState: DWORD;
    dwLocalAddr: DWORD;
    dwLocalPort: DWORD;
    dwRemoteAddr: DWORD;
    dwRemotePort: DWORD;
  end;
  PMIB_TCPROW = ^MIB_TCPROW;

  MIB_TCPTABLE = record
    dwNumEntries: DWORD;
    table: array[0..0] of MIB_TCPROW;
  end;
  PMIB_TCPTABLE = ^MIB_TCPTABLE;

function GetTcpTable(pTcpTable: PMIB_TCPTABLE; var pdwSize: DWORD;
  bOrder: BOOL): DWORD; stdcall; external 'iphlpapi.dll';

function EstaOcupado(Puerto: Integer): BOOL; stdcall;
var
  TcpTable: PMIB_TCPTABLE;
  Size, i: DWORD;
begin
  Result:= FALSE;
  GetMem(TcpTable,sizeof(MIB_TCPTABLE));
  Size:= 0;
  if GetTcpTable(TcpTable, Size, TRUE) = ERROR_INSUFFICIENT_BUFFER then
  begin
    FreeMem(TcpTable);
    GetMem(TcpTable,Size);
  end;
  try
    if (GetTcpTable(TcpTable, Size, TRUE) = NO_ERROR) then
      for i:= 0 to TcpTable.dwNumEntries - 1 do
        if (TcpTable.table[i].dwState = 2) then
          if htons(TcpTable.table[i].dwLocalPort) = Puerto then
        begin
          Result:= TRUE;
          break;
        end;
  finally
    FreeMem(TcpTable);
  end;
end;

exports EstaOcupado;

begin
end.
La librería anterior exporta la función "EstaOcupado" que devuelve TRUE si el puerto esta ocupado. Desde delphi la llamaríamos así:
Código Delphi [-]
// La declaramos
function EstaOcupado(Puerto: Integer): BOOL; stdcall; external 'Puertos.dll';

// La usamos
  ShowMessage(BoolToStr(EstaOcupado(80),TRUE));
Al parecer, según Ñuño, con Pascal Scripting se pueden llamar funciones incluidas en una dll, así que con esto debería ser suficiente para hacer lo que tu quieres.

seoane 26-03-2007 15:49:23

Estuve haciendo un par de pruebas en Inno setup, y teniendo en cuenta que es el primer script que hago no parece muy difícil. Añadí la dll "Puertos.dll" a los archivos del proyecto y utilizo el siguiente script:
Código:


; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
AppName=My Program
AppVerName=My Program 1.5
AppPublisher=My Company, Inc.
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
CreateAppDir=no
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "C:\Puertos.dll"; DestDir: "{tmp}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[code]
//importing a Windows API function
function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
external 'MessageBoxA@user32.dll stdcall';

//importing a custom DLL function
function EstaOcupado(Puerto: Integer): Boolean;external 'EstaOcupado@files:Puertos.dll stdcall';

function NextButtonClick(CurPage: Integer): Boolean;
var
  hWnd: Integer;
begin
  if CurPage = wpWelcome then begin
    hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
    if EstaOcupado(80) then
      MessageBox(hWnd, 'Esta ocupado', 'MessageBoxA', MB_OK)
    else
      MessageBox(hWnd, 'No esta ocupado', 'MessageBoxA', MB_OK);
  end;
  Result := True;
end;



La franja horaria es GMT +2. Ahora son las 15:19:21.

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