Jump to content

_Service_UDF v4 : Build your own service with autoit code


Recommended Posts

EDIT: Since the issue is a general W7 issue, not anything to do with this UDF, I decided to open new thread

Hi CGRemakes

I say in first post that it not an issue, it's a security added in w7, vista and w2008+

You can't spawn a gui service in this OS anymore.

Recently i've seen that some remote installers manage to do it, but i wonder if it's the windows installer that let it or not.

If you need one gui, you can spawn a process that will interact with services using IPC methods.

Edit

Maybe i'm wrong, see this :

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to post
Share on other sites
  • Replies 405
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

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

Very nice arcker! Bout time this was done.

In v4 there is a bug in services.au3: Case $SERVICE_CONTROL_STOP,$SERVICE_ACCEPT_SHUTDOWN ; new in v4, stop when system shutdown ( better mmm ? ) https://msdn.microsoft.com/en-us/library/w

Posted Images

The ServiceExample run with no error but the code in While..Wend statements in main() function cannot be executed ;)

I tested with a beep but nothing happen :)

While $bServiceRunning ; REQUIRED  ( dont change variable name ) ; there are several ways to find that service have to be stoped - $Running flag in loop is the first method
  #region --> insert your running code here
        Beep(500,1000)
  Sleep(10)
  #endregion --> insert your running code here
WEnd
Edited by ShadowOfBeing
Link to post
Share on other sites

Hello!

More than 6 months of using your scripts(Service_UDF v.1),thanks for the good work. And, too,was faced with the script hangs.I wrote a vbs-script that kill the process and start the service, when autoit-script hangs. But I wanted the service work for a long time without freezing.

I would like to offer my solution to this problem.I saw that the new version(Service_UDF v.2) and yesterday modified ServiceExample.au3,I created a pause function(see below).The script no longer hang, is working half day.I will test further and write about the results later.

Func _Sleep($delay)

logprint("Pause " & $delay / 1000 & " seconds...")

Local $dll = DllOpen("kernel32.dll")

Local $result = DllCall($dll, "none", "Sleep", "dword", $delay)

DllClose($dll)

EndFunc ;==>_Sleep

Best regards,

Dmitrii.

ServiceExample.v2.au3

Edited by dimmmmmm
Link to post
Share on other sites
  • 1 month later...

Arcker,

I am trying to use the new version of this UDF with a service where I already used the old version. I am getting an execution error message box:

Error: Subscript used with non-Array variable.

Debugging the Services.au3 I found that SetPrivs($avPrivilege) function is giving the error in two positions:

$avOPT = DllCall($hAdvapi32, "int", "OpenProcessToken", _

"hwnd", $ahGCP[0], _

"dword", BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY), _

"hwnd*", 0)

and

DllCall($hAdvapi32, "int", "AdjustTokenPrivileges", _

"hwnd", $avOPT[3], _

"int", False, _

"ptr", DllStructGetPtr($tCurrState), _

"dword", DllStructGetSize($tCurrState), _

"ptr", $pPrevState, _

"dword*", 0)

$ahGCP and $avOPT[3] are declared as non-Array variables.

What is the correct coding for this function?

Link to post
Share on other sites

Trying to play with ServiceExample.au3: Install works, uninstall works, service start works, but when I try to stop the service, it takes too long to stop and gives a 1061 error message and after clicking OK it stops the service.

Running Windows 7 and AutoIt beta.

How to fix this behavior?

Thanks,

Klaus

Link to post
Share on other sites

Hi guys,

I'm aware of problem with win7.

As i said, i've no time to test it on this but will try to do.

The V2 should be used.

Dimmmmm has posted a solution by using the sleep api instead of using internal sleep, dunno, will test it.

@dimmmm : your sleep function seems good but pleae use internal dll $kernel32 since the dll is already opened :D

will try your solution.

Thx all for your feedback,

regards

arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to post
Share on other sites

Hi guys,

I'm aware of problem with win7.

As i said, i've no time to test it on this but will try to do.

The V2 should be used.

Dimmmmm has posted a solution by using the sleep api instead of using internal sleep, dunno, will test it.

@dimmmm : your sleep function seems good but pleae use internal dll $kernel32 since the dll is already opened :D

will try your solution.

Thx all for your feedback,

regards

arcker

I have tryed dimmmmmm´s solution with ServiceExample.au3, but it still gives error 1061 when I try to stop the service.

Klaus

Link to post
Share on other sites

Hi Klaus,

so one test less for me :D

Win7 has integrated a lot of new security, so i'll have to handle it.

Edit :

Guys, when the error is shown, can you please checked if the service is stopped or stop pending ?

thx

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to post
Share on other sites

Hi Klaus,

so one test less for me :D

Win7 has integrated a lot of new security, so i'll have to handle it.

Edit :

Guys, when the error is shown, can you please checked if the service is stopped or stop pending ?

thx

Hi Arcker,

As requested, I have the error message box on screen waiting for the OK, and submitted the following command:

C:\temp>sc query autoit_service
SERVICE_NAME: autoit_service
     TYPE            : 10 WIN32_OWN_PROCESS
     STATE           : 1 STOPPED
     WIN32_EXIT_CODE : 0 (0x0)
     SERVICE_EXIT_CODE : 0 (0x0)
     CHECKPOINT      : 0x0
     WAIT_HINT       : 0x0
C:\temp>
Link to post
Share on other sites

hi

i have same problem as kschwarz.

and when i start compiled ServiceExample.exe without any option i got msgbox "Script not compiled" - "Please run this script once compiled and start it from Services console".

i dont look Service.au3, but means this i should only start ServiceExample.exe as Service or is there a bug and ServiceExample.exe dont 'see' its compiled?

if the second reason i dont wonder why u can install/uninstall ServiceExample.exe as service and start. but when started magbox "Script not compiled" appear which u cant see.

then it is understandable why you can not stop the service and get the error.

ps: therefore it is not a written logfile from ServiceExample.exe when run as service.

i hope iam true :rolleyes:

mfg

Dominic

Link to post
Share on other sites

@D2thunderI Don't think you read first post and whole doc. Those questions shoulbn't be here anymore and that

wasting the thread more and more. Please RTFM before posting thanks.

@kschwarz

Thx for the post. So this is what i thought. In service example, I think the problem is with stop_pending.

At the end, there is a value of 1000 => Means wait 1 second for further answers. Since it stopped just after, scm in Win7 doesn't understand.

Can you try to change thise value from 1000 to 0 ? maybe that's the culprit.

_Service_ReportStatus($SERVICE_STOP_PENDING, $NO_ERROR, 1000);

to

_Service_ReportStatus($SERVICE_STOP_PENDING, $NO_ERROR, 0);

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to post
Share on other sites

@D2thunderI Don't think you read first post and whole doc. Those questions shoulbn't be here anymore and that

wasting the thread more and more. Please RTFM before posting thanks.

@kschwarz

Thx for the post. So this is what i thought. In service example, I think the problem is with stop_pending.

At the end, there is a value of 1000 => Means wait 1 second for further answers. Since it stopped just after, scm in Win7 doesn't understand.

Can you try to change thise value from 1000 to 0 ? maybe that's the culprit.

_Service_ReportStatus($SERVICE_STOP_PENDING, $NO_ERROR, 1000);

to

_Service_ReportStatus($SERVICE_STOP_PENDING, $NO_ERROR, 0);

I´ve made the modification but am still getting the same error 1061!

Klaus.

Link to post
Share on other sites

Ok thx for the info, so i don't think that's too bad since the service stop well, but I have to investigate.

If you have some clues it's ok for me :)

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to post
Share on other sites
  • 4 weeks later...
  • 1 month later...

Hi,

I am learning Autoit sorry if my question is simple or not fit here.

I am using the Services.UDF and what I would like to do is to call my functions using hotkey

HotKeySet("^+!d", "Func1") ;crl-Shift-Alt-d

While $bServiceRunning

;insert code here

Sleep(1000)

WEnd

There service and the func1() work fine if I insert the func1() in the While loop, but Hotkey doesn’t work. I am using win7.

I would be grateful if you let me know what I am doing wrong.

Link to post
Share on other sites
  • 2 weeks later...

The ServiceExample run with no error but the code in While..Wend statements in main() function cannot be executed ;)

I tested with a beep but nothing happen :)

While $bServiceRunning ; REQUIRED ( dont change variable name ) ; there are several ways to find that service have to be stoped - $Running flag in loop is the first method
#region --> insert your running code here
        Beep(500,1000)
Sleep(10)
#endregion --> insert your running code here
WEnd

Hi Seeker,

Have you found out how to solve your Beep Problem?

what I am doing wrong in the code?

HotKeySet("^+!d", "Func1") ;crl-Shift-Alt-d

...

While $ServiceRunning

;Or ---> If _IsPressed('76') Then

Func1()

Sleep(1000)

WEnd

Link to post
Share on other sites
  • 4 weeks later...

HI,

When I run a script , this error i.

C:Program Files (x86)AutoIt3IncludeServices.au3(308,29) : ERROR: $ghADVAPI32: undeclared global variable.

$avSC = DllCall($ghADVAPI32,

~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files (x86)\AutoIt3\Include\Services.au3(2266,41) : ERROR: $ERROR_CALL_NOT_IMPLEMENTED: undeclared global variable.

$return = $ERROR_CALL_NOT_IMPLEMENTED

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files (x86)\AutoIt3\Include\Services.au3(2224,12) : ERROR: _Svc_Main(): undefined function.

_Svc_Main()

thank you for your help.

AutoIt Version: V3.3.8.1 [X64]

Windows Version: WIN_7 [X64]

Language: French (040C)

Link to post
Share on other sites
  • 3 months later...

Arcker,

I am trying to use the new version of this UDF with a service where I already used the old version. I am getting an execution error message box:

Error: Subscript used with non-Array variable.

Debugging the Services.au3 I found that SetPrivs($avPrivilege) function is giving the error in two positions:

$avOPT = DllCall($hAdvapi32, "int", "OpenProcessToken", _

"hwnd", $ahGCP[0], _

"dword", BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY), _

"hwnd*", 0)

and

DllCall($hAdvapi32, "int", "AdjustTokenPrivileges", _

"hwnd", $avOPT[3], _

"int", False, _

"ptr", DllStructGetPtr($tCurrState), _

"dword", DllStructGetSize($tCurrState), _

"ptr", $pPrevState, _

"dword*", 0)

$ahGCP and $avOPT[3] are declared as non-Array variables.

What is the correct coding for this function?

I have the same problem. I try set the options "Recover" but fail. The error occour in this line in Services.au3:

= DllCall($hAdvapi32, "int", "OpenProcessToken", _
"hwnd", $ahGCP[0], _
"dword", BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY), _
"hwnd*", 0)

The error message says:

Line 3396
Error: Subscript used with non-Array variable.

Any help?

Link to post
Share on other sites
  • 3 weeks later...

PS: Never mind, my command propmpt was not running with Admin privileges :D,

run as admin for cmd fixed install problem :)

serv_au.exe -I

InstallService(): Installing service, please waitInstallService(): Problem insta

lling service, Error number is 6

message : The handle is invalid.

Trying the example :(

Tried 3.3.8.1 and 3.3.9.4, same result

OS: WIn 7 x64 Enterprise

Any ideas?

Edited by chavv
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By AutoJohn
      Hi,
      Part of my standard template for a new project is including the lines:
          #AutoIt3Wrapper_Run_Au3Stripper=y ;Run Au3Stripper before compilation (Default=n)
          #Au3Stripper_Parameters=/mo ;     Use the parameters as listed above
      I extensively use bookmarks to jump back and forth between sections of code while debugging and I am experiencing an annoyance that I'm hoping someone could steer me towards a "better" solution.
      The problem is when I go to compile code, all of my bookmarks get deleted.
      I have determined that if I comment out the line    #AutoIt3Wrapper_Run_Au3Stripper then the issue no longer happens and my bookmarks remain.
      Are there some other properties I could be setting somewhere to keep the line in place yet not destroy my bookmarks on every compile?
      Thanks
      SciTE Version 3.7.3     Feb 16 2017 21:41:17
      AutoIT 3.3.14.5
    • By DonChunior
      Introduction 
      In the course of my research for a project involving, among other things, the transfer of large amounts of data, I came across the BITS service and from that the idea for this UDF was born.
      For a brief overview, I'll quote from Microsoft's BITS website (https://docs.microsoft.com/en-us/windows/win32/bits/background-intelligent-transfer-service-portal).
      Availability 🛒
      The BITS UDF can be downloaded from my GitHub repository:
      🔗 https://github.com/DonChunior/BITS-UDF
      Comments 💬
      Currently, only an alpha version of the UDF is available.
      This contains by and large the full functionality of the object interfaces, but still completely lacks error checking and handling.
      I will implement this in the upcoming beta version.
      Therefore I ask you to use the UDF only for testing purposes but not in productive code!
      Acknowledgment 🤝
      Many thanks to @Nine and @Danyfirex.
      You helped me very well in solving some tricky problems.
    • By SgtHugoStiglitz
      HI people,
                        I got a questions, I maintain code in autoIT and every time I compile a new version or modification, Scite generate 2 folders. One folder is finish by released and the other is tentative. I try to make some google search, but never find answer would satisfied myself. The dev who was maintain it before were using AutoIt3Wrapper_GUI, and I don't know if it's related. I look both folder, but they seem pretty identical, but I would like to know what it's the difference between those to folder. Anyone have a clue?
    • By Rhidlor
      I don't have any experience compiling AutoIt scripts or know of any best practices regarding said scripts so I was wondering, what are some of the options for passing data to complied scripts? Here's an example of what I mean by "option": Writing data to a text file, then running a script which reads the data from that text file.
      Thanks!
      I apologize if this topic is a little lackluster
    • By Skeletor
      Hey All,
      Yes, this is an odd request. 
      But is there a way to bulk up the size of the compiled program? 
      I know many want to reduce it's size, but I want to increase it.
      What methods do you suggest?
×
×
  • Create New...