Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Install EDBSrvr as a Windows service programmatically
Wed, Oct 14 2015 10:33 PMPermanent Link

Jeff Cook

Aspect Systems Ltd

Avatar

Hi

I'm writing an installer for my application.  The app runs c/s only so I
need to install the EDBSrvr.exe as a service.

I know how do do it manually:-

EDBsrvr /install /nointeract /silent
net start EDBSRVR

In DelphiXE, I have tried creating a batch file like this :-

    sl := TStringList.Create;
    try
      sl.Add('cd ' + sBasePath);
      sl.Add('APMEDBsrvr /install /nointeract /silent >
ServerInstall.log');
      sl.Add('net start EDBSRVR > ServerStart.log');
      s := sBasePath + 'Server.bat';
      sl.SaveToFile(s);
      i := ShellExecute(handle, 'open', PChar(s), '', '', SW_HIDE);
      if i > 32 then
        LogMessage('Service installed/started')
      else
        LogMessage('Service failed but carrying on install');
    finally
      sl.Free;
    end;

I get this error message:-
------------------------------------
Error running the ElevateDB Server as a service:

System Error.  Code: 5.
Access is denied
------------------------------------

.... and the ShellExecute returns 42.

Any suggestions?

Cheers

Jeff
Wed, Oct 14 2015 11:19 PMPermanent Link

Raul

Team Elevate Team Elevate

On 10/14/2015 10:33 PM, Jeff Cook wrote:
> System Error.  Code: 5.
> Access is denied
> ------------------------------------
>
> ... and the ShellExecute returns 42.
>
> Any suggestions?

Yes - this is normal error when your process is not running with
elevated privileges.

I just tried on Win8 and can easily duplicate this from regular command
line - trying to install a service and i get same error. Now if run the
command prompt elevated (Run as Administrator) then all works OK and
service gets installed.

Have not had to create an installer but my first thought is that your
installer might not be running elevated so check that first.

Quick googling showed also that you should probably be calling
ShellExecuteEx  - for example see
http://edn.embarcadero.com/article/33942 and likely many other links.


Raul

Why are you not running the ShellExecute directly with the right
parameters though and instead are creating a batch file? (or better yet
CreateProcess).
Thu, Oct 15 2015 12:09 AMPermanent Link

Jeff Cook

Aspect Systems Ltd

Avatar

On 15/10/2015 4:19 p.m., Raul wrote:
>
> Yes - this is normal error when your process is not running with
> elevated privileges.
>
> I just tried on Win8 and can easily duplicate this from regular command
> line - trying to install a service and i get same error. Now if run the
> command prompt elevated (Run as Administrator) then all works OK and
> service gets installed.

As I could do it from the command line, I presumed that when I ran my
program I would have the same privileges.

> Quick googling showed also that you should probably be calling
> ShellExecuteEx  - for example see
> http://edn.embarcadero.com/article/33942 and likely many other links.
>

Just had a quick look at that link - looks like exactly what I want, a
bit *heavy* bedtime reading Wink

>
> Why are you not running the ShellExecute directly with the right
> parameters though and instead are creating a batch file? (or better yet
> CreateProcess).

After much reading, I understand that ShellExecute(ex) doesn't wait for
the command to complete ... effectively asynchronous ... without some
complex code like I found in StackOverflow.  This means that the "net
start" would start before the server was installed.  The .bat file
should avoid this problem in a simple way.
>
Thank you Raul - looks like I'll make a bit more progress tomorrow!

Cheers

Jeff
Thu, Oct 15 2015 2:40 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Jeff


Long time since I needed an installer but have you looked at InnoSetup? I think it will handle this sort of thing.

Roy Lambert
Image