Jump to content
Sign in to follow this  
arcker

_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]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hi Arcker,

Thanks for the reply and investigation but i'm still getting the 1061 error

Also tried with beta 3.3.9.4 and another computer running Windows 7 32 Bits

Thnx

Best regards,

Emiel

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


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

Share this post


Link to post
Share on other sites

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?

Share this post


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

Share this post


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]

Share this post


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

Share this post


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]

Share this post


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>

Share this post


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

Share this post


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]

Share this post


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.

Share this post


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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • 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?
    • By dimm
      Is it possible to compile script without any icon resources included?
      When I make exe it uses default system icon of current OS even if I compile as console application.
      On other versions of Windows it looks a little strange

       
      Update:
      It seems that the only way is remove icons from exe after compilation using resource editors like ResHacker.

       
      another bad solution:
      Using corrupted 35 bytes icon file. Windows can't load it and shows default system icon.
      #pragma compile(Icon, broken.ico) broken.ico
    • By Dreamfire
      Hi,
      Since today, exe's are being flagged as having a trojan by Windows Defender (Fuery.B!cl)
      Version:  3.3.14.3 - SciTE Version 3.7.3



       

×
×
  • Create New...