Jump to content

Au3@Service


ptrex
 Share

Recommended Posts

Thanks for sharing this. :P

I could't configure my service created by srvany via sc config.

sc config "myService" type= own type= interact

always failed.

Always told me I did something wrong (if I use this on "real" services, everything is fine).

But thanks to ptrex, I can use "build-in" code to configure my own services.

Yes!!!

Link to comment
Share on other sites

  • 6 months later...
  • 3 months later...

I am trying to create a polling script that will monitor a particular directory for a filetype. If the file is found, it will launch and application and do stuff and exit from the application.

The idea is for someone to drop the file in the specified directory and get the processed files almost immediately. The responsibility of processing the file lies with me, but it is an automatable process. In a nutshell the following needs to be done.

1. Monitor Folder for *.txt files

2. If file found, launch application and open txt file, process it, and then save as <fileName>.new, delete <fileName>.txt

3. Exit application

I need to run this repeatedly as a service. How can i achieve that ?

Link to comment
Share on other sites

I need to run this repeatedly as a service. How can i achieve that ?

put the process in a loop with no end

do

sleep [some interval]

Look for files....

if any match, process file

until forever

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

  • 6 months later...

@kase

Look in my signature for FILE MONITOR.

regards,

ptrex

I am curious about having AutoIT use a wrapper to perform Service installation. Isn't there a DLL or WMI usage of standard files that come with windows that would provide this facility? I'm surprised that there is no AutoIT UDF or embedded functionality for this.

Link to comment
Share on other sites

@raoman123

If you would have googled you would have found what you needed. :)

Const $OWN_PROCESS = 16
Const $NOT_INTERACTIVE = True

$strComputer = "."

$objWMIService = ObjGet("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$objService = $objWMIService.Get("Win32_BaseService")
$errReturn = $objService.Create ("_AUService", "Personnel AU Service", _
"c:\windows\system32\AU3_ServiceTest.exe", $OWN_PROCESS ,2 ,"Automatic" , $NOT_INTERACTIVE ,".\LocalSystem" ,"")

regards,

ptrex

Link to comment
Share on other sites

@raoman123

If you would have googled you would have found what you needed. :)

Const $OWN_PROCESS = 16
Const $NOT_INTERACTIVE = True

$strComputer = "."

$objWMIService = ObjGet("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$objService = $objWMIService.Get("Win32_BaseService")
$errReturn = $objService.Create ("_AUService", "Personnel AU Service", _
"c:\windows\system32\AU3_ServiceTest.exe", $OWN_PROCESS ,2 ,"Automatic" , $NOT_INTERACTIVE ,".\LocalSystem" ,"")

regards,

ptrex

Thank you very much. I tried googling and searching this forum and couldn't find what you have placed here. Thanks a bunch.
Link to comment
Share on other sites

  • 5 months later...

Not sure if this has been asked, but is it still necessary to use a program like srvany.exe etc etc in conjunction with my script to be able to run it as a service?

I know that in past versions of autoit srvany.exe was required, but has the new version changed this restriction?

Just curious to know whether I'd be wasting my time trying figure out how to do that natively with the new autoit, thanks!

Edited by ShminkyBoy
Link to comment
Share on other sites

I cant get it work

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>23:45:30 Starting AutoIt3Wrapper v.1.10.1.8   Environment(Language:0409  Keyboard:00000425  OS:WIN_XP/Service Pack 2  CPU:X86)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3(24,66) : WARNING: $WS_OVERLAPPEDWINDOW: possibly used before declaration.
GUICreate("Au3@Service", 570, 668, 289, 123, $WS_OVERLAPPEDWINDOW)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3(24,66) : ERROR: $WS_OVERLAPPEDWINDOW: undeclared global variable.
GUICreate("Au3@Service", 570, 668, 289, 123, $WS_OVERLAPPEDWINDOW)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3(26,50) : ERROR: _GUICtrlListViewSetColumnWidth(): undefined function.
_GUICtrlListViewSetColumnWidth ($listview1, 0,320)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3(52,63) : ERROR: _GUICtrlListViewGetSubItemsCount(): undefined function.
Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3(115,47) : ERROR: _GUICtrlListViewDeleteAllItems(): undefined function.
    _GUICtrlListViewDeleteAllItems ($listview1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\rain\Desktop\New AutoIt v3 Script.au3 - 4 error(s), 1 warning(s)
!>23:45:31 AU3Check ended.rc:2
>E
xit code: 0 Time: 6.521
Link to comment
Share on other sites

one of the recent updates made changes to the way UDF functions are labelled and how the includes are organised.

Just add this at the top of the script:

#include <WindowsConstants.au3>

and then just add an underscore ( _ ) after _GUICtrlListView.

Hope this helps

My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website

Link to comment
Share on other sites

  • 2 weeks later...

Hi!

alternative: you can use SC.EXE (in command-line), for launch your script as a service.

Understood- just wondering if autoit gained the ability to do this natively yet or not.

I'm currently using srvany.exe, no need to switch away from it to sc.exe if I've already got it working..

I just wanted to know if anyone has tried to see if it can be done natively with the newer version of autoit yet =)

(didn't the inability to do this come from the way autoit previously handled stdin/stdout/stderr or something like that?)

Link to comment
Share on other sites

@ShminkyBoy

I can be done natively. Someone created these funtions to do so.

;===============================================================================
; Description:   Creates a service on a computer
; Parameters:    $sComputerName - name of the target computer. If empty, the local computer name is used
;                $sServiceName - name of the service to create
;                $sDisplayName - display name of the service
;                $sBinaryPath - fully qualified path to the service binary file
;                               The path can also include arguments for an auto-start service
;                $sServiceUser - [optional] default is LocalSystem
;                                name of the account under which the service should run
;                $sPassword - [optional] default is empty
;                             password to the account name specified by $sServiceUser
;                             Specify an empty string if the account has no password or if the service 
;                             runs in the LocalService, NetworkService, or LocalSystem account
;                 $nServiceType - [optional] default is $SERVICE_WIN32_OWN_PROCESS
;                 $nStartType - [optional] default is $SERVICE_AUTO_START
;                 $nErrorType - [optional] default is $SERVICE_ERROR_NORMAL
;                 $nDesiredAccess - [optional] default is $SERVICE_ALL_ACCESS
;                 $sLoadOrderGroup - [optional] default is empty
;                                    names the load ordering group of which this service is a member
; Requirements:  Administrative rights on the computer
; Return Values: On Success - 1
;                On Failure - 0 and @error is set to extended Windows error code
; Note:          Dependencies cannot be specified using this function
;                Refer to the CreateService page on MSDN for more information
;===============================================================================
Func _CreateService($sComputerName, _
                    $sServiceName, _
                    $sDisplayName, _
                    $sBinaryPath, _
                    $sServiceUser = "LocalSystem", _
                    $sPassword = "", _
                    $nServiceType = 0x00000010, _
                    $nStartType = 0x00000002, _
                    $nErrorType = 0x00000001, _
                    $nDesiredAccess = 0x000f01ff, _
                    $sLoadOrderGroup = "")
   Local $hAdvapi32
   Local $hKernel32
   Local $arRet
   Local $hSC
   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_ALL_ACCESS)
   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_INTERROGATE)
      If $arRet[0] = 0 Then
         $arRet = DllCall($hAdvapi32, "long", "CreateService", _
                          "long", $hSC, _
                          "str", $sServiceName, _
                          "str", $sDisplayName, _
                          "long", $nDesiredAccess, _
                          "long", $nServiceType, _
                          "long", $nStartType, _
                          "long", $nErrorType, _
                          "str", $sBinaryPath, _
                          "str", $sLoadOrderGroup, _
                          "ptr", 0, _
                          "str", "", _
                          "str", $sServiceUser, _
                          "str", $sPassword)
         If $arRet[0] = 0 Then            
            $arRet = DllCall($hKernel32, "long", "GetLastError")
            $lError = $arRet[0]
         Else
            DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $arRet[0])
         EndIf
      Else
         DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $arRet[0])
      EndIf      
      DllCall($hAdvapi32, "int", "CloseServiceHandle", "long", $hSC)
   EndIf
   DllClose($hAdvapi32)
   DllClose($hKernel32)   
   If $lError <> -1 Then 
      SetError($lError)
      Return 0
   EndIf
   Return 1
EndFunc

;===============================================================================
; Description:   Deletes a service on a computer
; Parameters:    $sComputerName - name of the target computer. If empty, the local computer name is used
;                $sServiceName - name of the service to delete
; Requirements:  Administrative rights on the computer
; Return Values: On Success - 1
;                On Failure - 0 and @error is set to extended Windows error code
;===============================================================================
Func _DeleteService($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_ALL_ACCESS)
   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_ALL_ACCESS)
      If $arRet[0] = 0 Then
         $arRet = DllCall($hKernel32, "long", "GetLastError")
         $lError = $arRet[0]
      Else
         $hService = $arRet[0]
         $arRet = DllCall($hAdvapi32, "int", "DeleteService", _
                          "long", $hService)
         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

regards

ptrex

Link to comment
Share on other sites

@ShminkyBoy

I can be done natively. Someone created these funtions to do so.

regards

ptrex

Thanks for the heads up ptrex, I'll try this tonight, doing services without having to use srvany.exe will make for a nice portable code (I want to be able to drop the script on a workstation pc and have it self-configure as a service on first run without having to worry about support apps)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...