Sign in to follow this  
Followers 0
kor

problem making a script run as a service

11 posts in this topic

Here is my code:

While 1
    ProcessWait("logon.scr")
    If ProcessExists("logon.scr") Then
        For $i = 1 to 1800 Step 1
            If Not ProcessExists("logon.scr") Then ExitLoop
            Sleep(1000)
        Next
        If $i >= 1800 Then Run("psshutdown.exe -d -t 1", @WindowsDir & "\", @SW_HIDE)
    EndIf
WEnd

I am using this code to try and turn the script into a service. (I have tried both compiled and uncompiled)

#include "ServiceControl.au3"
$sService = "Sleep"
_CreateService("", $sService, "C:\script.exe", "C:\Windows\srvany.exe", "LocalSystem", "", 0x110)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $sService & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)

The service is created as verified in services.msc. However when I attempt to start the service I get an error

"The C:\script.exe service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service"

I'm not sure what I am doing wrong.

Share this post


Link to post
Share on other sites



Hi,

If Not ProcessExists("logon.scr") Then ExitLoop

Your script must be always on a loop, or else the script ends!

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Hi,

If Not ProcessExists("logon.scr") Then ExitLoop

Your script must be always on a loop, or else the script ends!

Cheers

the ExitLoop exists the For Next loop, not the while loop.

Uncompiled, this code above works fine. it's when I try and run it as a service that I have a problem.

Share this post


Link to post
Share on other sites

Hi again,

And this?

RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $sService & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)

Try to hard code c:\script.exe

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

the ExitLoop exists the For Next loop, not the while loop.

the ExitLoop "Exit" the For Next loop, not the while loop Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

the ExitLoop "Exit" the For Next loop, not the while loop Posted Image

misspelled.

I'm still having the problem though.

EDIT: After even trying the RunAsSvc.exe program I am seeing the same problem when trying to start the service. Which leads me to believe it is not the service creation that is the problem... it has something to do with my original script.

When I run the script either uncompiled or even compiled it works fine. But for some reason when trying to run that While loop program as a service it just immediately terminates. Has anyone ever seen this problem or can let me know what I need to change in my script to make it run as a service properly?

Edited by kor

Share this post


Link to post
Share on other sites

Well, I figured out my problem. It was the while loop. I changed it to a DO loop and everything works fine. Here is my updated code.

$x = 0
Do
    ProcessWait("logon.scr")
    If ProcessExists("logon.scr") Then
        For $i = 1 to 1800 Step 1
            If Not ProcessExists("logon.scr") Then ExitLoop
            Sleep(1000)
        Next
        If $i >= 1800 Then Run("psshutdown.exe -d -t 1 /accepteula", @WindowsDir & "\", @SW_HIDE)
    EndIf
Until $x = 1

Share this post


Link to post
Share on other sites

How does it work ?

There is no $x in the loop ? Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

How does it work ?

There is no $x in the loop ? Posted Image

Thats the point. There is no X which means its a forever loop which is what I want.

Share this post


Link to post
Share on other sites

Why not a

While 1

;

WEnd


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Why not a

While 1

;

WEnd

Well, I figured out my problem. It was the while loop. I changed it to a DO loop and everything works fine. Here is my updated code.

That is why.

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