Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Au3@Service


  • Please log in to reply
36 replies to this topic

#1 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 02 November 2005 - 04:11 PM

Is anyone interested to run Au3 (compiled scripts) as a windows service ?

Let me know, I have a solution. Just have to finalize a GUI for it.

Maybe I can trade this in against a SQLite plugin B)

OK since you all replied so enthusiastic. :o Here is the script.

Plain Text         
;------------------------------------- ; ; Run AutoIT Scripts as a service ; PTREX 03/11/2005 ; ;------------------------------------- #include <GUIConstants.au3> #include <GuiListView.au3> #include <Process.au3> #NoTrayIcon ;Declare Vars Global $objWMIService Global $strComputer = "." Const $OWN_PROCESS = 16;16 is own process Const $INTERACTIVE = true;True changes the $Own_Process to 272 is interact with desktop Const $NORMAL_ERROR_CONTROL = 1 Dim $Script, $SrvAny, $info, $Help ;Main Gui ;Generated with Form Designer preview, great Job !! GUICreate("Au3@Service", 570, 668, 289, 123, $WS_OVERLAPPEDWINDOW) $ListView1 = GUICtrlCreateListView("Service Name |Status", 24, 160, 520, 481, $LVS_ICON+$LVS_SORTASCENDING ) _GUICtrlListViewSetColumnWidth ($listview1, 0,320) $GUI_FileMenu   = GUICtrlCreateMenu     ("&File") $GUI_FileOpen   = GUICtrlCreateMenuitem ("&Open..."     ,$GUI_FileMenu) $Helpmenu = GUICtrlCreateMenu ("?") $Helpitem = GUICtrlCreateMenuitem ("Help",$Helpmenu) $Infoitem = GUICtrlCreateMenuitem ("Info",$Helpmenu) $Edit1 = GUICtrlCreateInput("Select a compiled script to start", 24, 20, 273, 21) $Checkbox1 = GUICtrlCreateCheckbox ("Interact with Desktop. (Your script has a GUI)", 24, 130, 280, 20) GUICtrlSetState (-1,1)             $Button1 = GUICtrlCreateButton("Add Any Service", 24, 110, 93, 17) $Button2 = GUICtrlCreateButton("Delete Any Service", 120, 110, 120, 17) $Button3 = GUICtrlCreateButton("Open Services", 303, 110, 91, 17) $Button4 = GUICtrlCreateButton("Select Script ...", 24, 50, 91, 17) $Button5 = GUICtrlCreateButton("Assing Script to run" , 120, 50, 120, 17) GUICtrlCreateGroup ("Services Control", 400, 5, 140, 150) $RadioButton1 = GUICtrlCreateRadio("List All Services", 416, 24, 89, 17) $RadioButton2 = GUICtrlCreateRadio("List Au3 Services", 416, 54, 113, 17) $RadioButton3 = GUICtrlCreateRadio("Start Au3 Service", 416, 94, 120, 17) $RadioButton4 = GUICtrlCreateRadio("Stop Au3 Servioe", 416, 124, 120, 17) GUICtrlSetState ($RadioButton1,$GUI_CHECKED) GUISetState(@SW_SHOW) Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview1) ] _List_Services1() While 1     $msg = GuiGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE         ExitLoop     Case $msg = $GUI_FileOpen         _File_Open()     Case $msg = $infoitem         Info()         Msgbox(0,"Info",$Info)     Case $msg = $Helpitem         Help()         Msgbox(0,"Help",$Help)     Case $msg = $Button1         _Install_Service()     Case $msg = $Button2         _Delete_Service()     Case $msg = $Button3         _Open_Services()     Case $msg = $Button4         _Select_Script()     Case $msg = $Button5         _Assign_Script()     Case $msg = $RadioButton1         _List_Services1()     Case $msg = $RadioButton2         _List_Services2()     Case $msg = $RadioButton3         _Start_Service()     Case $msg = $RadioButton4         _Stop_Service()     Case $msg = $Checkbox1         _Interact_Desktop()     EndSelect WEnd Exit ;Functions Func _File_Open()     $FileOD = FileOpenDialog("Select SrvAny.exe File", "C:\", "EXE (*.exe)", 3)     $File = FileOpen($FileOD, 0)     GUICtrlSetData($Edit1,Chr(34) & $FileOD  & chr(34))     $SrvAny = (Chr(34) & $FileOD  & chr(34) )     If $File = -1 Then         MsgBox(0, "Error", "Unable to open file, or no file selected !!")     EndIf EndFunc Func _Select_Script()     $FileOD = FileOpenDialog("Select Au3 Script File", "C:\", "EXE (*.exe)", 3)     $File = FileOpen($FileOD, 0)     GUICtrlSetData($Edit1,Chr(34) & $FileOD  & chr(34))     $Script = (Chr(34) & $FileOD  & chr(34) )     If $File = -1 Then         MsgBox(0, "Error", "Unable to open file, or no file selected !!")     EndIf Endfunc Func _List_Services1()     _GUICtrlListViewDeleteAllItems ($listview1)         $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")     $colRunningServices = $objWMIService.ExecQuery("Select * from Win32_Service")         For $objService in $colRunningServices     local $Data = ($objService.DisplayName  & "|" & $objService.State)     GUICtrlCreateListViewItem($Data,$listview1)     Next EndFunc Func _List_Services2()     _GUICtrlListViewDeleteAllItems ($listview1)         $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")     $colRunningServices = $objWMIService.ExecQuery("Select * from Win32_Service Where Name like '_Au%'")         For $objService in $colRunningServices     local $Data = ($objService.DisplayName  & "|" & $objService.State)     GUICtrlCreateListViewItem($Data,$listview1)     Next EndFunc Func _Install_Service()     If $SrvAny = "" Then     MsgBox(0,"Warning ", "Select the SvrAny.exe using the File Open first")     Else     MsgBox(0,"Information","This has to be activated only ONCE !!")     $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")     $objService = $objWMIService.Get("Win32_BaseService")     $errReturn = $objService.Create("_Au3@Service" ,"_Au3@Service" , $SrvAny, $OWN_PROCESS, $NORMAL_ERROR_CONTROL, _     "Manual", $INTERACTIVE, "LocalSystem", ""  )     EndIf EndFunc         Func _Delete_Service()     $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")     $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '_Au3@Service'")         For $objService in $colListOfServices             $objService.StopService()             $objService.Delete()     Next EndFunc Func _Start_Service()     Local $var1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service", "ImagePath")     If @error = -1 or StringRight ($var1, 11) <> "srvany.exe"&chr(34) Then         MsgBox(4096,"",  "RegKey SrvAny not yet created, or not correct"&$var1)     Else         Local $var2 = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service\Parameters", "Application")         If @error = 1 Then         MsgBox(0,"Warning","No Script has been assigned yet to the Any service!!")         EndIf     _RunDos("Net start _au3@service")     EndIf EndFunc Func _Stop_Service()     _RunDos("Net stop _au3@service") EndFunc Func _Open_Services()     _RunDos("services.msc") EndFunc Func _Interact_Desktop()     Local $var1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service", "ImagePath")     if @error = -1 or StringRight ($var1, 11) <> "srvany.exe"&chr(34) Then         MsgBox(4096,"",  "RegKey not yet created, or not correct")     Elseif GUICtrlRead($Checkbox1)= 1 Then         RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service", "Type", "REG_DWORD", "272")     Elseif GUICtrlRead($Checkbox1)= 4 Then         RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service", "Type", "REG_DWORD", "16")     EndIf EndFunc Func _Assign_Script()         Local $var1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service", "ImagePath")     if @error = -1 or StringRight ($var1, 11) <> "srvany.exe"&chr(34) Then         MsgBox(4096,"",  "RegKey not yet created, or not correct")     Else         RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service\Parameters", "AppDirectory", "REG_SZ", @WorkingDir)         RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service\Parameters", "Application", "REG_SZ", $Script)     EndIf EndFunc Func Info()     $Info = "Sytem Requirements :"&@CR&@CR& _             "- In order to use this application you need to have 98/NT/2K/XP."&@CR&@CR& _             "- You need to copy the file SrvAny.exe to your Windows directory."&@CR& _             "  Afterwards you will need to register this file as a service, once."&@CR& _             "  See Help for more info"             EndFunc Func Help()     $Help = "Registering the SrvAny.exe file as a service :"&@CR& _             "- Go to the Windows directory where you have placed the SrvAny.exe file, using the FILE OPEN menu. " &@CR& _             "- Press the Add Any Service button. This procedure has to be done only once."  &@CR&@CR& _             "Assigning a Script to the service :"&@CR& _             "- Use the Select Script button to pick a compiled script."&@CR& _             "- Press the Assign Script to run button, to link this to the service."&@CR&@CR& _             "Starting the service :"&@CR& _             "- Click the start Au3 Service radio button, to start your script service."&@CR&@CR& _             "Stopping the service :"&@CR& _             "- Click the stop Au3 Service radio button, to stop your script service."&@CR&@CR& _             "Open Services :"&@CR& _             "- This button will allow you to open the Services.msc." EndFunc


You will need this file to put in your Windows Dir.
This SrvAny.exe file(provided by MS), works as a wrapper for your custom services.
Read the Help included in the Gui to proceed from there.




This is a Test script you can use.
If everthing works fine a countdown will appear in a msgbox.
You can logoff and logon again and still see the countdown proceeding.

sleep (3000) For $i = 100 to 1 Step -1     MsgBox(0, "Count down!", $i,1)     MsgBox(0,"Services", "Test is still running",1) Next


Update for 3.2.11.12 and later.

Attached File  Au3_Services.au3   8.62KB   1529 downloads

Edited by ptrex, 07 July 2008 - 09:07 PM.








#2 SumTingWong

SumTingWong

    My custom member title

  • Active Members
  • PipPipPipPipPipPip
  • 360 posts

Posted 02 November 2005 - 04:28 PM

Is anyone interested to run Au3 (compiled scripts) as a windows service ?

Let me know, I have a solution. Just have to finalize a GUI for it.

Maybe I can trade this in against a SQLite pugin B)



One of many tools out there - RunExeSvc

#3 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 02 November 2005 - 04:38 PM

@SumTingWong

OK.

How about NON compiled scripts ?

#4 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 03 November 2005 - 08:05 AM

@SumTingWong

I checked out your suggestion. Thanks by the way !!

But is seems more a utillty for the JAVA oriented JudoScripters.

Not what I had in mind.

#5 SumTingWong

SumTingWong

    My custom member title

  • Active Members
  • PipPipPipPipPipPip
  • 360 posts

Posted 03 November 2005 - 09:10 AM

@SumTingWong

I checked out your suggestion. Thanks by the way !!

But is seems more a utillty for the JAVA oriented JudoScripters.

Not what I had in mind.



I haven't actually needed to use it myself but I know colleagues who have used it to run compiled AutoIT scripts as services and it does work.

#6 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 03 November 2005 - 09:18 AM

@SumTingWong


Could you check with your colleagues, and give us an example on how to use this.

It might be interesting to all of us !!

Thanks

#7 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 03 November 2005 - 02:13 PM

Script added in post #1

Could be modified to run uncompiled script (.au3 files), if there are requests for this.

Regards

#8 Michel Claveau

Michel Claveau

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 352 posts

Posted 04 November 2005 - 01:43 AM

This SrvAny.exe file(provided by MS)


Hi, PTREX!

You have un more recent srvany in Win2003-resource-kit (it run under XP).
See here : http://download.microsoft.com/download/8/e...057/rktools.exe

B)

#9 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 04 November 2005 - 07:29 AM

@Michel Claveau

Thanks for the info.


Just for my information, did you have problems running the older version ?

#10 gcriaco

gcriaco

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 04 November 2005 - 08:45 AM

Another tool:
RunAsService

#11 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 04 November 2005 - 08:55 AM

@gcriaco

Thanks for the input.

I know there are lot's of these tools available elsewhere.

But AutoIt makes nice GUI's to manage your Run as a Service dynamically.

I like that a lot about AutoIT. I think this make it a nice playground B)

And it is a good reference for other Script authors, if they want to do similar scripts.

#12 Adam1213

Adam1213

    Adventurer

  • Active Members
  • PipPip
  • 133 posts

Posted 07 February 2006 - 09:35 AM

To run a autoit script use "C:\Program Files\AutoIt3\beta\AutoIt3.exe" "C:\autoitscript.au3"

#13 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 08 February 2006 - 10:47 AM

@Adam1213

I know that you can run a script like you indicate, but this is not quite the same as running a script AS a SERVICE.

This way a script keeps on running even if you have logged off !!

Thanks for the feedback anyway.

#14 Adam1213

Adam1213

    Adventurer

  • Active Members
  • PipPip
  • 133 posts

Posted 08 February 2006 - 10:53 AM

@Adam1213

I know that you can run a script like you indicate, but this is not quite the same as running a script AS a SERVICE.

This way a script keeps on running even if you have logged off !!

Thanks for the feedback anyway.


Not certain on your way. Only had a quick look at it

#15 Fossil Rock

Fossil Rock

    ASCII a stupid question,… get a stupid ANSI.

  • Active Members
  • PipPipPipPipPipPip
  • 1,084 posts

Posted 01 April 2006 - 06:25 PM

How do you use the 'Delete Any Service' feature ?

Agreement is not necessary - thinking for one's self is!

Posted Image

Posted Image


#16 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 15 April 2006 - 05:44 PM

@Fossil Rock

Late reply, too late maybe ?

The delete Any Service feature, does what it says.
It remove the Au3@service from the Windows services list.

This is kind if uninstall for the Au3@service, to get rid of it.

When you pressed that button, you will see that the "_au3@service" has been removed from the services list.

#17 rnj

rnj

    Seeker

  • Active Members
  • 37 posts

Posted 05 May 2006 - 07:09 AM

Good job dude. Is there any way one can disable a service in the services list using au3 script?
RnJScript: AutoIT v3.1.1.124 (beta)OS: Windows XP/2000

#18 ptrex

ptrex

    Universalist

  • MVPs
  • 2,413 posts

Posted 05 May 2006 - 01:42 PM

It is possible.

this will diable all services that are have MANUAL as start type.
Not tested of course.

#Include <Constants.au3> Func RemoteReboot() $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = inputbox( "Please enter the name of the computer you want to reboot", "Input" ) $objWMIService = ObjGet("winmgmts:{(RemoteShutdown)}//" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("Select * from Win32_Service where StartMode = 'Manual'")     For $objOS in $colItems     $objOS.Change( , , , , "Disabled")       Next endFunc


Success

#19 Olish

Olish

    Wayfarer

  • Active Members
  • Pip
  • 60 posts

Posted 05 September 2006 - 05:51 AM

Is SrvAny free to use in free programs ? I just tried RunExeSvc and the Admin Tool tells me :

"Error 1073 : The specified service is already running" but it is not running.
Olivier, from France.Free Wake On LAN script

#20 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,730 posts

Posted 05 September 2006 - 06:04 AM

Is SrvAny free to use in free programs ? I just tried RunExeSvc and the Admin Tool tells me :

"Error 1073 : The specified service is already running" but it is not running.

:nuke: RootKit :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users