#1  
Old 16th April 2021, 11:02 PM
David Rose
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed andrunning?

On 19/04/2021 08:50, david_navigator wrote:
> I have Inno script that does what you want, it's too long to post here
> via web portal (limited to 5000 characters), so will post it shortly
> (after school run) via NG client.
>
>


// function IsServiceInstalled(ServiceName: string) : boolean;
// function IsServiceRunning(ServiceName: string) : boolean;
// function InstallService(FileName, ServiceName, DisplayName,
Description : string;ServiceType,StartType :cardinal) : boolean;
// function RemoveService(ServiceName: string) : boolean;
// function StartService(ServiceName: string) : boolean;
// function StopService(ServiceName: string) : boolean;
// function SetupService(service, port, comment: string) : boolean;

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;

//
################################################## #####################################
// nt based service utilities
//
################################################## #####################################
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 GetLastError() : cardinal;
external 'GetLastError@kernel32.dll stdcall';

function OpenServiceManager() : HANDLE;
begin
if UsingWinNT() = true then begin
Result := OpenSCManager('','',SC_MANAGER_ALL_ACCESS);
if Result = 0 then
MsgBox('the servicemanager is not available', mbError, MB_OK)
end
else begin
MsgBox('only nt based systems support services', mbError,
MB_OK)
Result := 0;
end
end;

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;

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;

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;

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;

procedure UpdateConfigRegistryANDStart(Path:string; ServiceName: String);
var
Setting :string;
start: boolean;
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE,
'System\CurrentControlSet\Services\Navigator_web_s ervice',
'ImagePath', Setting) then
begin
if pos('/CONFIG:', UpperCase(Setting)) = 0 then // make sure we
don't write config multiple times
begin
Setting := Setting + ' "'+ ExpandConstant(Path)+'"';
RegWriteStringValue(HKEY_LOCAL_MACHINE,
'System\CurrentControlSet\Services\Navigator_web_s ervice',
'ImagePath', Setting);
end;
end;
// MsgBox('starting service', mbInformation, MB_OK);
start := StartService(ServiceName);
if start then MsgBox('Web Service Started', mbInformation, MB_OK)
else
MsgBox('Unable to start web service. Please start manually',
mbInformation, MB_OK);
end;

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;

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;

Function CheckServerInstalled:boolean;
begin
Result := IsServiceInstalled('NSSQLV3') OR
IsServiceInstalled('Navigator_data_service');
end;

Function Check64BitServerInstalled:boolean;
begin
Result := IsServiceInstalled('Navigator_data_service');
end;

Function CheckWebServerInstalled:boolean;
begin
Result := IsServiceInstalled('Navigator_web_service');
end;

Procedure CheckSystemPath;
begin
if CheckServerInstalled then
If not DirExists(ExpandConstant('{commonappdata}\Navigato r Systems\NX
SQL Server\$SYSTEM')) then
MsgBox('Your server config files were not found in the default
location. Please contact technical support for help on moving them from
the previous installed server.' , mbInformation, MB_OK);
end;

procedure Stop64bitServers;
begin
If IsServiceInstalled('Navigator_data_service') then
if IsServiceRunning('Navigator_data_service') then
if not StopService('Navigator_data_service') then
MsgBox('Unable to stop the Navigator NX SQL Data Server. Please
manaully stop the service.', mbInformation, MB_OK);

If IsServiceInstalled('Navigator_web_service') then
if IsServiceRunning('Navigator_web_service') then
if not StopService('Navigator_web_service') then
MsgBox('Unable to stop the Navigator NX Web Server. Please manaully
stop the service.', mbInformation, MB_OK);
end;

procedure Stop32bitServer;
begin
If IsServiceInstalled('NSSQLV3') then
begin
if IsServiceRunning('NSSQLV3') then
begin
if not StopService('NSSQLV3') then
MsgBox('Unable to stop 32-bit Navigator SQL Server service.' +
#10#13 + #10#13+ 'Please stop manually and DISABLE the service
"Navigator Systems NX SQL Server V3" to stop it restarting on reboot!',
mbInformation, MB_OK)
else
MsgBox('The 32-bit Navigator SQL Server service has been stopped.' +
#10#13 +#10#13 + 'Please DISABLE the service "Navigator Systems NX SQL
Server V3" to stop it restarting on reboot!', mbInformation, MB_OK);
end
else
MsgBox('The 32-bit Navigator SQL Server service is stopped. ' +
#10#13 + #10#13 + 'Please confirm it is DISABLED "Navigator Systems NX
SQL Server V3" to stop it restarting on reboot!', mbInformation, MB_OK);
end;
end;
  #2  
Old 19th April 2021, 12:34 PM
cwilson cwilson is offline
Junior Member
 
Join Date: Oct 2017
Location: SC, USA
Posts: 7
Default programmatically detect if Nexus service is installed and running?

Hi,
Would there be some recommended way to detect in the installation (or batch file?) if Nexus service is already installed and running? I use Inno Setup. Ideally I'd like my installation to detect if Nexus service is already running, in which case abort the installation and tell the user so. (for example, tell the user they don't need to run the full install, they just need to install an update to my software..something along those lines).
Thanks.
CW
  #3  
Old 19th April 2021, 06:50 PM
david_navigator david_navigator is offline
Junior Member
 
Join Date: Dec 2009
Posts: 22
Default

I have Inno script that does what you want, it's too long to post here via web portal (limited to 5000 characters), so will post it shortly (after school run) via NG client.
  #4  
Old 19th April 2021, 07:37 PM
David Rose
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed andrunning?

On 19/04/2021 02:34, cwilson wrote:
> Hi,
> Would there be some recommended way to detect in the installation (or
> batch file?) if Nexus service is already installed and running? I use
> Inno Setup. Ideally I'd like my installation to detect if Nexus service
> is already running, in which case abort the installation and tell the
> user so. (for example, tell the user they don't need to run the full
> install, they just need to install an update to my software..something
> along those lines).
> Thanks.
> CW
>
>

Seems it's too long for NG too, so sent directly
  #5  
Old 19th April 2021, 08:04 PM
David Rose
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed andrunning?

On 19/04/2021 09:37, David Rose wrote:
> On 19/04/2021 02:34, cwilson wrote:
>> Hi,
>> Would there be some recommended way to detect in the installation (or


> Seems it's too long for NG too, so sent directly


and that bounced....
  #6  
Old 20th April 2021, 12:43 AM
Tor
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed andrunning?

Den 19.04.2021 11.04, skrev David Rose:
> On 19/04/2021 09:37, David Rose wrote:
>> On 19/04/2021 02:34, cwilson wrote:
>>> Hi,
>>> Would there be some recommended way to detect in the installation (or

>
>> Seems it's too long for NG too, so sent directly

>
> and that bounced....


Post to binaries..?
  #7  
Old 20th April 2021, 02:11 AM
David Rose
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed andrunning?

On 19/04/2021 14:43, Tor wrote:
> Den 19.04.2021 11.04, skrev David Rose:
>> On 19/04/2021 09:37, David Rose wrote:
>>> On 19/04/2021 02:34, cwilson wrote:
>>>> Hi,
>>>> Would there be some recommended way to detect in the installation (or

>>
>>> Seems it's too long for NG too, so sent directly

>>
>> and that bounced....

>
> Post to binaries..?


done
  #8  
Old 20th April 2021, 11:50 AM
Eivind Bakkestuen
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed and running?

> done

It went to the beta.binaries group, which likely noone reads.

--

Eivind [NX]
  #9  
Old 20th April 2021, 03:08 PM
cwilson cwilson is offline
Junior Member
 
Join Date: Oct 2017
Location: SC, USA
Posts: 7
Default

thanks all - but where does one find the "beta.binaries" group? I cant see it. Im using browser based access to newsgroups.
  #10  
Old 20th April 2021, 08:04 PM
David Rose
 
Posts: n/a
Default Re: programmatically detect if Nexus service is installed andrunning?

On 20/04/2021 05:08, cwilson wrote:
> thanks all - but where does one find the "beta.binaries" group? I cant
> see it. Im using browser based access to newsgroups.
>
>

Hopefully now in public binaries !!

David


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
Changing the port for an installed service Sue King nexusdb.public.support 2 11th February 2015 07:15 PM
How to shutdown programmatically Nexus v2 ? AlexNG nexusdb.public.support 4 28th October 2009 10:03 AM
Error 1053 when installed as a service. Chris nexusdb.public.support 5 29th October 2008 12:59 AM
Error 1053 running Nexus as Service after v2.0706 update Mark McGibbon nexusdb.public.support 9 10th July 2008 01:01 PM
Running Nexus Server as a service AJ nexusdb.public.support 3 3rd June 2006 05:00 PM


All times are GMT +11. The time now is 08:50 AM.


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