Sign in to follow this  
Followers 0
yehia

Service closes after 30 sec

7 posts in this topic

i was trying to test creating a service and i though it worked untill i tested my script for a time longer than 30 secs

im not using the srvany.exe file im using the Service.au3 and 2 functions from ServiceControl.au3

when i tried to start the service from Services.msc i got this error

"Error 1053 : the service did not respond to the start or control request in a timely fashion"

i searched the forum found topics but no solutions

this is my script i hope someone can help without the use of srvany.exe

(the script will start the service and close it self to leave the script work as a service)

#include <Service.au3>


$sServiceName = "blah"

If Not _ServiceExists("", $sServiceName) Then
    _Service_Create("", $sServiceName, "blah", '"' & @ScriptFullPath & '"')
    _StartService("", $sServiceName)
    Exit
EndIf

Do
    Sleep(1000)
    Beep(1000,100)
Until 1 = 5

Func _StartService($sComputerName, $sServiceName)
   Local $hAdvapi32
   Local $hKernel32
   Local $arRet
   Local $hSC
   Local $hService
   Local $lError = -1

   $hAdvapi32 = DllOpen("advapi32.dll")
   If $hAdvapi32 = -1 Then Return 0
   $hKernel32 = DllOpen("kernel32.dll")
   If $hKernel32 = -1 Then Return 0
   $arRet = DllCall($hAdvapi32, "long", "OpenSCManager", _
                    "str", $sComputerName, _
                    "str", "ServicesActive", _ 
                    "long", $SC_MANAGER_CONNECT)
   If $arRet[0] = 0 Then
      $arRet = DllCall($hKernel32, "long", "GetLastError")
      $lError = $arRet[0]
   Else
      $hSC = $arRet[0]
      $arRet = DllCall($hAdvapi32, "long", "OpenService", _
                       "long", $hSC, _
                       "str", $sServiceName, _
                       "long", $SERVICE_START)
      If $arRet[0] = 0 Then
         $arRet = DllCall($hKernel32, "long", "GetLastError")
         $lError = $arRet[0]
      Else
         $hService = $arRet[0]
         $arRet = DllCall($hAdvapi32, "int", "StartService", _
                          "long", $hService, _
                          "long", 0, _
                          "str", "")
         If $arRet[0] = 0 Then
            $arRet = DllCall($hKernel32, "long", "GetLastError")
            $lError = $arRet[0]
         EndIf
         DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $hService)         
      EndIf
      DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $hSC)
   EndIf
   DllClose($hAdvapi32)
   DllClose($hKernel32)
   If $lError <> -1 Then 
      SetError($lError)
      Return 0
   EndIf
   Return 1
EndFunc

Func _ServiceExists($sComputerName, $sServiceName)
   Local $hAdvapi32
   Local $arRet
   Local $hSC
   Local $bExist = 0

   $hAdvapi32 = DllOpen("advapi32.dll")
   If $hAdvapi32 = -1 Then Return 0
   $arRet = DllCall($hAdvapi32, "long", "OpenSCManager", _
                    "str", $sComputerName, _
                    "str", "ServicesActive", _
                    "long", $SC_MANAGER_CONNECT)
   If $arRet[0] <> 0 Then
      $hSC = $arRet[0]
      $arRet = DllCall($hAdvapi32, "long", "OpenService", _
                       "long", $hSC, _
                       "str", $sServiceName, _
                       "long", $SERVICE_INTERROGATE)
      If $arRet[0] <> 0 Then
         $bExist = 1
         DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $arRet[0])
      EndIf
      DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $hSC)
   EndIf
   DllClose($hAdvapi32)
   Return $bExist
EndFunc

Share this post


Link to post
Share on other sites



Have a look Here - it shows how to create a service without using srvany.

Good luck,


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

u got me all wrong, i mean how to make my script work well or whats the mistake on it

i dont want to use external exes

thanks alot for ur help and its appreciated

You cannot just run a program as service unless it adheres to the defined standards for Service programs. You need a helper exe like srvany.exe to be able to run a "regular" exe as service. Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

thanks for ur answer Jos

this topic is about registering a service without external files

http://www.autoitscript.com/forum/index.ph...c=80201&hl=

im trying to get this topic writer support and here too

i supported my script above it works but it times out after 30 secs dont know why and how to make it work weel

Share this post


Link to post
Share on other sites

It looks like you're bumping your post everyday by deleting/reposting your last reply (actually you've been doing that since you started the thread).

If you haven't got any useful replies by now there is a small chance that you will get any.

Re-bumping endlessly your thread can be considered rude even if it is not violating this forum's TOS.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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