Discussion Locked

Run Program when System is shutdown

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi

I have a PC with Win-98 installed in it.
I want a program (which notes down the time of the shutdown perhaps in a file) to be run automatically when system is shutdown.

i.e this program should run just before the shutdown automatically.How can i write such a program using Visual Basic and how how can i make it run automatically?

Can anyone please help me?

Indira.

9 replies

by lo

Not sure how you could tie such a program to shutdown, but ...

Write a program (or two) that:
1) runs in startup, this would open the start/stop log file, and make an entry that indicates the system was booted, date/time stamp + "BOOTED AT" or some such.

2) have the program then go into a loop (or start another program) that:
a) wakes up every N time intervals (1 second or so)
b) finds the "BOOTED AT" entry done by program 1, read/writes "SHUTDOWN AT" + date/time stamp as record following boot
c) close file
d) wait for N time intervals

Need to add something to accommodate a boot with a crash before the shutdown gets written but that is probably an unlikely. May have to Boot portion add the Shutdown to get past that.

Bit of overhead doing this but not too bad. There are ways to force the data to disk and leave the file open (which saves some time).

2

by pritaeas

hi, write a program that is not visible (like a service) using registerserviceprocess and make sure it cannot be killed by the user. when it shuts down (due to a broadcast of wm_quit) then write to the logfile and close your app.

hth, Hans 'pritaeas' Pollaerts

by andrew

Here's an easy way (you don't have to subclass the wm_quit message).

Create a VB exe with a single form.
Set the form's properties:
BorderStyle = None
Visible = False
ViewInTaskBar = False

In the form's QueryUnload event put the following code:

If UnloadMode = vbAppWindows Then App.LogEvent "System shutting down at " & Now

Compile this, and run it when it at start up. When the OS shuts down, it will kill this app, triggering the event.

Here's a link to the QueryUnload event if you'd like to know more:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbevtqueryunload.asp

(make sure there are no spaces in the URL).

by fenaikh

Hi
There is a utility called somthing like satartup and shutdown luncher which help you manage loading program during sartup and shut down.to load any program you can use the the registry places such as runonce (there is an article in microsft technet)
or use startup menu,autoexec.bat ec..
there is a program listed in zdnet to show you how to shutdown in VB.

Performing the Windows shutdown operation
Help & How-To
July 6, 1999 9:00 PM PT
URL: http://www.zdnet.com/zdhelp/stories/main/0,5594,920189,00.html

Ever wondered how programs that you install automatically perform the Windows shutdown operation? Well, it's actually a simple API call to do this. Add the following API Declares and Constants to a BAS Module:

Declare Function ExitWindowsEx& Lib "user32" (ByVal uFlags&, ByVal wReserved&)

Global Const EWX_FORCE = 4 'constants needed for exiting Windows
Global Const EWX_LOGOFF = 0
Global Const EWX_REBOOT = 2
Global Const EWX_SHUTDOWN = 1

Then you Shutdown/reboot/logoff windows with the following call:

lresult = ExitWindowsEx(EWX_SHUTDOWN, 0&) 'shut down the computer

Note: Replace the first parameter of the ExitWindowsEx function call with the appropriate CONSTANT.

This discussion is closed to new replies.