Thoughts from Dan Miser RSS 2.0
# Wednesday, October 20, 2004
We have several DataSnap (ugh, it still pains me to say that instead of MIDAS :-)) servers in our application suite. We can run them either as regular processes or services. Recently, one of our customers went to Windows 2003 and our applications quit working. It turns out that Microsoft made some changes in Win2003 that causes a "Server Execution Failed" error when running a COM server as a service.

While searching Google, I found one post from Anders Evensen, who had contacted Microsoft directly about the issue. According to him, "The problem is that Microsoft requires StartServiceCtrlDispatcher to be called before CoRegisterClassObject. However, this requirement has not been implemented in earlier versions of Windows than 2003. Windows 2003 checks that the service has been started before it allows CoRegisterClassObject to be called."

Delphi does this backwards, since StartServiceCtrlDispatcher is called in TService.Execute, and CoRegisterClassObject is called during the call to Application.Initialize. I ended up with the following solution, and things now work wonderfully on all Windows versions.


function IsRunningInInstallMode : Boolean;

  function FindSwitch(const Switch: string): Boolean;
  begin
    Result := FindCmdLineSwitch(Switch, ['-', '/'], True);
  end;

begin
  Result := FindSwitch('REGSERVER') or FindSwitch('UNREGSERVER')
    or FindSwitch('INSTALL') or FindSwitch('UNINSTALL');
end;

procedure TService1.ServiceExecute(Sender: TService);
begin
  { Windows 2003 Server support. The problem is that you should always call
    StartServiceCtrlDispatcher (done in VCL) before calling CoRegisterClassObject
    (done from Application.Initialize). Win2003 now enforces this explicitly, but
    earlier versions did nothing if this was done improperly. }
  if not IsRunningInInstallMode then
    SvcMgr.Application.Initialize;

  while not Terminated do
  begin
    ServiceThread.ProcessRequests(false);
    Sleep(500);
  end;
end;
Wednesday, October 20, 2004 10:51:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [3] -
Delphi
Tracked by:
http://www.google.com/search?q=fjcddqfm [Pingback]
http://9nm-information.info/51215284/light-mentsrual-bleeding.html [Pingback]
http://9np-information.info/26611210/reviews-of-smart-dvd-creator-pro.html [Pingback]
http://9nt-information.info/30629526/how-can-i-apply-for-a-job-at-at-and-t.html [Pingback]
http://9nx-information.info/16911871/index.html [Pingback]
http://9nh-information.info/98937425/nln-medication-test-study-guide.html [Pingback]
http://9na-information.info/74134739/business-valuation-ireland.html [Pingback]
http://9nu-information.info/77026568/index.html [Pingback]
http://9ns-information.info/32071525/electric-guitar-music-sheet.html [Pingback]
http://9ne-information.info/83656682/index.html [Pingback]
http://9qr-information.info/17552239/index.html [Pingback]
http://9ok-information.info/31358185/index.html [Pingback]
http://9or-information.info/26594731/index.html [Pingback]
http://9ov-information.info/20517274/does-head-on-work-for-headaches-.html [Pingback]
http://9qs-information.info/38497359/humanitas-salerno-com.html [Pingback]
http://9oo-information.info/04958516/stupid-gift-ideas.html [Pingback]
http://9ob-information.info/71149772/index.html [Pingback]
http://9of-information.info/86034564/today-show-baby-photo-contest.html [Pingback]
http://9om-information.info/88222459/index.html [Pingback]
http://9qp-information.info/35404397/index.html [Pingback]
http://9rt-information.info/30483859/earn-my-high-school-diploma-at-home.html [Pingback]
http://9rq-information.info/64943343/index.html [Pingback]
http://9sf-information.info/77775411/water-bidet-twin.html [Pingback]
http://9sj-information.info/53892264/ragazza-rasta.html [Pingback]
http://9sj-information.info/86733740/index.html [Pingback]
http://9sh-information.info/28372957/testo-you-to-are-everything.html [Pingback]
http://9rm-information.info/00093233/cincinnati-oh-in-home-care.html [Pingback]
http://9rj-information.info/39861974/index.html [Pingback]
http://9rh-information.info/06519421/index.html [Pingback]
http://9ro-information.info/62095024/index.html [Pingback]
http://9re-information.info/10175295/curtain-tieback-hardware.html [Pingback]
http://9sm-information.info/82140911/poesie-giacomo-leopardi.html [Pingback]
http://9rk-information.info/24140676/index.html [Pingback]
http://9rs-information.info/47553151/index.html [Pingback]
http://9rn-information.info/43863856/index.html [Pingback]
http://9se-information.info/61281875/disable-spanning-tree-port-workstation.html [Pingback]
http://9uaek-le-informazioni.info/69100310/index.html [Pingback]
http://9uaem-le-informazioni.info/71437255/saggio-breve-affetti-familiare.html [Pingback]
http://9uaej-le-informazioni.info/19586650/scrittura-contabile-fusione-incorpora... [Pingback]
http://9uafk-le-informazioni.info/30809518/night-club-di-londra.html [Pingback]
http://9uael-le-informazioni.info/66210333/index.html [Pingback]
http://9uaem-le-informazioni.info/28528341/index.html [Pingback]
http://9uafa-le-informazioni.info/05131274/index.html [Pingback]
http://9uaef-le-informazioni.info/56812562/index.html [Pingback]
http://9uafk-le-informazioni.info/31897258/index.html [Pingback]
http://9uaeg-le-informazioni.info/40819629/index.html [Pingback]
http://9uaef-le-informazioni.info/51096099/artiglio-abbigliamento-aprilia.html [Pingback]
http://9uafd-le-informazioni.info/57142977/bossi-fini-testo.html [Pingback]
http://9uael-le-informazioni.info/47875284/index.html [Pingback]
http://9uaei-le-informazioni.info/39328947/index.html [Pingback]
http://9uafi-le-informazioni.info/61409872/index.html [Pingback]
http://9uafe-le-informazioni.info/73542180/index.html [Pingback]
http://9uaej-le-informazioni.info/70918613/cambio-usd-euro.html [Pingback]
http://9uafq-le-informazioni.info/90375015/index.html [Pingback]
http://9uage-le-informazioni.info/27184700/index.html [Pingback]
http://9uahn-le-informazioni.info/21594332/messico-lastminute.html [Pingback]
http://9uahd-le-informazioni.info/22555245/index.html [Pingback]
http://9uagi-le-informazioni.info/68357748/index.html [Pingback]
http://9uagf-le-informazioni.info/75363155/offerte-disneyland-paris.html [Pingback]
http://9uahg-le-informazioni.info/26567609/crisi-uva-puglia-2006.html [Pingback]
http://9uagl-le-informazioni.info/43743417/elezioni-amministrative-busto-arsizio... [Pingback]
http://9uahg-le-informazioni.info/38292020/proform-390-p.html [Pingback]
http://9uagc-le-informazioni.info/94957613/index.html [Pingback]
http://9uagc-le-informazioni.info/66966833/labor-cost.html [Pingback]
http://9uags-le-informazioni.info/15464557/index.html [Pingback]
http://9uagq-le-informazioni.info/12261687/index.html [Pingback]
http://9uahk-le-informazioni.info/28217571/index.html [Pingback]
http://9uahb-le-informazioni.info/69510630/answers-to-questions-for-job-intervie... [Pingback]
http://9uahg-le-informazioni.info/82099590/seggiolino-jane.html [Pingback]
Navigation
Archive
<October 2014>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)