kor Posted May 24, 2011 Share Posted May 24, 2011 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. Link to comment Share on other sites More sharing options...
November Posted May 24, 2011 Share Posted May 24, 2011 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] Link to comment Share on other sites More sharing options...
kor Posted May 24, 2011 Author Share Posted May 24, 2011 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. Link to comment Share on other sites More sharing options...
November Posted May 24, 2011 Share Posted May 24, 2011 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] Link to comment Share on other sites More sharing options...
wakillon Posted May 25, 2011 Share Posted May 25, 2011 the ExitLoop exists the For Next loop, not the while loop.the ExitLoop "Exit" the For Next loop, not the while loop AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kor Posted May 25, 2011 Author Share Posted May 25, 2011 (edited) the ExitLoop "Exit" the For Next loop, not the while loop 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 May 25, 2011 by kor Link to comment Share on other sites More sharing options...
kor Posted May 25, 2011 Author Share Posted May 25, 2011 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 Link to comment Share on other sites More sharing options...
wakillon Posted May 25, 2011 Share Posted May 25, 2011 How does it work ?There is no $x in the loop ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kor Posted May 25, 2011 Author Share Posted May 25, 2011 How does it work ?There is no $x in the loop ? Thats the point. There is no X which means its a forever loop which is what I want. Link to comment Share on other sites More sharing options...
wakillon Posted May 25, 2011 Share Posted May 25, 2011 Why not a While 1 ; WEnd AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
kor Posted May 25, 2011 Author Share Posted May 25, 2011 Why not aWhile 1 ;WEndWell, 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now