Jump to content
Sign in to follow this  
JedCooper

Check for exe and process

Recommended Posts

JedCooper

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

Share this post


Link to post
Share on other sites
Valuater

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 by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
dbzfanatic

Share this post


Link to post
Share on other sites
Valuater

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 by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
JedCooper

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 Expression

And 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 1

If 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 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

Share this post


Link to post
Share on other sites
Valuater

it gives a message box that it is already running

I don't see that message box in my code or yours??

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
JedCooper

it gives a message box that it is already running

I don't see that message box in my code or yours??

8)

I know, isn't that bizare! Check out the attached screenshot...

post-41536-1226110919_thumb.jpg

Share this post


Link to post
Share on other sites
Valuater

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 by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
JedCooper

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)

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

Share this post


Link to post
Share on other sites
JedCooper

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

Found 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:

CODE
If Not ProcessExists("DICTEX~1.EXE") Then Run ("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\DictExport.exe")

EndIf

Share this post


Link to post
Share on other sites
storme

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.