Sign in to follow this  
Followers 0
debkol35

any alternative of srvany.exe to run autoit script as service

12 posts in this topic

Hello,

This is my code:-

#include "ServiceControl.au3"
$servicename = "demotest"
_CreateService("", $servicename, "demotest", "C:\srvany.exe", "LocalSystem", "", 0x110)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", "C:\demo.exe")

#include <IE.au3>
Local $oIE = _IECreate("http://google.com/")
_IENavigate($oIE, "http://debhl.mepage.us/DEB/")
While 1
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended
_IELinkClickByIndex($oIE, Random(0, $iNumLinks -1))
Sleep ( 180000 )
_IENavigate($oIE, "http://debhl.mepage.us/DEB/")
WEnd

I used srvany.exe to run my script as service (learned from here) and whenever windows will start it will start too and this is working fine in Windows XP (where I was making it)

but When I try to run it in windows 8.1 or 7, its not working. I searched google and found in some places that srvany.exe is not supported by win7 or 8 !!

so, is there any alternative way to do it which will work on win 7 or 8??

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Have you tried employing the forum search at any point? You would have come across the Service UDF:

 '?do=embed' frameborder='0' data-embedContent>>

yes..I tried it...everything went over the head :(( I have 0 knowledge, so it is kind of impossible for me now to to figure out where to put which code from there into my script) so, I was looking for easier way to do it like I found in wiki :(

Edited by debkol35

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Unfortunately, with the deprecation of srvany and XP, there isn't an "easy way". As far as having 0 knowledge, we all were at Day 1 at one point; everyone is here to learn (or improve their ability) to code, and this takes time and effort.

From what I can see, the UDF is very well commented. Taking some time to read through each function should provide you with the direction you need.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Unfortunately, with the deprecation of srvany and XP, there isn't an "easy way". As far as having 0 knowledge, we all were at Day 1 at one point; everyone is here to learn (or improve their ability) to code, and this takes time and effort.

From what I can see, the UDF is very well commented. Taking some time to read through each function should provide you with the direction you need.

 

umm...srvany.exe is working in win8.1 ...I forgot to run it as admin ... but problem is, its making IE window hidden in Win 8.1 but in XP, IE window not hidden :(

Edited by debkol35

Share this post


Link to post
Share on other sites

Last I knew srvany was not going to play well in WIN7, I believe the last one was released with the Server 2003 Resource Kit. I had a number of scripts that used it in XP and ended up going with the Services UDF instead. Have not tried it in 8.1.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Have a look at ServiceEx.  I have used it on some projects, and it work well on Windows 7.  I have not tried it on Windows 8 and 8.1.    

 

Adam

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Have a look at ServiceEx.  I have used it on some projects, and it work well on Windows 7.  I have not tried it on Windows 8 and 8.1.    

 

Adam

 

Thank you...I will definitely look at it :)

Last I knew srvany was not going to play well in WIN7, I believe the last one was released with the Server 2003 Resource Kit. I had a number of scripts that used it in XP and ended up going with the Services UDF instead. Have not tried it in 8.1.

 

Last I knew srvany was not going to play well in WIN7, I believe the last one was released with the Server 2003 Resource Kit. I had a number of scripts that used it in XP and ended up going with the Services UDF instead. Have not tried it in 8.1.

 

Ok...looks like srvany wont work...So, I was reading ServiceExample_v4 script from the topic link you gave me...after reading few times..I find this

 

Func InstallService()
    #RequireAdmin
    Local $bDebug = True
;~     If $bDebug Then ConsoleWrite("InstallService(): Installing service, please wait")
    If $cmdline[0] > 1 Then

        $sServiceName = $cmdline[2]
    EndIf
    If $bDebug Then ConsoleWrite("InstallService("&$sServiceName &"): Installing service, please wait")
    _Service_Create($sServiceName, "Au3Service " & $sServiceName, $SERVICE_WIN32_OWN_PROCESS, $SERVICE_DEMAND_START, $SERVICE_ERROR_SEVERE, '"' & @ScriptFullPath & '"')
    If @error Then

        If $bDebug Then ConsoleWrite("InstallService(): Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage())
    Else
        If $bDebug Then ConsoleWrite("InstallService(): Installation of service successful")
    EndIf
    Exit
 EndFunc   ;==>InstallService

So, after reading few times...it looks like this part of that script, will install the service...Please correct me if I am wrong...

so, If I put my code this way

#RequireAdmin
#include <Winapi.au3>
#include "services.au3"
#include "ServiceControl.au3"

$sServiceName ="demotest"
_Service_Create($sServiceName, "Au3Service " & $sServiceName, $SERVICE_WIN32_OWN_PROCESS, $SERVICE_DEMAND_START, '"' & "C:\demo.exe" & '"')
#include <IE.au3>
Local $oIE = _IECreate("http://google.com/")
_IENavigate($oIE, "http://debhl.mepage.us/DEB/")
While 1
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended
_IELinkClickByIndex($oIE, Random(0, $iNumLinks -1))
Sleep ( 10000 )
_IENavigate($oIE, "http://debhl.mepage.us/DEB/")
WEnd

will it first install my script as service then run my script? :( dont be mad if I made some stupid mistake...I am scared already to ask :D

getting error :-

 

"C:\Documents and Settings\Administrator\Desktop\ServiceControl.au3" (1) : ==> Can not redeclare a constant.:
Global $STANDARD_RIGHTS_REQUIRED = 0x000F0000
Global ^ ERROR
>Exit code: 1    Time: 0.2851

-------------------------------------

I tried sc.exe to do it.... exe is running as service but looks like its not executing rest of the scripts...its opening IE window hidden and nothing happening :( another dead end :(

sc create demo binpath= "demo.exe" type= own start= auto DisplayName= "demo"
sc config demo binpath= "cmd.exe /c C:\demo.exe" type= own start= auto DisplayName= "demo"

9907d7486aa6366381bbb519c71a0314.png

Edited by debkol35

Share this post


Link to post
Share on other sites

Hello,

Just for the records, there is an alternative to srvany, take a look to nssm, it should work fine on Win7 and 8.

Cheers,

sahsanu

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hello,

Just for the records, there is an alternative to srvany, take a look to nssm, it should work fine on Win7 and 8.

Cheers,

sahsanu

thank you for your reply :) I tried nssm, sc.exe,srvany.exe too... everthing works good under 7 and 8 if I run as admin, in xp, no need to run as admin!! ..they start exe as service..but thing is ..they are making IE window hidden.... I installed Microsoft Network Monitor 3.4 to capture if IE sending any data after being hidden...I saw..they are sending data and receiving too..looks like they are working  as per scripts... but only problem remains is they are becoming hidden :(

Edited by debkol35

Share this post


Link to post
Share on other sites

   I have been tring to find out how to run an AutoIT compiled script as a service for days and haven't gotten anywhere. I have stared at _Services_UDF V4 until I am blue in the face and can't even figure out what it does. There are 3 or 4 different versions of the same files scattered throughout the thread and the example flat out don't work.

   I need to revert back to the basics. I was under the impression that you can't just take any old .exe and install it as a service because it isn't "service compatible" in that the service start, stop, pause might not work. Is that true and is that the only reasons?

   The natural follow up to that question would be are AutoIT exes "service compatible" just as they stand? i.e. can I take a compiled script and add it to services with the SC command and just have it work?

   My understanding of Svrany, nssm, AlwaysUp etc. is that they are "helpers" and need to be memory resident on the computer that has the exes running as a service. To me that is one more program to worry about. If the AutoIT exes do need to be modified to be "service compatible" isn't there some kind of program that will make the mods to the exe and leave you with a resultant exe that is stand alone and can be installed as a service with SC?

   BTW, in layman terms, what is _Services_UDF V4 supposed to do?

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

  • Similar Content

    • wtarkan
      By wtarkan
      If I create a service to run a program , Application window cannot Appear - How can I make the App window visible
    • tremolux66
      By tremolux66
      I'm unable to display a message box from a compiled AutoIt alerting script that is executed from a service (also a compiled AutoIt script). I used $MB_SERVICE_NOTIFICATION, but the dialog doesn't appear and the alerting script continues as if the OK button had been clicked. The service script uses ShellExecute() to launch the alerter (as opposed to a *Wait() call) so it can continue processing. Note that we used Windows Service Wrapper (winsw) to turn the compiled script into a service but haven't identified any issues from it.
      I tried the one-line execute example given in this thread: Message box timeout not working
      ; 2097152 = $MB_SERVICE_NOTIFICATION $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(2097152, ''' & $sTitle & ''', ''' & $sText & ''')"') without the timeout code, but no luck: the MsgBox does not appear. (In any case, we don't have AutoIt installed on the target system, so it would have to be converted into a .exe file.)
      We're developing and unit-testing on Win 7 Enterprise; the target OS is Win 7 Pro, and the AutoIt version is 3.3.14.2.
      Any solutions or suggestions will be much appreciated. Code fragments are below.
      Thanks.
       
      The following code fragment is the relevant portion of the alerting script that displays the MsgBox:
      [...] ; Alert the operator that there's a problem with the recording $sFeed = $aRecInfo[6] $sSession = $aRecInfo[2] $sTemp = $aRecInfo[4] $sDate = _FormatDate($sTemp) $sTemp = $aRecInfo[5] $sTime = _FormatTime($sTemp) _Debug2("Inactive recording feed " & $sFeed & ", Session=" & $sSession & ", Start Date/Time=" & _ $sDate & " " & $sTime) $sErrorMsg = "ERROR: Feed " & $sFeed & " for session " & $sSession & " stopped, notify reporter immediately" $iMbFlag = $MB_SERVICE_NOTIFICATION _Debug1("Displaying MsgBox...") MsgBox($iMbFlag, "INTERVIEW RECORDING ERROR", $sErrorMsg) _Debug1("Returned from MsgBox") [...]  
      And the calling code fragment in the service is:
      ; Walk through the array backwards so we don't end up evaluating an index that doesn't exist For $iIndex = UBound($aFeedArray)-1 To 0 Step -1 [...] ; Before timing-out the feed, check for a .mpgpart file (=> feed may still be recording) $sDirPath = $sDirTemp & "\" & $sFeedTemp & "\" & $aFeedArray[$iIndex][$cSessionName] $sMpgPartName = GetMpgPart($sDirPath, $sFeedTemp) If StringLen($sMpgPartName) > 0 Then ; If .mpgpart file name hasn't changed in more than $iDeadFeedTime seconds, then declare feed dead ; ========v Test code to force error v======== $sMpgPartName = $aFeedArray[$iIndex][$cMpgPartName] ; ========^ Test code to force error ^======== _Debug2("Just set $sMpgPartName to '" & $sMpgPartName & "', should fall into dead-feed code") If $sMpgPartName = $aFeedArray[$iIndex][$cMpgPartName] Then ; Name is same => feed is dead: alert the operator and delete the feed w/out stop-processing _Debug2("Feed " & $sFeedTemp & " looks dead -- alerting the operator") _Debug2("Delete GUID " & $aFeedArray[$iIndex][$cGUID]) ; ======== Alert app execution ======== ; $sAlertApp = @ScriptDir & "\" & "RecAlert.exe" $iChildPid = ShellExecute($sAlertApp, $sDirPath, "", "open") _Debug2("Alert app: ShellExecute(): " & _RetStr($iChildPid, @error, @extended)) _ArrayDelete($aFeedArray, $iIndex) Else ; Otherwise, the .mpgpart name has changed, reset the timer, store the name, and continue _Debug2("Feed " & $sFeedTemp & " timeout, but has new .mpgpart file -- continuing") $aFeedArray[$iIndex][$cDateTime] = TimerInit() $aFeedArray[$iIndex][$cMpgPartName] = $sMpgPartName EndIf ContinueLoop EndIf [...] Next  
    • arcker
      By arcker
      I can't be responsible for any impact of your script or services you would run in production.


      | _Services_UDF v4
      |
      | By Arcker
      | Run your script as a service
      | Req. AutoIt 3.3.8.1 min, last beta recommended ( tested in 3.3.9.21 ) 
      |_______________________________________

      ++ Preparing v5

      !! Checked on 27/04/2015
      <> Updated on 10/23/2013
      <> Updated 07/29/2013
      <> Best practices Updated 24/02/2012
       -- Removed GUI code, and old codes.
      == Warning : 26/02/2012
      <> New Version (v3 ) : 29/07/2013
      |
      Thx to ShminkyBoy, wraithdu, Udgeen and HolmesShelock for their great contributions.
      Special thx to bitboy,
       
      Downloads

      see end of this post : ServiceExample_v4, Services.au3, ServicesConstants.au3
      Presentation

      Here is my _Service _ UDF

      With this UDF, you can compile your autoit script and run it as service.

      Any comments are welcome.

      Hope you'll like it,

       
      1 - changelog
      Update V4 : 23/10/2013,27/04/2015
      Update : V3 on 29/07/2013
      Compile the service example to see how to do then you can use the main function for your proper script Choose an appropriate location and copy the script here. open a command prompt, and execute the compiled script with option –I ( must be admin right since vista ) start / execute "services.msc" . You will see a service called "Autoit_service". you can execute "sc query" in a command prompt too. Launch it : it will run the previous compile script. The main function will be executed after the service_init. stop and relaunch the service as you wish.

      Examples / Session Change / uses v1 (lock, logon, etc) By HolmesShelock. Awesome work.
      Edit : this example doesn't use v2 or v3 method

      SessionChange Service.zip

      Example output to give you an idea
      Examples demos

      Synoptic

      And for End Users, I've tried to explain the service control manager and the way it works with programs.

      see below

      Best Practice, by arcker :

      /! please read this if you encounter stability issues

      I've had to rework on services.au3 to reflect threadsafe.
      Threadsafe means each dll call must be on "dllopened" instead of calling dll directly
      for example, if you need a function in kernel32.dll, you have to open it and call it after.
      That's contraignant since a lot of integrated functions in autoit are not programmed this way.
      If you take my services.au3, at the end, you'll see reworked function to handle this change. I've not tried
      services for a while, since i don't need it for now, but i can help you only if your provide whole script, to see how you call every functions.
      I can tell that fix stability issues in callback, but i don't think it's need for your script, as far as you don't use callback.


      Best Practice, by udgeen :

      Good news! Probably i've found the working method of integrating service.au3 with other projects

      I realised it after ASock.au3 project by Zatorg (please, sorry if im wrong) - ASock is asynck socket - tcp on event (uses ws2_32.dll).

      Asock & sqlite didnt work together. The only reason for that was..._ArrayDisplay() func with gui!!! Ok. I made special sqlite.au3 without dependences. It works, but my udf seemed too be much heavy to use at another project.

      Few weeks ago I returned to service.au3 and found TCP UDF, Event driven project based on ASock.au3. It seemed to work as example, but didn't work at all as service.

      In my variant of service_example.au3 i posted msdn words about service_main procedure, that it must contain all global vars of project

      I'll try to post that project as an another service_example.au3 in some weeks here. If it will works.

      Some advice: use SysInternals Process Explorer (free gui based), or kill.exe from support tools to stop suspended service process. U can start-stop service even net start/net stop commands. Use file logging while debuging. No need to install-uninstall service after every recompilation: only stop, recompile, start. See, if it was suspended (while stopping) - kill process. The only reason not to stop service correctly i've found for today is unclean exit: opened sockets, maybe some dlls.
      Edit : Arcker note: too bad, that would be too easy. unclean exit is not due to opened dll, but by some more internal exit checks or something.

      FAQ.

      1 - Hey, I've got error 1063 or error 0, what does that mean ?

      It simply means that you intend to run your script in scite or directly by executing it.

      Your script has to be installed as service and run from it. Several ways to do it :
      You have to combine all Globals in one place: for example at the the begining. You have to make it with other udfs too... silly work Then sort Global Const and other Global statements. If u see something like global $x = 1 do that way: global $x leeve at top. $x =1 insert into module's (udf or project) Init func. U have to do it even with standart udf... or use only necessary functions from it in your own include. Or... maybe u have another plan? Try to build your project with modified udfs - does it works now? Hmm... But it have to Maybe later after everything will work fine i'll say "msdn is wrong, microsoft lies"... But maybe i'll say that microsoft - is not so bad, because autoit works in it net start "yourservicename" Services.msc Use API provided _Service_start, Service_stop.  2 - I want to make a GUI !

      It's not possible in a service.
      Create another process and communicate with your service by using IPC.
      3 - I've to let the main function that way ? That's contraignant.

      Hey, a script intended to run as service is special no ? Autoit is not C++. The only way to have a "Main" in autoit is to have a function.

      If you find another way, please share it

      ServiceExample_ThreadSafe.au3
       
      Services.au3
      ServiceExample_v4.au3
      ServicesConstants.au3
    • rickybobby
      By rickybobby
      So I've been trying to create a service using the Service UDF here :  >UDF
      But I keep getting 0 returned, which means failure, and no service appears in the service viewer.
      My goal here is to create a service which will launch an autoit exe before a user logs on.
      Here's my code: 
      #include"C:\Users\xxx\Desktop\serviceCreator\services.au3" $Return =_Service_Create("MY new Service", "NEW SERVICE", $SERVICE_INTERACTIVE_PROCESS, $SERVICE_AUTO_START, $SERVICE_ERROR_IGNORE,'"C:\Program Files\xxx\xxx.exe"') MsgBox("","",$Return) MsgBox("","",@error) Any idea what I'm doing wrong?
    • Manko
      By Manko
      Know your system!
      Prod your system for unwanted code! (virus/malware)
      Please report bugs/requests/criticism or whatever!

      ProDLLer v0.503
      Update: 23rd of October 2011
      ProDLLer.rar
      Earlier versions downloaded: 2726 times.


      Most Recent changes... ; 0.503 ; Fixed: Don't leave icon in tray when leaving, XP/7. ; Fixed: Don't leave them after crash either. ; Added: Don't allow shutdown or standby while ProDLLing in XP, Thanks to Prog@ndy. Vista/7, dont alow shutdown. ; Added: Don't let ProDLLer be put to sleep by idletimers in xp/vista/7. ; Fixed: Lockup when returning from sleep in vista/7, . (if "Noprocs" running then disable "noprocs" and resume all procs.) ; Change: No suspending of "theme"-service in XP. On crash, just resume all processes... like we have to in vista/7... ; 0.502 ; Fixed: Gui-problem fixed by BeginPaint/endpaint... tested on win7 ; Fixed: "Crashnet" and SuspendAll. In the unlikely event that this happens. All procs will be resumed on vist and win7. ; Fixed: Fixed false positives in SSDTshadow on vista/win7. ; 0.501 ; Added: SSDTshadow - not complete, but fully functional. = lacking names. (Logic is painful; need to guard against faults...) ; Fixed: Lockup in crashnet if "Services.exe" and "System" is suspended. Just resume them... You can suspend again... ; Fixed: Further lockups, same, to do with themes and "lsass.exe"... ; 0.500 ; Added: Startup-killing... to take a load off the GUI... it will ask... ; Fixed: Slowdown because I accidentaly changed ProDLLer to itterate processes every second... ; Fixed: Process-CPU-utilization. Movement of abandoned children... I cheat. Just load up new list... ; Fixed: Got rid of the Adlib. There were too many possible problems... ; Fixed: CPU-load. Is again aligned... ; 0.499 ; Added: If over 16 procs start from 1 sec to another or if a total of 40 procs have started; "NoProcsAllowed" is activated. ; Added: Crash-recovery... Just start a new instance of ProDLLer... :) ; Change: No loading of moduleinfo at start. ; Added: Refresh moduleinfo when we need it. KINDA CLUNKY SINCE I ITERATE ALL OF THEM, RIGHT NOW.... ; Added: On start of app. Disallow new procs. "NoProcsAllowed" is activated. ; Fixed: A number of bugs that crash Prodller if insane amounts of processes start and stop... ; 0.498 ; Fixed: "KernelNot.". When disabling callbacks; adjacent CBs of same type would sometimes vanish. Famous anti-rootkit had same faulty behavior. ; 0.497 ; Fixed: Lockup when suspending some procs during modules-itteration. Context-menu disabled during itteration. ; Fixed: Lockup after thread-view due to excessive killing of already terminated security-threads... Now checking IF it needs killing... ; Fixed: Lockup when trying to change state of services while it is already working with your earlier request. Disable display. Thanks for functions:

      Thanks to "Smoke_N" for his "_ProcessListModules()"! Apparently i borrowed it a looooong time ago.
      Thanks to "Engine" for his GREAT "Windows Services UDF"!!!
      Thanks to JScript, Larry, SmOke_N, mrRevoked for _ProcessGetPath. I used this because I'm too lazy to do one myself.

      Special thanks to:

      Thanks to wraithdu for help and support!
      Thanks to Ascend4nt for support and friendship!
      Thanks to trancexx for good talks and friendship!

      Thanks also to this great community! I really feel empowered!

      /Manko [EDIT: New version.]