Sign in to follow this  
Followers 0
rudi

ServiceControl.au3: failing to use _CreateService()

4 posts in this topic

Hi.

Using Autoit v3.3.0.0 and ServiceControl.Au3 from this posting I desperately fail to start the created service.

To make it simple, I tried this as my "Service" script.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=C:\MyTestService.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <date.au3>
#include <file.au3>

; Opt("TrayIconHide",1) commented, as suspected to interfere with "service startup" - didn't help.

Dim $logfile="C:\MyTestServiceLogFile.txt"
Dim $i=0
if FileExists($logfile) Then FileDelete($logfile)
FileWriteLine($logfile,"Logging started at " & _NowCalcDate() & "@" & _NowTime(5) & @CRLF & " ..............................................................")
while 1
    sleep(1000)
    $i+=1
    FileWriteLine($logfile,"running about " & $i & " seconds...")
WEndoÝ÷ Ù§)à~)Þ§²Ö«µç[ÉÚ.nW'$ªê-IÊ®¢ØZ±û¥§zË
LT­ -=Ù8b²+&ÉÊzÚ"ËZV§vËZ®ÛazÇ«¾'jëh×6; myServiceCreator.au3
#include <servicecontrol.au3>

Dim $sServer="" ; this will target the local system
Dim $sServiceName = "MyTestService"
Dim $sDisplayName = "MyTestService"
Dim $sBinaryPath = "C:\MyTestService.exe"

If Not _ServiceExists($sServer, $sServiceName) Then
    if _CreateService($sServer, $sServiceName, $sDisplayName, $sBinaryPath) Then ; all other params are optional. This way "SYSTEM" will be used.
        _startservice($sServer, $sServiceName) ; return value just proves, that the START command was accepted (it *DOESN'T* prove, that the start was done successfully)
        Sleep(20 * 1000) ; wait 20 seconds for the service to start up.
        If _Servicerunning($sServer, $sServiceName) Then
            MsgBox(64, "Info", "The service " & $sServiceName & " was created and started successfully.", 5)
            Exit
        Else
            MsgBox(48, "Error", "The service " & $sServiceName & " was created, but it could *NOT* be started!", 20)
        EndIf
    Else
        MsgBox(48, "Error", "The service " & $sServiceName & " could *NOT* be created!", 20)
        Exit
    EndIf
EndIf

A system's restart doesn't help either.

Tested on Windows XP SP3 + hotfixes as well as on a Windows 2003 R2 64bit Server, Standard Edition, SP2 + hotfixes. (That's the system I finally need to create a service).

sc query mytestservice is returning this:

SERVICE_NAME: mytestservice
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE             : 1  STOPPED
                                (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT       : 0x0
        WAIT_HINT         : 0x0

The currentcontrolset seems to have a valid service entry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyTestService]
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"ImagePath"=hex(2):43,00,3a,00,5c,00,4d,00,79,00,54,00,65,00,73,00,74,00,53,00,\
  65,00,72,00,76,00,69,00,63,00,65,00,2e,00,65,00,78,00,65,00,00,00
"DisplayName"="MyTestService"
"ObjectName"="LocalSystem"

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyTestService\Security]
"Security"=hex:<hex numbers [snipped]>
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyTestService\Enum]
"0"="Root\\LEGACY_MYTESTSERVICE\\0000"
"Count"=dword:00000001
"NextInstance"=dword:00000001

The Reg_Expand_Sz value of "ImagePath" is in clear text "C:\MyTestService.exe".

What do I miss? :D

Regards, Rudi.

PS: Deleting a service using _DeleteService() from ServiceControl.au3 works fine, but needs a reboot - that's not mentioned in it's description.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites



What shows up in the System Event Log when you try and fail to start this service?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hi.

Thanks for your reply.

Anybody out there who recently succeeded to create services with servicecontrol.au3??

What shows up in the System Event Log when you try and fail to start this service?

The Service Creation is fine.

Each try to start that service is throwing two erros within the same 1 second:

Eventlog, System:

--------- Error 1 ---------------------------------------------------------

Time: 17:53:28 Category: none

Typ: error Event ID: 7009

User: n/a

Computer: pc4-006

Timeout (30000ms) trying to connect to service MyTestService.

--------- Error 1 ---------------------------------------------------------

MS' explanation:

Within a specified time period after a new service starts, it notifies Service Control Manager (SCM) that it is ready to connect. In this case, the service did not notify SCM within the time period.

The service might be stuck in a loop or waiting on a system resource, such as additional memory.

To determine why the service is not connecting, do the following:

Verify that the service is configured correctly.

Verify that the system is in a healthy state, for example, it is not running low on resources.

--------- Erro 2 ----------------------------------------------------------

17:53:28 Category: none

Type: Error Event-ID: 7000

...

The Service "MyTestService" was not started due to an error:

The Service didn't respond in time to the Start- or Control request.

--------- Erro 2 ----------------------------------------------------------

Explanation

Service Control Manager (SCM) could not start the specified service, probably because the service is not configured correctly.

User Action

Do one or all of the following:

Review the error information displayed in the message.

Verify that the service password has not expired. ( shouldn't be applicable when using "SYSTEM")

Verify that the service is in the correct location. ( as you can see from the sample scripts I compile the EXE to C:\ )

Verify that the service is not infected with a virus. ( deactivating AV doesn't help)

To display the WIN32_EXIT_CODE error that SCM encountered when trying to start the program, at the command prompt, type

sc query service name

The information displayed can help you troubleshoot possible causes for the error.

If the WIN32_EXIT_CODE is zero, then SCM did not attempt to start the service because the error was detected first. <- this *IS* fact:

SERVICE_NAME: mytestservice
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE             : 1  STOPPED
                                (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT       : 0x0
        WAIT_HINT         : 0x0

What's going wrong here? Anybody: Can you reproduce this /nice/ problem?

I suspect, that either I have made some general mistake how I use this UDF. Or maybe it's because there was something changed in XP-SP3, Win2008-64bit, so that it doesn't work any more? :D

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi.

Anybody out there, who used ServiceControl.AU3's service install option successfully with Autoit 3.3.0.0 on XP SP3?

Who could please provide a list of the required steps required to succeed, please?

[edit]

OK, I just recognized, that I used INSTSRV not correctly. Microsoft KB 137890 describes the steps like this (General Help FAQ do as well, I missed the FAQ's desciption's meaning, sorry):

C:\>c:\instsrv foobar c:\instsrv.exe

The service was successfuly added!

Make sure that you go into the Control Panel and use
the Services applet to change the Account Name and
Password that this newly installed service will use
for its Security Context.

C:\>sc query foobar

SERVICE_NAME: foobar
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE             : 1  STOPPED
                                (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE : 1077     (0x435)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT       : 0x0
        WAIT_HINT         : 0x0

C:\>

So the Service IS installed.

instsrv.exe created these registry keys/vals:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\foobar]
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001

; ImagePath is REG_EXPAND_SZ, clear text: c:\instsrv.exe
"ImagePath"=hex(2):63,00,3a,00,5c,00,69,00,6e,00,73,00,74,00,73,00,72,00,76,00,\
  2e,00,65,00,78,00,65,00,00,00
"DisplayName"="foobar"
"ObjectName"="LocalSystem"

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\foobar\Security]
"Security"=hex:<about 7 lines hex numbers snipped>

I added this key and value as by KB article:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\foobar\Parameters]
"Application"="c:\\windows\\system32\\notepad.exe"

with ProcMon.Exe I monitored registry, when <F5> updating the list in services.msc, Filter: include, path, contains, foobar. I can see, that "HKLM\SYSTEM\CurrentControlSet\Services\foobar" and keys/vals below *DO* get several reads, but NOT the key "Parameters" nor the value "Application". Later on local FS for "notepad.exe" to be touched during startup: This didn't happen.

Also starting the service, which is returning Error 2186 [1], doesn't access this Key/Val, nor the specified c:\windows\system32\notepad.exe

All howtos for INSTSRV.EXE describe exactly this way to use it. :D what do I miss ? :o ???? :D ????

It's frustrating :P Rudi.

[1] Der Dienst kann den Befehl zurzeit nicht ausführen = ca. "the service currently can't service the request right now"

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0