0

I've made a exe (Update.exe) file to update a record in a table via SQL statement.
I've made another program(update_service.exe) which runs as an admin service in windows.

When I run update.exe standalone it updates the record in the table. No errors. It works.
When update.exe is executed via update_service.exe it gives me a access violation:

Access violation at address 40006A2F in module 'rtl60.bpl'. Read of address 00000004.

The OS where the error occurs is W2003 server.
Delphi versie 6
Data access components: ADODB
It's a VCL app

On my local W7 PC everything works ok.

Code:

procedure TService1.tmr1Timer(Sender: TObject);
var
  LclParams : string;
begin
  if (FBusyUpgrading) or (UpgradeFileExists()) then
    Exit;

  if HourOfTheDay(Time) = HourOfTheDay(strToTime(FStartServiceTime)) then
    if MinuteOfTheHour(Time) = MinuteOfTheHour(strToTime(FStartServiceTime)) then
      begin
          FBusyUpgrading := True;
          WinExecAndWait32(IncludeTrailingBackslash(GetCurrentDir) + 'update.exe /START', SW_NORMAL);
          FBusyUpgrading := False
      end;

end;

How can I solve this problem?

FWIW: SQL statements for update:

sl.Add('UPDATE Licentie SET ExpiratieDatum=' + QuotedStr(LicenseKey.Expiratie) + ' WHERE Active=True')

(LicenseKey.Expiratie is an ordinary string)

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
user3552264
  • 147
  • 1
  • 2
  • 12
  • 1
    what is happening when update.exe started from ide with /START parameter? you can do it by using menu Run > Parameters ?. – sddk Aug 18 '15 at 11:24
  • 1
    What kind of application is Update.exe? You definitely cannot spawn interactive apps from a service, and in fact I don't believe you can spawn _any_ external application from a service - if so only subject to the user rights of the service account you use. – 500 - Internal Server Error Aug 18 '15 at 12:30
  • Update.exe is a normal delphi application. I can see via a logfile that the application is running. Only the update statement gives a access violation. When running the update.exe (not via the service) it works ok. – user3552264 Aug 18 '15 at 12:41
  • Can you give more details about LicenseKey.Expiratie? Is it perhaps a property with a getter method that reads from a file or the registry? – Sam M Aug 18 '15 at 14:08
  • LicenseKey.Expiratie is just a string property – user3552264 Aug 18 '15 at 14:57
  • Is Update.Exe compiled with the $CONSOLE flag? – Hazzit Aug 18 '15 at 17:24
  • Is Update_Service.exe a windows service that calls Update.exe which is a normal application ? I do not think that it is possible for a service to start another executable because the service will probably be started under a user account with limited rights. – GuidoG Aug 18 '15 at 19:56
  • Update.exe is not compiled with the $CONSOLE flag. – user3552264 Aug 19 '15 at 06:34
  • Update_service.exe is running with the administrator account. – user3552264 Aug 19 '15 at 06:35
  • It's difficult to see without you showing your full code, but it looks like you might be trying to use a timer in a service which will not work as the service does not provide a message queue to receive the WM_TIMER messages. I'd also spawn a worker thread to do the work rather than put code in the `OnExecute` service event. – Andy_D Aug 19 '15 at 08:19
  • The Timer does work. I can see via a logfile that the update.exe is started and he does executes a lot of statements. Only the update statement is giving a access violation. – user3552264 Aug 19 '15 at 13:35

1 Answers1

0

Is the field ExpiratieDatum in table Licentie a datetime field ?

In that case it could be a format problem.
The service is started with the administrator account, which might have a different datetime format than the user you logged on when starting update.exe.

GuidoG
  • 11,359
  • 6
  • 44
  • 79
  • I'm logged on as administrator. When i start update.exe it works ok. Expiratiedatumm is a string field. – user3552264 Aug 20 '15 at 09:32
  • So you are logged on as local administrator ? Not a user with administrator rights but actually as user 'administrator' ? You say Expiratiedatumm is a string field, I wanted to know if the field in the database table is of type DateTime or VarChar. If the field in the database is DateTime and you are filling it from a string in c# than the dateformat of that string is important, and that might be different for the service than it is for you – GuidoG Aug 20 '15 at 10:14