Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Why Cant Start A service. (https://www.delphipraxis.net/48156-why-cant-start-service.html)

ZuBi 21. Jun 2005 13:27


Why Cant Start A service.
 
i wrote an service, now when trying to run him i get this:

Code:
C:\svch\dll>net start xmldrv
The Who care ha it service is starting.
The Who care ha it service could not be started.

A system error has occurred.

System error 127 has occurred.

The specified procedure could not be found.
i have regsitred service main and i dont know what couse that, did anyone mess with somthingg like this ?

Main code:

Code:
begin
installservice;
//uninstallservice;

FillChar(DispatchTable, SizeOf(DispatchTable), 0);
DispatchTable[0].lpServiceName:= PChar(S_Name);
DispatchTable[0].lpServiceProc:= @ServiceProc;
StartServiceCtrlDispatcher(DispatchTable[0]);
end.
what can be wrong ?

runger 21. Jun 2005 13:31

Re: Why Cant Start A service.
 
Hallo,

ich nehm mal an, dass deine Muttersprache deutsch ist, soviele Fehler kann ein Engländer niemals machen.
Bitte formuliere das ganze in deutsch!

rainer

alcaeus 21. Jun 2005 13:37

Re: Why Cant Start A service.
 
Hello rainer,

Zitat:

Zitat von runger
ich nehm mal an, dass deine Muttersprache deutsch ist, soviele Fehler kann ein Engländer niemals machen.
Bitte formuliere das ganze in deutsch!

there are more localized versions of Delphi than just the German one. Therefore, it is easily possible that a French person would program with Delphi. However, English questions are accepted on this board to a certain extent, so I don't think there's a reason to go off like that.

@ZuBi: Are you sure that the problem is in the Code you posted? What does the installservice method do? I don't think that those 4 lines of code cause your service to crash :-?

Greetz
alcaeus

DP-Maintenance 21. Jun 2005 13:37

DP-Maintenance
 
Dieses Thema wurde von "alcaeus" von "Object-Pascal / Delphi-Language" nach "Windows API / MS.NET Framework API" verschoben.
Und ab zur WinAPI. Ist dort wohl besser aufgehoben.

ZuBi 21. Jun 2005 14:05

Re: Why Cant Start A service.
 
Zitat:

Zitat von alcaeus
Hello rainer,

Zitat:

Zitat von runger
ich nehm mal an, dass deine Muttersprache deutsch ist, soviele Fehler kann ein Engländer niemals machen.
Bitte formuliere das ganze in deutsch!

there are more localized versions of Delphi than just the German one. Therefore, it is easily possible that a French person would program with Delphi. However, English questions are accepted on this board to a certain extent, so I don't think there's a reason to go off like that.

@ZuBi: Are you sure that the problem is in the Code you posted? What does the installservice method do? I don't think that those 4 lines of code cause your service to crash :-?

Greetz
alcaeus

i quite sure the problem is in there, there for i debug it

Delphi-Quellcode:
FillChar(DispatchTable, SizeOf(DispatchTable), 0);
DispatchTable[0].lpServiceName:= PChar(S_Name);
DispatchTable[0].lpServiceProc:= @ServiceProc;
If not StartServiceCtrlDispatcher(DispatchTable[0]) Then AddToMessageLog('StartServiceCtrlDispatcher error');
Log:
Code:
[16:02:13] StartServiceCtrlDispatcher error
its seems its not passing this so the problem comes from there, i tryed to see if its somthing with ServiceProc but when i put there a log, its ont wrting anything so its not getting to there, i am trying to implent service in a dll( is it other method ? ).

i know its to know the problem from this few lines i have posted, there for i will post all soon.

Ps: It seems it cant register the proc (@ServiceProc) so it cant find the procedure, i dont know why.

[edit=alcaeus]Replaced code-tags with delphi-tags. Mfg, alcaeus[/edit]

Olli 23. Jun 2005 20:02

Re: Why Cant Start A service.
 
Zitat:

Zitat von ZuBi
i quite sure the problem is in there, there for i debug it

Delphi-Quellcode:
FillChar(DispatchTable, SizeOf(DispatchTable), 0);
DispatchTable[0].lpServiceName:= PChar(S_Name);
DispatchTable[0].lpServiceProc:= @ServiceProc;
If not StartServiceCtrlDispatcher(DispatchTable[0]) Then AddToMessageLog('StartServiceCtrlDispatcher error');

Straight from this code there's no obvious mistake!

Zitat:

Zitat von ZuBi
Log:
Code:
[16:02:13] StartServiceCtrlDispatcher error
its seems its not passing this so the problem comes from there, i tryed to see if its somthing with ServiceProc but when i put there a log, its ont wrting anything so its not getting to there,

So control is not passed to the SCM?

Zitat:

Zitat von ZuBi
i am trying to implent service in a dll( is it other method ? ).

I doubt that will work, since DLLs and PE/EXE files share only the structure but differ by many flags. The SCM was made to get control over an EXE file, not a DLL.

Zitat:

Zitat von ZuBi
i know its to know the problem from this few lines i have posted, there for i will post all soon.

Ps: It seems it cant register the proc (@ServiceProc) so it cant find the procedure, i dont know why.

Could you please add a GetLastError() after the IF-condition and tell us the error code?! There must be one.

ZuBi 30. Jun 2005 00:12

Re: Why Cant Start A service.
 
Zitat:

Zitat von Olli
Zitat:

Zitat von ZuBi
i quite sure the problem is in there, there for i debug it

Delphi-Quellcode:
FillChar(DispatchTable, SizeOf(DispatchTable), 0);
DispatchTable[0].lpServiceName:= PChar(S_Name);
DispatchTable[0].lpServiceProc:= @ServiceProc;
If not StartServiceCtrlDispatcher(DispatchTable[0]) Then AddToMessageLog('StartServiceCtrlDispatcher error');

Straight from this code there's no obvious mistake!

Zitat:

Zitat von ZuBi
Log:
Code:
[16:02:13] StartServiceCtrlDispatcher error
its seems its not passing this so the problem comes from there, i tryed to see if its somthing with ServiceProc but when i put there a log, its ont wrting anything so its not getting to there,

So control is not passed to the SCM?

Zitat:

Zitat von ZuBi
i am trying to implent service in a dll( is it other method ? ).

I doubt that will work, since DLLs and PE/EXE files share only the structure but differ by many flags. The SCM was made to get control over an EXE file, not a DLL.

Zitat:

Zitat von ZuBi
i know its to know the problem from this few lines i have posted, there for i will post all soon.

Ps: It seems it cant register the proc (@ServiceProc) so it cant find the procedure, i dont know why.

Could you please add a GetLastError() after the IF-condition and tell us the error code?! There must be one.

hello, the problem comes when trying to implent dll as service, it is possible and works at C. the SCM can control dll, as micrsoft doind it with loaders (svchost), there is no dubet the error comes when trying to reg the procedure, if i covert it to exe it works like it shuold, seince it dll and delphi doesnt speak with win like c, i tryd using stcall to make it like c, since nobody if its really works, its not. and i still cant make it as a service. the problem its possible becouse same thing works with c code posted artclie i saw some where. now can u sper few min and try slove it ? with code. u dont need alot just proc for install then to reg it(StartServiceCtrlDispatcher). if u want my codes let me know.

Olli 30. Jun 2005 09:06

Re: Why Cant Start A service.
 
Zitat:

Zitat von ZuBi
hello, the problem comes when trying to implent dll as service, it is possible and works at C. the SCM can control dll, as micrsoft doind it with loaders (svchost), there is no dubet the error comes when trying to reg the procedure, if i covert it to exe it works like it shuold, seince it dll and delphi doesnt speak with win like c, i tryd using stcall to make it like c, since nobody if its really works, its not. and i still cant make it as a service. the problem its possible becouse same thing works with c code posted artclie i saw some where. now can u sper few min and try slove it ? with code. u dont need alot just proc for install then to reg it(StartServiceCtrlDispatcher). if u want my codes let me know.

Thanks for the hint. You are right. MS uses this method (starting with W2K or WXP) to run different services in different instances of "svchost.exe".

Can you please post the link to the article (with C code). Maybe it will bring the enlightening moment ;) ... thanks.

ZuBi 1. Jul 2005 01:19

Re: Why Cant Start A service.
 
Zitat:

Zitat von Olli
Zitat:

Zitat von ZuBi
hello, the problem comes when trying to implent dll as service, it is possible and works at C. the SCM can control dll, as micrsoft doind it with loaders (svchost), there is no dubet the error comes when trying to reg the procedure, if i covert it to exe it works like it shuold, seince it dll and delphi doesnt speak with win like c, i tryd using stcall to make it like c, since nobody if its really works, its not. and i still cant make it as a service. the problem its possible becouse same thing works with c code posted artclie i saw some where. now can u sper few min and try slove it ? with code. u dont need alot just proc for install then to reg it(StartServiceCtrlDispatcher). if u want my codes let me know.

Thanks for the hint. You are right. MS uses this method (starting with W2K or WXP) to run different services in different instances of "svchost.exe".

Can you please post the link to the article (with C code). Maybe it will bring the enlightening moment ;) ... thanks.

i am sorry but the article is down atm or deleted i will tr y to find u
anyway here is a link might help http://support.microsoft.com/?kbid=314056

first u create a service, then spfic it to svchost, and add feild called servicedll that has your dll
after that u just make the service - < not works

ps. i will try to reserch it again.. couse i need it too i am days on it and nothing.

{
// Articles:
// 1. HOWTO Create a service dll used by svchost.exe by bingle, at: http://www.BingleSite.net/article/sv...l-service.html
// 2. Inside Win32 Services, Part 2 by: Mark Russinovich, at: http://www.winnetmag.com/Articles/In...leID=8943&pg=3
// 3. Platform SDK: Tools - Rundll32, at: http://msdn.microsoft.com/library/en...s/rundll32.asp

}

Olli 1. Jul 2005 10:18

Re: Why Cant Start A service.
 
The perhaps most interesting thing (which you did wrong as well) is, that you MUST NOT use StartServiceCtrlDispatcher(). Actually this function does nothing more than passing the dispatcher function address to the SCM. The SCM calls it and the service EXE is no more than a "quasi-DLL" of the SCM from this point.

So this was your first mistake. You don't need to call this function because it is only needed if your service was located in an EXE file!

... to be continued ...

ZuBi 2. Jul 2005 22:59

Re: Why Cant Start A service.
 
Zitat:

Zitat von Olli
The perhaps most interesting thing (which you did wrong as well) is, that you MUST NOT use StartServiceCtrlDispatcher(). Actually this function does nothing more than passing the dispatcher function address to the SCM. The SCM calls it and the service EXE is no more than a "quasi-DLL" of the SCM from this point.

So this was your first mistake. You don't need to call this function because it is only needed if your service was located in an EXE file!

... to be continued ...

wow nice, where did u read that ? (i didnt know this), thats make me to next qustion then, how can i know if the program is running a service, and not called by rundll( if i got true with (StartServiceCtrlDispatcher) means its running as a servie)), is it possible without making a function for connect to scm and chk the status ?

Olli 3. Jul 2005 10:12

Re: Why Cant Start A service.
 
Zitat:

Zitat von ZuBi
wow nice, where did u read that ? (i didnt know this), thats make me to next qustion then, how can i know if the program is running a service, and not called by rundll( if i got true with (StartServiceCtrlDispatcher) means its running as a servie)), is it possible without making a function for connect to scm and chk the status ?

Hi,

my sample code is almost finished, but works not perfectly yet. That's why I do not publish it right now. You will have to wait some days. Sorry for that.

How can you distinguish? Well, easy. You have two choices:
- Get the module handle of the EXE and check the name for svchost.exe vs. rundll32.exe
- Check under which account you run. SYSTEM is most likely the result when running under svchost.exe

Note: The latter method is somewhat unsafe compared to the first one.

Where did I read it? Well in the cache of this Chinese website (although I don't understand a single word Chinese ;) ) and on the other websites you linked above. The principle is relatively easy - implementation not quite.

Please stay tuned for the sample source.

ZuBi 6. Jul 2005 19:52

Re: Why Cant Start A service.
 
[quote="Olli"]
Zitat:

Zitat von ZuBi
wow nice, where did u read that ? (i didnt know this), thats make me to next qustion then, how can i know if the program is running a service, and not called by rundll( if i got true with (StartServiceCtrlDispatcher) means its running as a servie)), is it possible without making a function for connect to scm and chk the status ?

Hi,

my sample code is almost finished, but works not perfectly yet. That's why I do not publish it right now. You will have to wait some days. Sorry for that.

How can you distinguish? Well, easy. You have two choices:
- Get the module handle of the EXE and check the name for svchost.exe vs. rundll32.exe
- Check under which account you run. SYSTEM is most likely the result when running under svchost.exe

Note: The latter method is somewhat unsafe compared to the first one.

Where did I read it? Well in the cache of this Chinese website (although I don't understand a single word Chinese ;) ) and on the other websites you linked above. The principle is relatively easy - implementation not quite.

i back
those methods are unreible for me - i cant used them them but anyway.

i tut while ServiceMain has been called it stop the maim thread means no code at the main thead should be procced, the problem come when its not like that i tryd many ways to know what called has been send by services or not. do u know some more about the servicemain ? i tut the svchost calling directly to the procedure like when u call in rundll c.dll,install no other code then the procedure will start( the main thread ) so well some info may do u know ?

Olli 6. Jul 2005 20:00

Re: Why Cant Start A service.
 
Zitat:

Zitat von ZuBi
i back
those methods are unreible for me - i cant used them them but anyway.

i tut while ServiceMain has been called it stop the maim thread means no code at the main thead should be procced, the problem come when its not like that i tryd many ways to know what called has been send by services or not. do u know some more about the servicemain ? i tut the svchost calling directly to the procedure like when u call in rundll c.dll,install no other code then the procedure will start( the main thread ) so well some info may do u know ?

Sorry, I don't understand.

My solution will not be available before friday, though.

ZuBi 6. Jul 2005 20:20

Re: Why Cant Start A service.
 
Zitat:

Zitat von Olli
Zitat:

Zitat von ZuBi
i back
those methods are unreible for me - i cant used them them but anyway.

i tut while ServiceMain has been called it stop the maim thread means no code at the main thead should be procced, the problem come when its not like that i tryd many ways to know what called has been send by services or not. do u know some more about the servicemain ? i tut the svchost calling directly to the procedure like when u call in rundll c.dll,install no other code then the procedure will start( the main thread ) so well some info may do u know ?

Sorry, I don't understand.

My solution will not be available before friday, though.

its not that, those things are old problems :>

i will say it in other way: is it possible to halt the main thread when servicemain is called

Olli 6. Jul 2005 20:46

Re: Why Cant Start A service.
 
Zitat:

Zitat von ZuBi
i will say it in other way: is it possible to halt the main thread when servicemain is called

What do you mean by main thread? Only the SCM holds the threads which are then running the Service-DLL.

NicoDE 20. Aug 2005 17:45

Re: Why Cant Start A service.
 
Zitat:

Zitat von Olli
How can you distinguish? Well, easy. You have two choices:
- Get the module handle of the EXE and check the name for svchost.exe vs. rundll32.exe
- Check under which account you run. SYSTEM is most likely the result when running under svchost.exe

You should use this code to check for the 'System Process Context':
Delphi-Quellcode:
function IsSystemProcessContext: Boolean;
(** )
type
  TLUID = LARGE_INTEGER;
  TTokenStatistics = packed record
    TokenId          : TLUID;
    AuthenticationId : TLUID;
    ExpirationTime   : LARGE_INTEGER;
    TokenType        : TTokenType;
    ImpersonationLevel: TSecurityImpersonationLevel;
    DynamicCharged   : DWORD;
    DynamicAvailable : DWORD;
    GroupCount       : DWORD;
    PrivilegeCount   : DWORD;
    ModifiedId       : TLUID;
  end;
const
  SYSTEM_LUID: LARGE_INTEGER = (LowPart: $03E7; HighPart: $0);
(**)
var
  TokenHandle: THandle;
  TokenInformation: TTokenStatistics;
  ReturnLength: DWORD;
begin
  Result := False;
  if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, TokenHandle) then
    try
      Result := GetTokenInformation(TokenHandle, TokenStatistics,
        Addr(TokenInformation), SizeOf(TTokenStatistics), ReturnLength) and
        (TokenInformation.AuthenticationId.LowPart = SYSTEM_LUID.LowPart) and
        (TokenInformation.AuthenticationId.HighPart = SYSTEM_LUID.HighPart);
    finally
      CloseHandle(TokenHandle);
    end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz