JedCooper Posted November 7, 2008 Share Posted November 7, 2008 Hi: I am trying to write a script that is an infinite loop containing if statements to check if an exe exists on the C:\ drive and then if the process is running. If it is not running, run it but I keep running into problems as I am a newbie. I would appreciate any ideas and/or assistance...I have: $folder = ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\executable.exe") While 1 If Not FileExists($folder)= 1 Then MsgBox(0,"File Not found", "Please contact Helpdesk") ElseIf = 0 Then ;exit the if statement and proceed to the one below if it's false and the exe is present as it should be EndIf If Not ProcessExists ("executable.exe") Then Run ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\executable.exe") Exit EndIf Sleep (600000) ; i need it to sleep for 10 minutes and then run the loop again because it's an important app Wend But I am getting errors.... Thanks Link to comment Share on other sites More sharing options...
Valuater Posted November 7, 2008 Share Posted November 7, 2008 (edited) Maybe... $folder = ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\executable.exe") While 1 If Not FileExists($folder) Then MsgBox(0, "File Not found", "Please contact Helpdesk") Exit EndIf If Not ProcessExists("executable.exe") Then $Runner = FileGetShortName($folder) Run($Runner) EndIf Sleep(600000) ; i need it to sleep for 10 minutes and then run the loop again because it's an important app WEnd 8) BTW... Welcome to the Forums Edited November 7, 2008 by Valuater Link to comment Share on other sites More sharing options...
dbzfanatic Posted November 7, 2008 Share Posted November 7, 2008 Please use the code or codebox tags when posting code. Also what error are you getting? More information would help. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Valuater Posted November 7, 2008 Share Posted November 7, 2008 (edited) Please use the code or codebox tags when posting code. Also what error are you getting? More information would help.There was enough info for me!!!8)BTW It's his FIRST POST... maybe we could teach/show him how to use a codebox? Edited November 7, 2008 by Valuater Link to comment Share on other sites More sharing options...
JedCooper Posted November 7, 2008 Author Share Posted November 7, 2008 There was enough info for me!!!8)BTW It's his FIRST POST... maybe we could teach/show him how to use a codebox?Thank you this is great. Sorry about that! I will use the code box next time. When I try to run it after compiled, it returns the error:Line -1: Error: Error in ExpressionAnd it was also getting an error on Line 21 which i have bolded in the code box below that was error 'else' statement with no matching 'if' statement. But it looks like the code from Valuater is working! Thank you! One other question, when the script runs and if the exe is already running, it gives a message box that it is already running and you need to click OK to clear it. Is there a way to suppress this message and keep it silent if it's running? Users will kill me! CODE$folder = ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\executable.exe")While 1If Not FileExists($folder)= 1 Then MsgBox(0,"File Not found", "Please contact Helpdesk")ElseIf = 0 Then Exit ;Line 21, which needs to exit the if statement and proceed to the one below if it's false and the exe is present as it should beEndIfIf Not ProcessExists ("executable.exe") Then Run ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\executable.exe")ExitEndIfSleep (600000) ; i need it to sleep for 10 minutes and then run the loop again because it's an important appWend Link to comment Share on other sites More sharing options...
Valuater Posted November 8, 2008 Share Posted November 8, 2008 it gives a message box that it is already runningI don't see that message box in my code or yours??8) Link to comment Share on other sites More sharing options...
JedCooper Posted November 8, 2008 Author Share Posted November 8, 2008 it gives a message box that it is already runningI don't see that message box in my code or yours??8)I know, isn't that bizare! Check out the attached screenshot... Link to comment Share on other sites More sharing options...
Valuater Posted November 8, 2008 Share Posted November 8, 2008 (edited) Maybe there are two exe files with this progy because If Not ProcessExists("executable.exe") Then $Runner = FileGetShortName($folder) Run($Runner) EndIf will not run it again... of course you could be using the wrong exe name too!!!...??? 8) Edited November 8, 2008 by Valuater Link to comment Share on other sites More sharing options...
JedCooper Posted November 8, 2008 Author Share Posted November 8, 2008 Maybe there are two exe files with this progy becauseIf Not ProcessExists("executable.exe") Then $Runner = FileGetShortName($folder) Run($Runner) EndIfwill not run it again... of course you could be using the wrong exe name too!!!...???8)Weird, it's got to be something with the vendor's software; it works perfectly when testing with notepad.exe or iexplore.exe. And it does work correctly with the message box if the exe isn't found. I'll have to keep testing...Thank you once again! Awesome Link to comment Share on other sites More sharing options...
JedCooper Posted November 8, 2008 Author Share Posted November 8, 2008 Weird, it's got to be something with the vendor's software; it works perfectly when testing with notepad.exe or iexplore.exe. And it does work correctly with the message box if the exe isn't found. I'll have to keep testing...Thank you once again! AwesomeFound it! The exe that was running had the old 8.3 convention when i looked in task manager. It was execut~1.exe and once i adjusted the code it worked fine. I also removed the exit after the first if statement...Thanks!This option worked too:CODEIf Not ProcessExists("DICTEX~1.EXE") Then Run ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\DictExport.exe") EndIf Link to comment Share on other sites More sharing options...
Valuater Posted November 8, 2008 Share Posted November 8, 2008 Welcome... good luck with that 8) Link to comment Share on other sites More sharing options...
storme Posted November 8, 2008 Share Posted November 8, 2008 Weird, it's got to be something with the vendor's software; it works perfectly when testing with notepad.exe or iexplore.exe. And it does work correctly with the message box if the exe isn't found. I'll have to keep testing... Thank you once again! Awesome Check that the orginal "executable.exe" is in the process/task list. It maybe that the original program starts a child process then exits. That way when you check ProcessExists("executable.exe") the orignal process doesn't exist and your code tries to (re)run it. But when the process starts it knows to check for the child and gives the error. Good luck John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E 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