Results 1 to 10 of 10

Thread: run bat file at shutdown

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Location
    wigan, uk
    Posts
    200

    run bat file at shutdown

    Is it possible to get windows to run a bat file, before it does anyhting else, whenever the computer is shutdown.

    Can you guess what i'm getting at

    thats right, i want this bat file to delete foldtrajlite.lock before it does anything else when shutdown is selected.

    any ideas, or am i gonna have to write a bat file that removes the foldtrajlite.lock file and then waits, and then shuts down?

    The first idea is my prefernece (to run a bat file before doing anything else)

  2. #2
    try this: http://www.webattack.com/get/lastchance.shtml

    you should be able to write your batch file, hook it to this, and you're done

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Location
    wigan, uk
    Posts
    200
    cheers, it seems to take me to a login screen when i use this though.

    Never mind, i'll either stop being lazy and continue right clicking on dfGUI > exit

    or write a bat file to delete foldtrajlite.lock and then call the shutdown -s command.

    Thanks anyway for such a quick response

  4. #4
    Administrator Dyyryath's Avatar
    Join Date
    Dec 2001
    Location
    North Carolina
    Posts
    1,850
    Heh, great minds think alike. I just finished adding a startup & shutdown script under Linux to handle starting & stopping my DF clients gracefully.
    "So utterly at variance is destiny with all the little plans of men." - H.G. Wells

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Location
    wigan, uk
    Posts
    200
    Originally posted by Dyyryath
    Heh, great minds think alike. I just finished adding a startup & shutdown script under Linux to handle starting & stopping my DF clients gracefully.
    wont argue with that

    am gonna be installing linux soon so will probably ask for some help in making similar scripts when I do

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Location
    Santa Barbara CA
    Posts
    355
    For running with Windows I sure like running dFold as a service, and it takes care of shutting it down.

  7. #7
    Senior Member
    Join Date
    Mar 2002
    Location
    MI, U.S.
    Posts
    697
    Originally posted by jonnyw
    am gonna be installing linux soon so will probably ask for some help in making similar scripts when I do
    Here you go. If your distro uses SysV init (basically, everything except for Slackware does), then put this file into /etc/rc.d/init.d, call it "folding" (or whatever), and symlink to it from the runlevel directories. If that doesn't make any sense, then look for a distro tool (like ksysvinit, or RedHat's service) to set things up for you. The stuff in bold needs to be changed depending on where you installed the DF client to, and which terminal you want to run it on (I use 11, so that Ctrl-Alt-F11, or Alt-F11 if X isn't running, will switch to the DF screen).

    Code:
    #!/bin/sh
    
    dfdir=/home/bilbo/distribfold
    
    case $1 in
    	start)
    		echo -n "Starting the Distributed Folding client..."
    		cd $dfdir
    		./foldit </dev/tty11 >/dev/tty11 &
    
    		if [ $? -eq 0 ] ; then
    			echo "    OK"
    		else
    			echo "  FAILED"
    		fi
    
    		;;
    	
    	stop)
    		echo -n "Stopping the Distributed Folding client..."
    		rm -f $dfdir/foldtrajlite.lock
    
    		while ps -C foldtrajlite >/dev/null 2>&1 ; do
    			sleep 1
    		done
    
    		echo "    OK"
    
    		;;
    esac

  8. #8
    Senior Member
    Join Date
    Feb 2003
    Location
    wigan, uk
    Posts
    200
    excellent, cheers for that

    all i need know is to get a new hard drive, and linux installed

  9. #9
    almost retired the-mk's Avatar
    Join Date
    Jan 2003
    Location
    KI/OOE/Austria
    Posts
    1,921
    Blog Entries
    6
    bwkaz

    Your init.d-script works great!

    It's the best way to prevent my linux machine running idle after a power outage

    the-mk

  10. #10
    Senior Member
    Join Date
    Mar 2002
    Location
    MI, U.S.
    Posts
    697
    Uhh, thanks!

    I think I've posted it before (or maybe a previous incarnation of it), I just don't remember where those threads would be. Ah well.

    I wrote it (well, version 1 of it ) after installing LFS. I needed a way to start it automatically, other than running it from rc.local, which was the way I used to do it in Mandrake. I had just figured out how LFS's init system worked (the "functions" script, and the "evaluate_retval" function, among other things), so mine does look a bit different, but it's effectively the same. I decided it'd be better to make it its own script, for some reason I don't remember at the time (probably because making it separate would let me shut it down). A bit of shell programming later, and it actually worked, go figure.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •