Run a program before Logoff and wait for finish

3

2

When I want to run a program (.exe \ .bat) before Windows 7 Home Premium Logoff \ Restart I use the Task Scheduler and I set a custom event: Log: System, Source: Winlogon, Event ID: 7002 \ 4634 \ 4647 \ .....

The problem is that the program starts but the system closes before the program finishes, while it's running.

What can I do? (My O.S doesn't have gpedit.msc unfortunately)

user3133076

Posted 2014-12-22T19:43:11.867

Reputation: 145

1Perhaps give this a try (not sure if it'll work): Add shutdown /a to the start of the script (to abort the current shutdown), and then add shutdown -s -t 00 to the end of it to initiate a new shutdown sequence when it's done. You may have to make a couple scripts or something to deal with reboot vs. shutdown vs. hibernation, etc. Are you on an Active Directory domain by any chance? – Ƭᴇcʜιᴇ007 – 2014-12-22T19:47:52.117

1It doesn't work. The system closes anyway. It doesn't abort the shutdown. The help says "/A can only be used during the time-out period" – user3133076 – 2014-12-22T20:44:42.273

What edition of Windows is this? Pro, something else? – I say Reinstate Monica – 2014-12-22T20:48:56.587

Windows 7 Home Premium (no gpedit.msc unfortunately) – user3133076 – 2014-12-22T21:27:38.813

Could you have a shortcut to run this item , then use a shutdown command after, instead of fighting a closing down system to run a program then? Just have an assortment of shutdown batches? I use that method from toolbars (like docks) – Psycogeek – 2014-12-22T21:34:13.120

No, I need to use the standard mode (standard UI) to restart and shutdown the PC. – user3133076 – 2014-12-22T21:40:49.537

Try make a batch file which executes the task and then, at the end, have a shutdown command. – benscabbia – 2014-12-22T22:56:09.117

No, I have to restart and shutdown the PC normally – user3133076 – 2014-12-23T08:41:12.400

Answers

0

Most probably you will need a tool for doing this. Here you can find 4 that could accomplish what you need with some tunning:

4 Tools to Prevent, Cancel and Abort a Windows System Shutdown

From these I think Shut It! is the best option available. You can configure it to prevent any shutdown while your application is not running and allow them when you app is on. That would do the trick.

Ignacio Soler Garcia

Posted 2014-12-22T19:43:11.867

Reputation: 1 729

0

What about... A Scheduled Task with the trigger set to "On disconnect from user session", and the "Connection from Local Computer" option set? (A shutdown/restart does logoff/disconnect the user session before powering down, so???)

Scott

Posted 2014-12-22T19:43:11.867

Reputation: 1

3True, the program starts but I can't make it ends before the system closes. In this way it launches the program and, after few seconds, the O.S. shutdown or restarts. – user3133076 – 2014-12-22T21:36:50.807

1I wonder if disabling the switch "If the running task does not end when requested, force it to stop" makes a difference? Or changing the priority of the script to Realtime? Without gpedit is a challenge. – Scott – 2014-12-22T22:52:22.690

It makes the program "survives" about 4 seconds more, but the problem is the same... Is it sure gpedit resolves this issue? – user3133076 – 2014-12-23T09:14:57.160

Here's the Technet on it... http://technet.microsoft.com/en-us/library/cc770300.aspx OR, how about create three different scripts on the desktop? Logoff, Shutdown, and Restart. Then call the command at the end of the script, OR write the script to choose your shutdown option? Of course, you'd have to use the shortcuts rather than the Start button power options, but it may suffice.

– Scott – 2014-12-23T13:29:38.610

The Technet solution refers to gpedit.msc and my O.S. doesn't have it. Moreover, I have to restart and shutdown the PC normally. – user3133076 – 2014-12-23T15:04:37.640

Yes, not available in Home but available if you choose the Windows Anytime Upgrade to Pro. (I believe that'll run you about $150 if you shop around.) There are some gpedit hack tools available online but those can be hit/miss/systemfail. You may be able to manually add the registry keys needed for the shutdown scripting. Here's the link to download the Group Policy Settings Reference in xlsx: http://www.microsoft.com/en-us/download/details.aspx?id=25250. If this a business necessity, it may be worth the upgrade opposed to the hours of trial, error, and research. If not, get your hands dirty.

– Scott – 2014-12-23T21:14:46.487