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

    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      I've scripted AutoIT to scrape a web forum I'm part of using the IE.au3 #include.  The script works great if I'm logged in, but doesn't work as a service.  Anyone have any ideas on how I might achieve that or will I have to have the computer logged in at all times?
      Thanks,
      -John
    • Kirky
      By Kirky
      Hello Again Legends of AutoIT
      I am immensely grateful for the help I was given in creating my first script which works (almost) perfectly when logged on to a PC with admin rights.
      The problem is that I need to silently install the application on to 50 PCs that do not have admin rights. We have a homemade distribution tool but basically a log on script runs, checks if your in an AD group and if you are it installs the application. The problem I have is that the user that installs the application is actually a service run as a user and this means that there is no UI.
      My script doesn't seem to run correctly or at least the application is not installed and I don't know enough about AutoIT basics (yet) to know whether it can be used in this context.
      I'm more than happy to give more information or share my script if this is not enough information to go on.
      Thanks in advance
    • musicstashall
      By musicstashall
      Excuse me, I did not understand how in the function of Main I can include hundreds of functions of my executable code ?? How to implement this?
    • 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