Run program before shutdown

Just starting out? Need help? Post your questions and find answers here.
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Run program before shutdown

Post by whertz »

Does anyone know how to run a program before windows shuts down? Like this tool does: http://www.fileware.com/products.htm#LastChance

I don't need to shut down windows myself, what I need is to detect when Windows shuts down, launch a program and when it is finished then carry on shutting windows down. I know you can do it via gpedit.msc but I need to do it by a PB program or batch file. Hope I made sense! Thanks.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Run program before shutdown

Post by c4s »

You could catch the #WM_QUERYENDSESSION message (http://msdn.microsoft.com/en-us/library ... 85%29.aspx), block shutting down, run the program you need and then shut down yourself.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Re: Run program before shutdown

Post by whertz »

c4s wrote:You could catch the #WM_QUERYENDSESSION message (http://msdn.microsoft.com/en-us/library ... 85%29.aspx), block shutting down, run the program you need and then shut down yourself.
Thanks c4s but that's beyond my capability. I just thought someone on the forum might have wanted to do this before and had some code handy.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Run program before shutdown

Post by Shardik »

whertz wrote:I just thought someone on the forum might have wanted to do this before and had some code handy.
ricardo posted a code example just 3 weeks ago:
http://www.purebasic.fr/english/viewtop ... 12&t=45779
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Re: Run program before shutdown

Post by whertz »

Shardik wrote:
whertz wrote:I just thought someone on the forum might have wanted to do this before and had some code handy.
ricardo posted a code example just 3 weeks ago:
http://www.purebasic.fr/english/viewtop ... 12&t=45779
Thanks Shardik. Seems simple enough, but this code would not wait until your program has finished what it is doing, so there could be a problem if windows shuts down too early.
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

Re: Run program before shutdown

Post by buddymatkona »

@whertz
Don't give up on Group Policy if you want to keep this simple. Just add a batch file into the Shutdown folder used by the MMC Group Policy snap-in. You will need admin privileges for MMC setup and to put the .BAT file in the proper folder but once there it can run a PB EXE which will not be cut off. It is easy to have the program look for a command somewhere to tell it what to do so you will not have to edit policy more than once.
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Re: Run program before shutdown

Post by whertz »

buddymatkona wrote:@whertz
Don't give up on Group Policy if you want to keep this simple. Just add a batch file into the Shutdown folder used by the MMC Group Policy snap-in. You will need admin privileges for MMC setup and to put the .BAT file in the proper folder but once there it can run a PB EXE which will not be cut off. It is easy to have the program look for a command somewhere to tell it what to do so you will not have to edit policy more than once.
I need to add the program not just for my computer, but other's as well. This is why I need a PB program to do it, or a batch file or something. So it has to be 'portable' in that it will run the program when the user finishes setting up my program. Can it be added to Group Policy via script? Maybe adding it via registry but that is kinda messy.
Post Reply