Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Batch Scripting in XP

  • 25-05-2003 12:04pm
    #1
    Closed Accounts Posts: 1,163 ✭✭✭


    Hi

    Hoping someone can point me in the right direction here,

    What I want is a simple batch script that will run every 10 minutes or so, check to see if file.exe is running if it's not or not responding it kills the process and executes file.exe

    Thanks in advance

    Emboss


Comments

  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Personally, I wouldnt use a script for that, but rather a "real" app, which performs the check then Sleeps for whatever length of time you specify between checks.


    But thats just me....

    jc


  • Closed Accounts Posts: 1,163 ✭✭✭Emboss


    Thanks Bonkey

    Know any stable apps that would be up to the task ?

    Emboss


  • Registered Users, Registered Users 2 Posts: 1,186 ✭✭✭davej


    I'm not an xp expert, but couldn't you use the built in Task Scheduler to do this?.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308569&sd=tech

    Just set your application to run every 10 mins, the task should fail if the application is already running.
    Give me crontab any day..

    davej


  • Closed Accounts Posts: 1,163 ✭✭✭Emboss


    Hi Dave

    Yeh I was using this for awhile but it doesn't work great if the task is not responding,

    GIVE ME CRONTAB :)

    the problem is in this case, i can't change the OS or the software and the software itself isn't very stable I'm lucky to get a few hours of it at best.

    Emboss


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Does XP have the "AT" command? closest to CRONTAB for command line (if you want to batch script to create new scheduled tasks).


  • Advertisement
  • Closed Accounts Posts: 1,163 ✭✭✭Emboss


    yes it does have the "AT" command but the problem with this is i need the script to check and see if the application is "not responding" this seems to be causing the problem :(

    Emboss


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Emboss
    Know any stable apps that would be up to the task ?

    Err....I meant "write a real app", rather than "use a real app".

    Basically, from what I know of the Windows architecture, the type of information you need can be gotten in one of two ways :

    1) API calls
    2) parsing the output of an already-written app which uses these API calls and generates output to stdout (or file, or somewhere)

    Because of the predominantly "windowsy" use of NT/XP, I doubt you're gonna find too many of the latter apps, which means that you'll probably find that you need to write one yourself.

    Similarly, when it comes to identifying a non-resonsive app, killing and restarting it, its again API calls (for Task Manager-style information), or finding a command-line tool which already does it for you, which your script can then use.

    Again, my guess is that you'll find these relatively few and far between.

    (I'm assuming, by the way, that the app in question doesnt have some sort of built-in "syn/ack" functionality where you can get it to tell you if its alive itself)

    So...if it were down to me, I'd have a quick search for these tools, then give up in disgust, and write my own version...and if I was writing the two of those, I'd rather write them as DLLs, and write a full-blown app to do the checking for me, rather than writing two command-line apps, and a script to hook them together...if you get my drift?

    Basically, I have never found scripting in NT/XP to be in any way "well done". Being a programmer, I tend to turn to writing programs as a preferable solution. With stuff like VB (for NT) or C# (for XP), its pretty straightforward to write everything you need, with the obvious caveat of having to dig around in an API reference to find out the calls you want.....

    jc

    And yes - the AT command in NT/XP is terrible. For evidence of this, check out the number of applications which come with their own scheduler....including many of MS' own!. If the guys who write the OS wont use the functionality within their own applications....it kinda says it all.


  • Registered Users, Registered Users 2 Posts: 640 ✭✭✭Kernel32


    This link should have everything you need...

    http://www.sysinternals.com/ntw2k/freeware/pstools.shtml

    You could use a .vbs file to tie it all together and run it from Scheduled Tasks.

    Bonkey, what is it about scheduled tasks on XP that is so bad?

    -A


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    If you got the dosh you could try Automate.

    http://www.unisyn.com/

    A TaskScheduler on steroids.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Kernel32
    Bonkey, what is it about scheduled tasks on XP that is so bad?

    The "flexibility" of the AT command is..quite simply...not there.

    For example, if you want a job to run (say) every 30 minutes, you cant. You can have *one* time for every date entry. So, you need 48 entries just to run the same script every 30 mins.

    Also, the level of security surrounding it is - for lack of a better term - nonexistant. How can you run jobs with differing privileges?

    Compare this to - for example - the scheduling facilities built in to MS SQL Server. The flexibility and design of that puts the AT command to shame, and even it is by no means complete (lacking the facility to have a "holiday table" for example).

    Look at pretty much every single backup program on the market....again, you find the same story. Forget the AT command, and have your own built in - thats the approach that they all seem to take.

    Somehow, I don't think its because they all enjoy re-inventing the egg :)

    jc


  • Advertisement
  • Closed Accounts Posts: 304 ✭✭Zaltais


    There is a scriptable program / Scripting Language called AutoIt.

    It has a function called IfWinExist whihc can be used to check if a program is running (based on the window title) and then can perform an action based on that.

    Take a look here


  • Closed Accounts Posts: 1,163 ✭✭✭Emboss


    Thanks to everyone for the ideas,

    I'm sure out of one of them I'll create a soloution.

    I'll give it a go when i get home

    Cheers

    Emboss


  • Registered Users, Registered Users 2 Posts: 640 ✭✭✭Kernel32


    bonkey,

    What is wrong with scheduled tasks, look under the control panel, why are you using the AT command anyway, this is 2003, not 1993. In scheduled tasks you can assign the user under which the process should run and set recurring tasks, such as your every 30 minutes example. This has been in windows since at least WinNT 4.0 and isn't something new to XP.

    -A


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Kernel, have you even read what I wrote?

    I said (and I'll quote myself here to make sure there's no mix up) :

    And yes - the AT command in NT/XP is terrible.

    So when you asked me about scheduled tasks on NT "that are so bad", I naturally assumed you were referring to the stuff I said was bad, rather than something that I never once referred to.

    The AT command - as suggested as being potentially useful by others on this thread - is a piece of crap on NT and on XP. I stand by that assertion.


    jc


  • Registered Users, Registered Users 2 Posts: 640 ✭✭✭Kernel32


    bonkey,

    I apologise for switching context on you within my reply, my question related to scheduled tasks, where as you were discussing the AT command so it didn't meet in the middle.
    I totally agree with you that the AT command is severely lacking in functionality, but I also maintain that scheduled tasks is a useful and viable solution for this particular problem and doesn't require reinventing this functionality within another application.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Kernel32
    but I also maintain that scheduled tasks is a useful and viable solution for this particular problem and doesn't require reinventing this functionality within another application.

    Agreed....

    As I said...Iwouldnt really expect to find the libraries/command-line-apps to do what was wanted, so once going down the path of writing 90%+ of the app, I generally throw a Sleeper routine in instead of bothering with a schedule.

    However, seeing as you've provided a link to those rather nifty ps-thingies (which is now firmly bookmarked for later usage), as you said...VBScript is probably enough to do the rest (assuming the psTools can determine when an app is on the process list but "not responding").

    In that case...yup...scripting and the Scheduler is a good way to go.

    But still stay away from the AT command ;)


Advertisement