April 27, 2024, 02:22:18 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


I would need some help on CreateService()...

Started by Ficko, January 06, 2007, 02:55:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ficko

January 06, 2007, 02:55:27 PM Last Edit: June 17, 2011, 08:46:04 AM by Ficko
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

Ionic Wind Support Team

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.
Ionic Wind Support Team

Ficko


Ionic Wind Support Team

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.
Ionic Wind Support Team

Ficko

January 06, 2007, 04:36:09 PM #4 Last Edit: June 17, 2011, 08:46:55 AM by Ficko
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