#1  
Old 1st September 2009, 04:29 PM
Ken Randall
 
Posts: n/a
Default InnoSetup Advice

I want to be able to stop the nxServer service and my own synchronisation
service before Innosetup tries to copy the files. I could do this
programatically but can't find a way of Innosetup being able to run anything
before it does this. The only thought that I've come up with is 2 Innosetup
installations, one within the other so that the first one runs my program
first (stopping services, etc) and then it runs the normal Innosetup
installation.

Any thoughts on this would be greatly appreciated.

Ken



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4385 (20090831) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




  #2  
Old 1st September 2009, 04:40 PM
Hannes Danzl[NDD]
 
Posts: n/a
Default Re: InnoSetup Advice

> Any thoughts on this would be greatly appreciated.

Check out the shellexec command of Innosetup (chm help!) which allows you to
run any command. We usually create bat/cmd file on the fly (check
LoadStringsFromFile and SaveStringsToFile) and then run it. For starting and
stopping services you can simply use the OS "net.exe" command.
  #3  
Old 1st September 2009, 05:34 PM
Ken Randall
 
Posts: n/a
Default Re: InnoSetup Advice

Hannes,

Many thanks, exactly what I needed.

Ken

"Hannes Danzl[NDD]" <hannes@nexusdb.dbnexus.com> wrote in message
news:xn0gen6etg2ncpc00c@news.nexusdb.com...
>> Any thoughts on this would be greatly appreciated.

>
> Check out the shellexec command of Innosetup (chm help!) which allows you
> to
> run any command. We usually create bat/cmd file on the fly (check
> LoadStringsFromFile and SaveStringsToFile) and then run it. For starting
> and
> stopping services you can simply use the OS "net.exe" command.




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4385 (20090831) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




  #4  
Old 1st September 2009, 08:00 PM
David Guest
 
Posts: n/a
Default Re: InnoSetup Advice

Hannes Danzl[NDD] wrote:
>> Any thoughts on this would be greatly appreciated.

>
> Check out the shellexec command of Innosetup (chm help!) which allows you to
> run any command. We usually create bat/cmd file on the fly (check
> LoadStringsFromFile and SaveStringsToFile) and then run it. For starting and
> stopping services you can simply use the OS "net.exe" command.



An example script, stopping the nexusdb service, installing a new one
and starting it would be appreciated by all .....
  #5  
Old 2nd September 2009, 12:25 AM
=?ISO-8859-1?Q?Hans_B=E4cklund?=
 
Posts: n/a
Default Re: InnoSetup Advice

Hi,
one way to go is to include some code for servicemanagement.
(included as InnoSCM.inc)

This is probably not the easiest or cleanest way to go, but I have some
old code for it...
....and I think it works
anyway here it is



Example:

[code]
#include "InnoSCM.inc"
#define MyServiceName "MyService"
#define MyServiceDesc "My Service Project"
#define MyServiceExec "{app}\MyService.exe"

//Name of service, servicedescription and exename&path

//"Generic" code, some old "Application.ProcessMessages"-ish procedure
procedure DoEvents;
var
Msg: TMsg;
begin
while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end; {DoEvents}



//Before install
//E.G. CurStepChanged(), if CurStep = ssInstall then
if IsServiceInstalled(ExpandConstant('{#MyServiceName }')) then begin
if IsServiceRunning(ExpandConstant('{#MyServiceName}' )) then begin
if StopService(ExpandConstant('{#MyServiceName}')) then
RemoveService(ExpandConstant('{#MyServiceName}'));
end
else
RemoveService(ExpandConstant('{#MyServiceName}'));
end;


//After install
//E.G. CurStepChanged(), if CurStep = ssPostInstall then
if not IsServiceInstalled(ExpandConstant('{#MyServiceName }')) then
begin
if InstallService(ExpandConstant('{#MyServiceExec}'),
ExpandConstant('{#MyServiceName}'),
ExpandConstant('{#MyServiceDesc}'),
ExpandConstant('{#MyServiceDesc}'),
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START) then
begin
StartService(ExpandConstant('{#MyServiceName}'));
end;
end
else begin
StartService(ExpandConstant('{#MyServiceName}'));
end;



//Uninstall
//E.G. CurUninstallStepChanged(), if CurUninstallStep = usUninstall then

if IsServiceInstalled(ExpandConstant('{#MyServiceName }')) then begin

//Stop service if running
if IsServiceRunning(ExpandConstant('{#MyServiceName}' )) then begin
if StopService(ExpandConstant('{#MyServiceName}')) then begin
//Wait for service to stop, max 100000 loops (?)
cnt := 0;
while IsServiceRunning(ExpandConstant('{#MyServiceName}' )) and
(cnt < 100000) do
begin
cnt := cnt + 1;

DoEvents;
end;
end;
end;

//Uninstall service if not running
if not IsServiceRunning(ExpandConstant('{#MyServiceName}' )) then
begin
cnt := 0;
if RemoveService(ExpandConstant('{#MyServiceName}')) then begin
//Wait for service to uninstall, max 100000 loops (?)
while IsServiceInstalled(ExpandConstant('{#MyServiceName }'))
and (cnt < 100000) do
begin
cnt := cnt + 1;

DoEvents;
end;
end;
end;
end;



//While looking at it, some things look strange...
....but it's an example, use it and abuse it

Best Regards
/Hans Bäcklund

Ken Randall skrev:
> I want to be able to stop the nxServer service and my own synchronisation
> service before Innosetup tries to copy the files. I could do this
> programatically but can't find a way of Innosetup being able to run anything
> before it does this. The only thought that I've come up with is 2 Innosetup
> installations, one within the other so that the first one runs my program
> first (stopping services, etc) and then it runs the normal Innosetup
> installation.
>
> Any thoughts on this would be greatly appreciated.
>
> Ken
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4385 (20090831) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>



[_ISTool]
EnableISX=true

[code]
type
SERVICE_STATUS = record
dwServiceType : cardinal;
dwCurrentState : cardinal;
dwControlsAccepted : cardinal;
dwWin32ExitCode : cardinal;
dwServiceSpecificExitCode : cardinal;
dwCheckPoint : cardinal;
dwWaitHint : cardinal;
end;

HANDLE = cardinal;

const
SERVICE_QUERY_CONFIG = $1;
SERVICE_CHANGE_CONFIG = $2;
SERVICE_QUERY_STATUS = $4;
SERVICE_START = $10;
SERVICE_STOP = $20;
SERVICE_ALL_ACCESS = $f01ff;
SC_MANAGER_ALL_ACCESS = $f003f;
SERVICE_WIN32_OWN_PROCESS = $10;
SERVICE_WIN32_SHARE_PROCESS = $20;
SERVICE_WIN32 = $30;
SERVICE_INTERACTIVE_PROCESS = $100;
SERVICE_BOOT_START = $0;
SERVICE_SYSTEM_START = $1;
SERVICE_AUTO_START = $2;
SERVICE_DEMAND_START = $3;
SERVICE_DISABLED = $4;
SERVICE_DELETE = $10000;
SERVICE_CONTROL_STOP = $1;
SERVICE_CONTROL_PAUSE = $2;
SERVICE_CONTROL_CONTINUE = $3;
SERVICE_CONTROL_INTERROGATE = $4;
SERVICE_STOPPED = $1;
SERVICE_START_PENDING = $2;
SERVICE_STOP_PENDING = $3;
SERVICE_RUNNING = $4;
SERVICE_CONTINUE_PENDING = $5;
SERVICE_PAUSE_PENDING = $6;
SERVICE_PAUSED = $7;

function OpenSCManager(lpMachineName, lpDatabaseName: string; dwDesiredAccess :cardinal): HANDLE;
external 'OpenSCManagerA@advapi32.dll stdcall';

function OpenService(hSCManager :HANDLE;lpServiceName: string; dwDesiredAccess :cardinal): HANDLE;
external 'OpenServiceA@advapi32.dll stdcall';

function CloseServiceHandle(hSCObject :HANDLE): boolean;
external 'CloseServiceHandle@advapi32.dll stdcall';

function CreateService(hSCManager :HANDLE;lpServiceName, lpDisplayName: string;dwDesiredAccess,dwServiceType,dwStartType,d wErrorControl: cardinal;lpBinaryPathName,lpLoadOrderGroup: String; lpdwTagId : cardinal;lpDependencies,lpServiceStartName,lpPassw ord :string): cardinal;
external 'CreateServiceA@advapi32.dll stdcall';

function DeleteService(hService :HANDLE): boolean;
external 'DeleteService@advapi32.dll stdcall';

function StartNTService(hService :HANDLE;dwNumServiceArgs : cardinal;lpServiceArgVectors : cardinal) : boolean;
external 'StartServiceA@advapi32.dll stdcall';

function ControlService(hService :HANDLE; dwControl :cardinal;var ServiceStatus :SERVICE_STATUS) : boolean;
external 'ControlService@advapi32.dll stdcall';

function QueryServiceStatus(hService :HANDLE;var ServiceStatus :SERVICE_STATUS) : boolean;
external 'QueryServiceStatus@advapi32.dll stdcall';

function QueryServiceStatusEx(hService :HANDLE;ServiceStatus :SERVICE_STATUS) : boolean;
external 'QueryServiceStatus@advapi32.dll stdcall';

function OpenServiceManager() : HANDLE;
begin
if UsingWinNT() = true then begin
Result := OpenSCManager('','ServicesActive',SC_MANAGER_ALL_A CCESS);
if Result = 0 then
MsgBox('Servicemanager är inte tillgänglig', mbError, MB_OK)
end
else begin
MsgBox('Endast NT-baserade system har stöd för tjänster', mbError, MB_OK)
Result := 0;
end
end; {OpenServiceManager}

function IsServiceInstalled(ServiceName: string) : boolean;
var
hSCM : HANDLE;
hService: HANDLE;
begin
hSCM := OpenServiceManager();
Result := false;
if hSCM <> 0 then begin
hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_CONFIG) ;
if hService <> 0 then begin
Result := true;
CloseServiceHandle(hService)
end;
CloseServiceHandle(hSCM)
end
end; {IsServiceInstalled}

function InstallService(FileName, ServiceName, DisplayName, Description : string;ServiceType,StartType :cardinal) : boolean;
var
hSCM : HANDLE;
hService: HANDLE;
begin
hSCM := OpenServiceManager();
Result := false;
if hSCM <> 0 then begin
hService := CreateService(hSCM,ServiceName,DisplayName,SERVICE _ALL_ACCESS,ServiceType,StartType,0,FileName,'',0, '','','');
if hService <> 0 then begin
Result := true;
// Win2K & WinXP supports aditional description text for services
if Description<> '' then
RegWriteStringValue(HKLM,'System\CurrentControlSet \Services\' + ServiceName,'Description',Description);
CloseServiceHandle(hService)
end;
CloseServiceHandle(hSCM)
end
end; {InstallService}

function RemoveService(ServiceName: string) : boolean;
var
hSCM : HANDLE;
hService: HANDLE;
begin
hSCM := OpenServiceManager();
Result := false;
if hSCM <> 0 then begin
hService := OpenService(hSCM,ServiceName,SERVICE_DELETE);
if hService <> 0 then begin
Result := DeleteService(hService);
CloseServiceHandle(hService)
end;
CloseServiceHandle(hSCM)
end
end; {RemoveService}

function StartService(ServiceName: string) : boolean;
var
hSCM : HANDLE;
hService: HANDLE;
begin
hSCM := OpenServiceManager();
Result := false;
if hSCM <> 0 then begin
hService := OpenService(hSCM,ServiceName,SERVICE_START);
if hService <> 0 then begin
Result := StartNTService(hService,0,0);
CloseServiceHandle(hService)
end;
CloseServiceHandle(hSCM)
end;
end; {StartService}

function StopService(ServiceName: string) : boolean;
var
hSCM : HANDLE;
hService: HANDLE;
Status : SERVICE_STATUS;
begin
hSCM := OpenServiceManager();
Result := false;
if hSCM <> 0 then begin
hService := OpenService(hSCM,ServiceName,SERVICE_STOP);
if hService <> 0 then begin
Result := ControlService(hService,SERVICE_CONTROL_STOP,Statu s);
CloseServiceHandle(hService)
end;
CloseServiceHandle(hSCM)
end;
end; {StopService}

function IsServiceRunning(ServiceName: string) : boolean;
var
hSCM : HANDLE;
hService: HANDLE;
Status : SERVICE_STATUS;
begin
hSCM := OpenServiceManager();
Result := false;
if hSCM <> 0 then begin
hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_STATUS) ;
if hService <> 0 then begin
if QueryServiceStatus(hService,Status) then begin
Result :=(Status.dwCurrentState = SERVICE_RUNNING)
end;
CloseServiceHandle(hService)
end;
CloseServiceHandle(hSCM)
end
end; {IsServiceRunning}

// ################################################## #####################################
// create an entry in the services file
// ################################################## #####################################
function SetupService(service, port, comment: string) : boolean;
var
filename : string;
s : string;
lines : TArrayOfString;
n : longint;
i : longint;
// errcode : integer;
servnamlen : integer;
error : boolean;
begin
if UsingWinNT() = true then
filename := ExpandConstant('{sys}\drivers\etc\services')
else
filename := ExpandConstant('{win}\services');

if LoadStringsFromFile(filename,lines) = true then begin
Result := true;
n := GetArrayLength(lines) - 1;
servnamlen := Length(service);
error := false;

for i:=0 to n do begin
if Copy(lines[i],1,1) <> '#' then begin
s := Copy(lines[i],1,servnamlen);
if CompareText(s,service) = 0 then
Exit; // found service-entry

if Pos(port,lines[i]) > 0 then begin
error := true;
lines[i] := '#' + lines[i] + ' # avstängd på grund av kollision med tjänsten ' + service;
end;
end
else if CompareText(Copy(lines[i],2,servnamlen),service) = 0 then begin
// service-entry was disabled
Delete(lines[i],1,1);
Result := SaveStringsToFile(filename,lines,false);
Exit;
end;
end;

if error = true then begin
// save disabled entries
if SaveStringsToFile(filename,lines,false) = false then begin
Result := false;
Exit;
end;
end;

// create new service entry
s := service + ' ' + port + ' # ' + comment + #13#10;
if SaveStringToFile(filename,s,true) = false then begin
Result := false;
Exit;
end;

if error = true then begin
MsgBox(service + ' porten användes av en annan tjänst. Den andra tjänsten är avstängd nu. Du kan kolla tjänsteloggen manuellt. (' + filename + ')',mbInformation,MB_OK);
// InstExec('notepad.exe',filename,GetCurrentDir(),tr ue,false,SW_SHOWNORMAL,errcode);
end;
end
else
Result := false;
end; {SetupService}

// ################################################## #####################################
// version functions
// ################################################## #####################################
function CheckVersion(Filename : string;hh,hl,lh,ll : integer) : boolean;
var
VersionMS : cardinal;
VersionLS : cardinal;
CheckMS : cardinal;
CheckLS : cardinal;
begin
if GetVersionNumbers(Filename,VersionMS,VersionLS) = false then begin
Result := false;
end
else begin
CheckMS := (hh shl $10) or hl;
CheckLS := (lh shl $10) or ll;
Result := (VersionMS > CheckMS) or ((VersionMS = CheckMS) and (VersionLS >= CheckLS));
end;
end; {CheckVersion}

// Some examples for version checking
function NeedShellFolderUpdate() : boolean;
begin
Result := CheckVersion('ShFolder.dll',5,50,4027,300) = false;
end; {NeedShellFolderUpdate}

function NeedVCRedistUpdate() : boolean;
begin
Result := (CheckVersion('mfc42.dll',6,0,8665,0) = false)
or (CheckVersion('msvcrt.dll',6,0,8797,0) = false)
or (CheckVersion('comctl32.dll',5,80,2614,3600) = false);
end; {NeedVCRedistUpdate}

function NeedHTMLHelpUpdate() : boolean;
begin
Result := CheckVersion('hh.exe',4,72,0,0) = false;
end; {NeedHTMLHelpUpdate}

function NeedWinsockUpdate() : boolean;
begin
Result := (UsingWinNT() = false) and (CheckVersion('mswsock.dll',4,10,0,1656) = false);
end; {NeedWinsockUpdate}

function NeedDCOMUpdate() : boolean;
begin
Result := (UsingWinNT() = false) and (CheckVersion('oleaut32.dll',2,30,0,0) = false);
end; {NeedDCOMUpdate}

(*
function InitializeSetup(): boolean;
begin
if IsServiceInstalled('myservice') = false then begin
if InstallService('c:\winnt\system32\myservice.exe',' CronaWeb','Crona Web','Crona Web-tjänst', SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START) = true then begin
StartService('myservice');
StopService('myservice');
// after stopping a service you should wait some seconds before removing
RemoveService('myservice');
// otherwise removing can fail
end
end
else if IsServiceRunning('myservice') then
MsgBox('myservice is running',mbInformation, MB_OK);

Result := false
end;
*)
  #6  
Old 2nd September 2009, 02:11 AM
Ken Randall
 
Posts: n/a
Default Re: InnoSetup Advice

Hans,

Thanks a lot, I'll take a look at this tonight.

Ken

"Hans Bäcklund" <hansNO.backlundSPAM@datavara.SE> wrote in message
news:4a9d1e71$1@77-37-8-25....
> Hi,
> one way to go is to include some code for servicemanagement.
> (included as InnoSCM.inc)






Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
InnoSetup server install script Gerard Hook nexusdb.public.discussions 0 10th June 2008 10:26 AM
sql syntax advice please Peter Sanders nexusdb.public.support.sql 4 8th November 2006 11:06 AM
Advice for cat owners Geoff [NDS] nexusdb.public.discussions 18 23rd November 2005 03:37 AM
Advice with unix... Pierre Demers nexusdb.public.discussions 15 24th September 2005 03:02 AM
OT: Advice column Sean Winstead nexusdb.public.discussions 15 24th April 2003 10:20 AM


All times are GMT +11. The time now is 07:36 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.