IonicWind Software

IWBasic => General Questions => Topic started by: Ficko on January 06, 2007, 02:55:27 PM

Title: I would need some help on CreateService()...
Post by: Ficko on January 06, 2007, 02:55:27 PM
I am stuck for hours on this function "_CreateService()"  :(

I am getting the error msg:"INVALID_PARAMETER" but I can't see why!

Could somebody give me a hand on that!

I would really appreciate it!

Here is the piece of code I am working on it:
_________________________________________________________________________________
$Include "Windows.inc"
DEF SERVICES_ACTIVE_DATABASE,MyService,XB,ErMes,Display AS String
DEF Error,TagId,nSize,Arguments AS Uint

CONST SERVICE_ERROR_NORMAL = 0x1
CONST SERVICE_DEMAND_START = 0x3
CONST SERVICE_WIN32_OWN_PROCESS = 0x10

nSize = 255
MyService ="ServicePilot"
Display ="PilotServ"
SERVICES_ACTIVE_DATABASE = "ServicesActive"
XB = "C:\\ServicePilot.exe"

OPENCONSOLE
hSCManager = _OpenSCManager("",SERVICES_ACTIVE_DATABASE,SC_MANAGER_CREATE_SERVICE)
IF hSCManager = 0 THEN
   Error = _GetLastError ()
   _FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,Error,0,ErMes,nSize,Arguments)
   Print "Error by SCM:",ErMes
   GOTO Exit
ENDIF
hCs=_CreateService(hSCManager,MyService,Display,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,XB,"",TagId,"","","")
IF hCs = 0 THEN
   Error = _GetLastError ()
   _FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,Error,0,ErMes,nSize,Arguments)
   PRINT "Error by CreateService.:",ErMes
ENDIF
_CloseServiceHandle(hCs)
_CloseServiceHandle(hSCManager)
LABEL Exit
DO:UNTIL INKEY$<>""
___________________________________________________________________________________________

Thanks,
Csaba
Title: Re: I would need some help on CreateService()...
Post by: Ionic Wind Support Team on January 06, 2007, 04:05:06 PM
No he is using the parameters correctly, however GetLastError is returning "The Parameter Is Incorrect".  So it is not a matter of syntax but of how the function is being used.

I'll see what I can do with it.
Title: Re: I would need some help on CreateService()...
Post by: Ficko on January 06, 2007, 04:08:46 PM
Thank You Paul !
Title: Re: I would need some help on CreateService()...
Post by: Ionic Wind Support Team on January 06, 2007, 04:17:32 PM
The DECLARE in windows.inc is a little off, which isn't surprising since it was converted from a VB file.  Change it like so:


$Include "Windows.inc"
DEF SERVICES_ACTIVE_DATABASE,MyService,XB,ErMes,Display AS String
DEF Error,TagId,nSize,Arguments AS Uint

CONST SERVICE_ERROR_NORMAL = 0x1
CONST SERVICE_DEMAND_START = 0x3
CONST SERVICE_WIN32_OWN_PROCESS = 0x10

nSize = 255
MyService ="ServicePilot"
Display ="PilotServ"
SERVICES_ACTIVE_DATABASE = "ServicesActive"
XB = "C:\\ServicePilot.exe"

DECLARE IMPORT, CreateService ALIAS CreateServiceA(hSCManager AS UINT,lpServiceName AS POINTER,lpDisplayName AS POINTER,dwDesiredAccess AS INT,dwServiceType AS INT,dwStartType AS INT,dwErrorControl AS INT,lpBinaryPathName AS POINTER,lpLoadOrderGroup AS POINTER,lpdwTagId AS POINTER,lpDependencies AS POINTER,lp AS POINTER,lpPassword AS POINTER),INT
DECLARE IMPORT, OpenSCManager ALIAS OpenSCManagerA(lpMachineName AS POINTER,lpDatabaseName AS POINTER,dwDesiredAccess AS INT),INT


OPENCONSOLE
hSCManager = OpenSCManager(0,SERVICES_ACTIVE_DATABASE,SC_MANAGER_CREATE_SERVICE)
IF hSCManager = 0 THEN
   Error = _GetLastError ()
   _FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,Error,0,ErMes,nSize,Arguments)
   Print "Error by SCM:",ErMes
   GOTO Exit
ENDIF
hCs=CreateService(hSCManager,MyService,Display,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,XB,0,0,0,0,0)
IF hCs = 0 THEN
   Error = _GetLastError ()
   _FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,Error,0,ErMes,nSize,Arguments)
   PRINT "Error by CreateService.:",ErMes
ENDIF
_CloseServiceHandle(hCs)
_CloseServiceHandle(hSCManager)
LABEL Exit
DO:UNTIL INKEY$<>""


The problem was you have to send a NULL for lpdwTagId if you are not specifying a load ordering group.  As indicated on this Microsoft page:

http://msdn2.microsoft.com/en-us/library/ms682450.aspx

Paul.
Title: Re: I would need some help on CreateService()...
Post by: Ficko on January 06, 2007, 04:36:09 PM
Thank You Paul you saved my life!

I thought about that and changed "lpdwTagId" for a pointer but it didn't worked because I didn't changed the declaration.

Now it is working!

Three cheers for Paul!!!  ;D