Jump to content

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


Recommended Posts

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??

Link to comment
Share on other sites

  • Moderators

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

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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

 

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

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

  • 1 month later...

   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?

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

×
×
  • Create New...