Need help with a batch file



  • I have a Win7 box running a program that sends all of our clock-in transactions to our ERP software. About 4 times a week, the program gets hung up and I get into work with a ticket waiting that there is nothing posted in the system for that day. I RDP into the box, close the program, restart it and everything posts through without issue. The ERP company has never been able to solve it and now they claim that its all because its running on VFP which is no longer supported by Microsoft and won't help.

    I figure if I can schedule a batch file to run every morning to force the program to restart, it will keep itself taken care of. The problem is, I can't figure out how to write this thing. It should be simple...kill process, start process but I just can't get it to work. Can anyone point me in the right direction here?



  • @tracy_burton said in Need help with a batch file:

    I have a Win7 box running a program that sends all of our clock-in transactions to our ERP software. About 4 times a week, the program gets hung up and I get into work with a ticket waiting that there is nothing posted in the system for that day. I RDP into the box, close the program, restart it and everything posts through without issue. The ERP company has never been able to solve it and now they claim that its all because its running on VFP which is no longer supported by Microsoft and won't help.

    I figure if I can schedule a batch file to run every morning to force the program to restart, it will keep itself taken care of. The problem is, I can't figure out how to write this thing. It should be simple...kill process, start process but I just can't get it to work. Can anyone point me in the right direction here?

    taskkill /fi "imagename eq process.exe"
    

    ??



  • @dafyre said in Need help with a batch file:

    @tracy_burton said in Need help with a batch file:

    I have a Win7 box running a program that sends all of our clock-in transactions to our ERP software. About 4 times a week, the program gets hung up and I get into work with a ticket waiting that there is nothing posted in the system for that day. I RDP into the box, close the program, restart it and everything posts through without issue. The ERP company has never been able to solve it and now they claim that its all because its running on VFP which is no longer supported by Microsoft and won't help.

    I figure if I can schedule a batch file to run every morning to force the program to restart, it will keep itself taken care of. The problem is, I can't figure out how to write this thing. It should be simple...kill process, start process but I just can't get it to work. Can anyone point me in the right direction here?

    taskkill /fi "imagename eq process.exe"
    

    ??

    That kills it when I put the process name in there but I also need to then start the service.



  • I think I got it figured out. I'll follow up tomorrow if it doesn't work as planned tomorrow morning.



  • You can also use powershell for this:

    Stop-Process -name processname -force
    Start-Sleep -Seconds 15
    Start-Process -FilePath 'C:\Program Files\processname\processname.exe'


  • To avoid this we run programs like this as a scheduled task. So the program runs the process once then closes. Then you schedule it to run every 15-60 minutes. You can this watch your logs and alarm if the process ends in an error code. Just a different way to skin the same cat.



  • @s-hackleman
    This won't work as it needs to be running all the time. As transactions come into the collection server, they need to be posted to the ERP server immediately.



  • @tracy_burton said in Need help with a batch file:

    @s-hackleman
    This won't work as it needs to be running all the time. As transactions come into the collection server, they need to be posted to the ERP server immediately.

    To solve that we use staging and queue tables in SQL. Sounds like you have the best solution for this issue, just sucks that it gets hung so often.



  • I got the batch script and thought everything was fine but it's still not working. I think this is an issue with this specific program so I'm not sure anyone here can help but I'll explain whats happening.

    When it launches, it has some associated preferences with it (the correct location to post to, etc). I can double click on the batch file and it runs perfectly as long as its located in the program folder where the exe file lives. When I setup the task scheduler, I pointed it directly to the correct Program Files folder but it doesn't launch with those associated preferences. I manually run it and its fine but the task scheduler is missing something.



  • Sounds like permissions would be the first place I would look. Does task scheduler attempt to run the program as you, or as a service account?



  • @tracy_burton said in Need help with a batch file:

    I got the batch script and thought everything was fine but it's still not working. I think this is an issue with this specific program so I'm not sure anyone here can help but I'll explain whats happening.

    When it launches, it has some associated preferences with it (the correct location to post to, etc). I can double click on the batch file and it runs perfectly as long as its located in the program folder where the exe file lives. When I setup the task scheduler, I pointed it directly to the correct Program Files folder but it doesn't launch with those associated preferences. I manually run it and its fine but the task scheduler is missing something.

    Does the task need to run as a particular user?

    Also, check the working directory in the Scheduled Job...

    You can also try and CD to the right directory at the start of the batch file.



  • @s-hackleman said in Need help with a batch file:

    Sounds like permissions would be the first place I would look. Does task scheduler attempt to run the program as you, or as a service account?

    I have it set to run as administrator so there should be no permission issues but I'll take a look.



  • @dafyre said in Need help with a batch file:

    @tracy_burton said in Need help with a batch file:

    I got the batch script and thought everything was fine but it's still not working. I think this is an issue with this specific program so I'm not sure anyone here can help but I'll explain whats happening.

    When it launches, it has some associated preferences with it (the correct location to post to, etc). I can double click on the batch file and it runs perfectly as long as its located in the program folder where the exe file lives. When I setup the task scheduler, I pointed it directly to the correct Program Files folder but it doesn't launch with those associated preferences. I manually run it and its fine but the task scheduler is missing something.

    You can also try and CD to the right directory at the start of the batch file.
    I don't think this is the issue since it does run the batch script so it knows where to find it.



  • @tracy_burton said in Need help with a batch file:

    @dafyre said in Need help with a batch file:

    @tracy_burton said in Need help with a batch file:

    I got the batch script and thought everything was fine but it's still not working. I think this is an issue with this specific program so I'm not sure anyone here can help but I'll explain whats happening.

    When it launches, it has some associated preferences with it (the correct location to post to, etc). I can double click on the batch file and it runs perfectly as long as its located in the program folder where the exe file lives. When I setup the task scheduler, I pointed it directly to the correct Program Files folder but it doesn't launch with those associated preferences. I manually run it and its fine but the task scheduler is missing something.

    You can also try and CD to the right directory at the start of the batch file.

    I don't think this is the issue since it does run the batch script so it knows where to find it.

    Right, but when it runs the batch script, unless you have set the Working Directory ("Start in" on the screen), it's just going to run the batch file form probbably C:\Windows\System32 or something like that.



  • @dafyre said in Need help with a batch file:

    @tracy_burton said in Need help with a batch file:

    @dafyre said in Need help with a batch file:

    @tracy_burton said in Need help with a batch file:

    I got the batch script and thought everything was fine but it's still not working. I think this is an issue with this specific program so I'm not sure anyone here can help but I'll explain whats happening.

    When it launches, it has some associated preferences with it (the correct location to post to, etc). I can double click on the batch file and it runs perfectly as long as its located in the program folder where the exe file lives. When I setup the task scheduler, I pointed it directly to the correct Program Files folder but it doesn't launch with those associated preferences. I manually run it and its fine but the task scheduler is missing something.

    You can also try and CD to the right directory at the start of the batch file.

    I don't think this is the issue since it does run the batch script so it knows where to find it.

    Right, but when it runs the batch script, unless you have set the Working Directory ("Start in" on the screen), it's just going to run the batch file form probbably C:\Windows\System32 or something like that.

    I think I see where you're going. Are you talking about what I'm pointing to in this screenshot?
    0_1504028546039_script.jpg





  • @dafyre said in Need help with a batch file:

    @tracy_burton Yepp!

    So in that field I should be putting CD "C:\Program Files (x86)\Consona\Made2Manage Client\BCP",. correct? When I do, the task won't even run.

    I also did it without the "CD" in front and nothing. I removed the quotes and it worked...Stupid crap!



  • @tracy_burton

    how do you solve it when it gets hung ? via task manager --> end process, if that is the case and this is working for you, then batch file will work.

    However I would investigate (when I have free time) how ERP software gets feeded (mysql/basic files/what connector it uses) and see if I can try to further understand to help solve the issue.

    Secondly, try replacing that Win 7 with 2008R2, and check if program runs more stably using that. I reckon there is still a way to trial 2008R2.



  • @emad-r said in Need help with a batch file:

    @tracy_burton

    how do you solve it when it gets hung ? via task manager --> end process, if that is the case and this is working for you, then batch file will work.

    However I would investigate (when I have free time) how ERP software gets feeded (mysql/basic files/what connector it uses) and see if I can try to further understand to help solve the issue.

    Secondly, try replacing that Win 7 with 2008R2, and check if program runs more stably using that. I reckon there is still a way to trial 2008R2.

    The new version of the ERP software runs on .net so once the upgrade is done, I don't anticipate this being an issue. It honestly is just really bad software and this is an "add-on" piece that no one in support even knows about. I've invested many many hours into trying to fix it and I'm done wasting my time. This will suffice for now.


Log in to reply