Jump to content
engine

Windows Services UDF

Recommended Posts

I am also having the error where the first service is always showing 0 for the service name. This is on a Windows 7 64 bit machine.

Share this post


Link to post
Share on other sites

Hi,

I used this api in lot's of scripts before and it really worked great. Now I reinstalled W7 64bit and use the latest AutoIt release v3.3.8.0. When trying to run the services.au3 there's an error.

Can someone help?

Regards,

B

C:UsersDesktopServices.au3(59,37) : ERROR: $READ_CONTROL previously declared as a 'Const'.
Global Const $READ_CONTROL = 0x20000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersDesktopServices.au3(60,34) : ERROR: $WRITE_DAC previously declared as a 'Const'.
Global Const $WRITE_DAC = 0x40000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersDesktopServices.au3(61,36) : ERROR: $WRITE_OWNER previously declared as a 'Const'.
Global Const $WRITE_OWNER = 0x80000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:UsersDesktopServices.au3(66,25) : ERROR: $STANDARD_RIGHTS_REQUIRED previously declared as a 'Const'.
          $WRITE_OWNER )
          ~~~~~~~~~~~~~~^
C:UsersDesktopServices.au3 - 4 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites

Only because I ran into this just the other day myself, I can tell you the answer. The errors are complaining that those 4 variables were already declared somewhere else, in some other include. The official includes (I believe SecurityConstants.au3) was updated to include these variables where it didn't before. You should be able to go in Services.au3 and comment them out/delete them and solve your problem.

There's another one that was named different from the AutoIt version and this file's version. I forget which one it is, but it was used only one other time in Services.au3.

Share this post


Link to post
Share on other sites

Hello!

Thank you for writing this!

I am looking for a way to stop/start a service and wait for it, as neither the NET.EXE tool nor the SC.EXE tool seem to have that functionality.

I'm writing my own tool in autoit, and using this very useful UDF to access the services. Thank you for writing it!

I also wrote this function to help me debug, without always having to look up all those codes:

; #FUNCTION# =======================================================================================================================================================
; Name...........: _Service_StatusToString
; Description ...: Translates the status codes of Service Query Status into English phrases
; Syntax.........: _Service_StatusToString(Const ByRef $aServiceStatus)
; Parameters ....: $aServiceStatus - An array of service status codes, returned by _Service_QueryStatus().
; Requirement(s).: Constants defined in services.au3
; Return values .: Success - Returns a string of descriptive lines delimited by CRLF
;                 Failure - Sets @error, returns English string description of error meaning
; Author ........: Mike Ratzlaff
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ==================================================================================================================================================================
Func _Service_StatusToString($aServiceStatus)
If (Not IsArray($aServiceStatus)) or (UBound($aServiceStatus)<>9) Then
SetError(1)
Return "Value passed to _Service_StatusToString was not a ServiceStatusArray"
EndIf

Local $sOutput=""

$sOutput &= $aServiceStatus[0] & @TAB & "Type of service" & @CRLF
If $aServiceStatus[0] = $SERVICE_KERNEL_DRIVER Then $sOutput &= @TAB & "The service is a device driver" & @CRLF
If $aServiceStatus[0] = $SERVICE_FILE_SYSTEM_DRIVER Then $sOutput &= @TAB & "The service is a file system driver" & @CRLF
If $aServiceStatus[0] = $SERVICE_WIN32_OWN_PROCESS Then $sOutput &= @TAB & "The service runs in its own process" & @CRLF
If $aServiceStatus[0] = $SERVICE_WIN32_SHARE_PROCESS Then $sOutput &= @TAB & "The service shares a process with other services" & @CRLF
If $aServiceStatus[0] = BitOR($SERVICE_WIN32_OWN_PROCESS, $SERVICE_INTERACTIVE_PROCESS) Then $sOutput &= @TAB & "The service runs in its own process and can interact with the desktop" & @CRLF
If $aServiceStatus[0] = BitOR($SERVICE_WIN32_SHARE_PROCESS, $SERVICE_INTERACTIVE_PROCESS) Then $sOutput &= @TAB & "The service shares a process with other services and can interact with the desktop" & @CRLF
$sOutput &= $aServiceStatus[1] & @TAB & "The current state of the service:" & @CRLF
If $aServiceStatus[1] = $SERVICE_STOPPED Then $sOutput &= @TAB & "The service has stopped" & @CRLF
If $aServiceStatus[1] = $SERVICE_START_PENDING Then $sOutput &= @TAB & "The service is starting" & @CRLF
If $aServiceStatus[1] = $SERVICE_STOP_PENDING Then $sOutput &= @TAB & "The service is stopping" & @CRLF
If $aServiceStatus[1] = $SERVICE_RUNNING Then $sOutput &= @TAB & "The service is running" & @CRLF
If $aServiceStatus[1] = $SERVICE_CONTINUE_PENDING Then $sOutput &= @TAB & "The service is about to continue" & @CRLF
If $aServiceStatus[1] = $SERVICE_PAUSE_PENDING Then $sOutput &= @TAB & "The service is pausing" & @CRLF
If $aServiceStatus[1] = $SERVICE_PAUSED Then $sOutput &= @TAB & "The service is paused" & @CRLF
$sOutput &= $aServiceStatus[2] & @TAB & "The control codes the service accepts and processes in its handler function" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_STOP) Then $sOutput &= @TAB & "The service can be stopped" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_PAUSE_CONTINUE) Then $sOutput &= @TAB & "The service can be paused and continued" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_SHUTDOWN) Then $sOutput &= @TAB & "The service is notified when system shutdown occurs" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_PARAMCHANGE) Then $sOutput &= @TAB & "The service can reread its startup parameters without being stopped and restarted" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_NETBINDCHANGE) Then $sOutput &= @TAB & "The service is a network component that can accept changes in its binding without being stopped and restarted" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_HARDWAREPROFILECHANGE) Then $sOutput &= @TAB & "The service is notified when the computer's hardware profile has changed" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_POWEREVENT) Then $sOutput &= @TAB & "The service is notified when the computer's power status has changed" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_SESSIONCHANGE) Then $sOutput &= @TAB & "The service is notified when the computer's session status has changed" & @CRLF
If BitAND($aServiceStatus[2], $SERVICE_ACCEPT_PRESHUTDOWN) Then $sOutput &= @TAB & "The service can perform preshutdown tasks" & @CRLF
$sOutput &= $aServiceStatus[3] & @TAB & "The error code that the service uses to report an error that occurs when it is starting or stopping" & @CRLF
If $aServiceStatus[3] = $ERROR_SERVICE_SPECIFIC_ERROR Then $sOutput &= "An error code specific to the service is stored in the next element" & @CRLF
If $aServiceStatus[3] = $NO_ERROR Then $sOutput &= @TAB & "Service is running or service terminates normally" & @CRLF
$sOutput &= $aServiceStatus[4] & @TAB & "The service-specific error code that the service returns when an error occurs while the service is starting or stopping" & @CRLF
If $aServiceStatus[3]<>$ERROR_SERVICE_SPECIFIC_ERROR Then $sOutput &= @TAB & "This value is ignored" & @CRLF
$sOutput &= $aServiceStatus[5] & @TAB & "The check-point value that the service increments periodically to report its progress during a lengthy start, stop, pause, or continue operation" & @CRLF
If ($aServiceStatus[5]<>0) and not (($aServiceStatus[1]=$SERVICE_START_PENDING) or _
                                   ($aServiceStatus[1]=$SERVICE_STOP_PENDING) or _
                                   ($aServiceStatus[1]=$SERVICE_CONTINUE_PENDING) or _
                                   ($aServiceStatus[1]=$SERVICE_PAUSE_PENDING)) Then $sOutput &= @TAB & "This value is not valid and should be zero" & @CRLF
$sOutput &= $aServiceStatus[6] & @TAB & "The estimated time required for a pending start, stop, pause, or continue operation, in milliseconds" & @CRLF
$sOutput &= $aServiceStatus[7] & @TAB & "The process identifier of the service (PID)" & @CRLF
$sOutput &= $aServiceStatus[8] & @TAB & "Service ""system process"" status" & @CRLF
If $aServiceStatus[8] = 0 Then $sOutput &= @TAB & "The service is running in a process that is not a system process, or it is not running" & @CRLF
If $aServiceStatus[8] = $SERVICE_RUNS_IN_SYSTEM_PROCESS Then $sOutput &= @TAB & "The service runs in a system process that must always be running" & @CRLF

Return $sOutput
EndFunc

and it can be used as such:

$sServiceName="w3svc"
$sComputerName=""
$aServiceStatus = _Service_QueryStatus($sServiceName, $sComputerName)
If Not @error Then
    ConsoleWrite(_Service_StatusToString($aServiceStatus))
EndIf
Edited by blindwig

Share this post


Link to post
Share on other sites

I'm working on error handling routines, specifically for the _Service_Start and _Service_Stop functions. I found the MSDN pages for StartService and ControlService, here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686321(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682108(v=vs.85).aspx

They list the error codes but not their actual values.

some values were listed by a user on the bottom of the ControlService page.

Anyone know where I can find the rest of the values?

Share this post


Link to post
Share on other sites

Anyone know where I can find the rest of the values?

I answered my own question, I found this page:

http://msdn.microsoft.com/en-us/library/ms819773.aspx

Very useful - has the error codes used for all Windows API calls.

Share this post


Link to post
Share on other sites

I'm using the following piece of code

#include<Services.au3>
$sServiceName = "AAAA"
$sDisplayName = "AAA"
_Service_Create($sServiceName, $sDisplayName, $SERVICE_INTERACTIVE_PROCESS, $SERVICE_AUTO_START, $SERVICE_ERROR_IGNORE, "C:\Windows\System32\CALC.EXE", Default, Default, Default, Default, Default, Default)
MsgBox(0, "", @error)

But it's returning ERROR: 6 which means ERROR_INVALID_HANDLE according to MSDN. Any suggestions, please?

i am facing the same error when i use the same example mentioned above? does any one have any clue why this happens?

Note: i am using windows 7 64 bit machine


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

i am facing the same error when i use the same example mentioned above? does any one have any clue why this happens?

Note: i am using windows 7 64 bit machine

im dunno but "C:\Windows\System32\CALC.EXE"

system32 exist on x64?

im read same links its should be redirected if app x32

but if compile x64 may not

Share this post


Link to post
Share on other sites

im dunno but "C:\Windows\System32\CALC.EXE"

system32 exist on x64?

im read same links its should be redirected if app x32

but if compile x64 may not

yeah..that exist! also i tried with "Syswow64" still i get the same error message :oops:


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

yeah..that exist! also i tried with "Syswow64" still i get the same error message :oops:

mm yes im forgot allready about interactive process

$serviceexe="C:\Windows\System32\CALC.EXE"
$sServiceName = "AAAA"
$sDisplayName = "AAA"
$SERVICE_INTERACTIVE_PROCESS2 = 0x00000110
_Service_create($sServiceName,$sDisplayName,$SERVICE_INTERACTIVE_PROCESS2,$SERVICE_AUTO_START,"",$serviceexe)
MsgBox(0, "", @error)

so u should replace $SERVICE_INTERACTIVE_PROCESS in service.au3

p.s. also im think in this topic allready was about that

Edited by macwcodvs

Share this post


Link to post
Share on other sites

still facing same problem :oops:

dunno all working for me x32 xp

u can try set in service type interactive (use gui)

found in registry this service(HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservices)

check value Type

and set this value to $SERVICE_INTERACTIVE_PROCESS

also problem with service UI0Detect on win7

but its allready after u create service

Edited by macwcodvs

Share this post


Link to post
Share on other sites

hi there

I seem to be struggling with creating a service. I can do everything else i have tried using the UDF without issue (although i've not tried altering a service yet). I used the example code with the alteration of $SERVICE_INTERACTIVE_PROCESS2 = 0x00000110 (i kept getting error code 6 otherwise) and while the service installs fine it refuses to run.

I get the error regarding the service not starting in a timely manor.

Any help you can give would be appreciated as i'd like to not have to resort to using this command line service creater i found as it's a bit hack and slash. I'm using the latest version of the UDF and also the latest beta version of autoit (i've tried the public version too just incase). I'm on windows 7 desktop and trying to get this to work in both a 2003 and a 2008 environment.

Many Thanks

edit.. i downloaded the securityex.au3 as well.

Edited by Rotahn

Share this post


Link to post
Share on other sites

Am I missing something (and I very well might be as I'm new to autoit)? When I try to launch Services.au3 or:

#include <Services.au3>
$sServiceName = "AAAA"
$sDisplayName = "AAA"
_Service_Create($sServiceName, $sDisplayName, $SERVICE_INTERACTIVE_PROCESS, $SERVICE_AUTO_START, $SERVICE_ERROR_IGNORE, "C:\Windows\System32\CALC.EXE")
MsgBox(0, "", @error)

I get:

---------------------------
AutoIt Error
---------------------------
[b]Line 65[/b]  (File "C:Usersjoe.raleighDesktopScriptsServicesServices.au3"):
Global Const $SC_MANAGER_ALL_ACCESS = BitOR( $STANDARD_RIGHTS_REQUIRED, $SC_MANAGER_CONNECT, $SC_MANAGER_CREATE_SERVICE, $SC_MANAGER_ENUMERATE_SERVICE, $SC_MANAGER_LOCK, $SC_MANAGER_QUERY_LOCK_STATUS, $SC_MANAGER_MODIFY_BOOT_CONFIG )
Global Const $SC_MANAGER_ALL_ACCESS = BitOR( ^ ERROR
[b]Error: Variable used without being declared.[/b]
---------------------------
OK  
---------------------------

Share this post


Link to post
Share on other sites

$STANDARD_RIGHTS_REQUIRED

That variable constant has probably been moved to another include than when the UDF was written.

Just search for it in the include-directory!

for me it resides in SecurityConstants.au3, but I don't have the newest version and certainly not the beta...

/Manko

Edited by Manko

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...

Share this post


Link to post
Share on other sites

So installing the latest version of AutoIT fixed my variable error...however I still cannot create a service with the examples I've found in this thread or anywhere else. (below is the code I'm using with some of the various formats I've tried commented out. All of them return Error 6 -- Invalid Handle. Which doesn't give me a whole lot to go on.

Has anyone successfully created services with this UDF? I've searched google, this form and everywhere else and I can see successfully manipulation of services but no one is creating.

#include <Services.au3>
$serviceexe="C:\Windows\System32\CALC.EXE"
$sServiceName = "Testing"
$sDisplayName = "JoeTest"
$SERVICE_INTERACTIVE_PROCESS2 = 0x00000110
;_Service_create($sServiceName,$sDisplayName,$SERVICE_INTERACTIVE_PROCESS2,$SERVICE_AUTO_START,"",$serviceexe)
;_Service_Create($sServiceName, $sServiceName, BitOR($SERVICE_INTERACTIVE_PROCESS, $SERVICE_WIN32_OWN_PROCESS), $SERVICE_AUTO_START, $SERVICE_ERROR_NORMAL, '"' & @WindowsDir & '\system32\calc.exe' & '"',"Tcpip","Tcpip","Tcpip")
_Service_Create($sServiceName, "Au3Service " & $sServiceName, $SERVICE_WIN32_OWN_PROCESS, $SERVICE_DEMAND_START, $SERVICE_ERROR_SEVERE, '"' & 'c:\temp\calc.exe' & '"')
;_Service_Create($sServiceName, $sServiceName, BitOR($SERVICE_INTERACTIVE_PROCESS, $SERVICE_WIN32_OWN_PROCESS), $SERVICE_AUTO_START, $SERVICE_ERROR_NORMAL, '"' & @WindowsDir & '\' & @ScriptName & '"',"Tcpip","Tcpip","Tcpip") c:\windows\system32\calc.exe
MsgBox(0, "", @error)

Share this post


Link to post
Share on other sites

This is not a userprivilege-exploit scheme... If you want to start a service, it should be a service. if you want to run any normal application with elevated privileges there are other scripts for that...

If I misunderstand, just ignore...

/Manko


Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...

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

×
×
  • Create New...