Home » Questions » Computers [ Ask a new question ]

run script on first boot, and on shutdown

run script on first boot, and on shutdown

We are using a web based punch in/punch out clock at work, and I only need to double click two nice icons to send the proper commands to the server when I get to work in the morning, and finish work at the evening.

Asked by: Guest | Views: 377
Total answers/comments: 2
Guest [Entry]

"To Windows, ""I'm being powered up"" and ""I'm being rebooted"" are the same thing. The OS doesn't know any difference between the two. Hibernation or Sleep modes are different but your midday reboots may actually require a reboot, and a Hibernate or Sleep won't suffice.

Consider this design (steps only; I script in bash). Two scripts, a clock-in script and a clock-out script. Schedule the first to run at login/boot, every time the computer starts. Run the second manually, only when clocking out -- let it shut the computer down for you.

clock-in script

Run this automatically at boot (or login). It can be scheduled with the Windows scheduler, or placed in Startup folder. It'll create a file to indicate that you've clocked in, and won't clock you in again if the file exists when it's run:

Check for the existence of some textfile ""C:\username.clocked.in"", and exit if found. If not found, continue.
Create the file.
Run the clock-in command.

clock-out script

This script is not automatically run. Instead, it should be run by double-clicking a desktop icon when the user is ready to clock-out and shut down the computer. This script will delete the special file, run the clock-out command, and shutdown the computer.

Delete the lockfile ""C:\username.clocked.in"".
Run the clock-out command.
Run shutdown -s to shutdown the computer."
Guest [Entry]

You don't need to create any batch files for this, just schedule these files to be launched at those two specific times of the day using the built-in windows scheduler. This way it doesn't matter if you restart your pc during the day.