How to schedule a task to run when shutting down windows










75















How do you schedule a task in Windows XP to run when you shutdown windows. Such that I want to run a simple command line program I wrote in c# everytime I shut down windows. There doesn't seem to be an option in scheduled tasks to perform this task when my computer shuts down.










share|improve this question


























    75















    How do you schedule a task in Windows XP to run when you shutdown windows. Such that I want to run a simple command line program I wrote in c# everytime I shut down windows. There doesn't seem to be an option in scheduled tasks to perform this task when my computer shuts down.










    share|improve this question
























      75












      75








      75


      33






      How do you schedule a task in Windows XP to run when you shutdown windows. Such that I want to run a simple command line program I wrote in c# everytime I shut down windows. There doesn't seem to be an option in scheduled tasks to perform this task when my computer shuts down.










      share|improve this question














      How do you schedule a task in Windows XP to run when you shutdown windows. Such that I want to run a simple command line program I wrote in c# everytime I shut down windows. There doesn't seem to be an option in scheduled tasks to perform this task when my computer shuts down.







      windows-xp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 19 '08 at 13:00









      CrippeobladeCrippeoblade

      2,10042527




      2,10042527






















          9 Answers
          9






          active

          oldest

          votes


















          83














          Execute gpedit.msc (local Policies)



          Computer Configuration -> Windows settings -> Scripts -> Shutdown -> Properties -> Add






          share|improve this answer




















          • 27





            If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

            – Dan Stevens
            Jan 19 '13 at 16:41







          • 3





            WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

            – voji
            Mar 26 '16 at 12:24












          • @voji: Is this true for Windows Server as well?

            – sampathsris
            Apr 24 '18 at 7:48











          • how about restart?

            – dangalg
            Jun 19 '18 at 5:26


















          33














          In addition to Dan Williams' answer, if you want to add a Startup/Shutdown script, you need to be looking for Windows Settings under Computer Configuration. If you want to add a Logon/Logoff script, you need to be looking for Windows Settings under User Configuration.



          So to reiterate what Dan said with this information included,



          For Startup/Shutdown:



          1. Run gpedit.msc (Local Policies)


          2. Computer Configuration -> Windows Settings -> Scripts -> Startup or Shutdown -> Properties -> Add

          For Logon/Logoff:



          1. Run gpedit.msc (Local Policies)


          2. User Configuration -> Windows Settings -> Scripts -> Logon or Logoff -> Properties -> Add


          Source: http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx






          share|improve this answer


















          • 2





            This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

            – Seth Spearman
            Jul 1 '15 at 15:30



















          26














          For those who prefer using the Task Scheduler, it's possible to schedule a task to run after a restart / shutdown has been initiated by setting the task to run after event 1074 in the System log in the Event Viewer has been logged.
          However, it's only good for very short task, which will run as long as the system is restarting / shutting down, which is usually only a few seconds.



          • From the Task Scheduler:

            Begin the task: On an event

            Log: System

            Source: USER32

            EventID: 1074




          • From the command prompt:


            schtasks /create /tn "taskname" /tr "task file" /sc onevent /ec system /mo *[system/eventid=1074]





          Comment: the /ec option is available from Windows Vista and above. (thank you @t2d)



          Please note that the task status can be:






          The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (0x800704DD)






          However, it doesn't mean that it didn't run.






          share|improve this answer

























          • Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

            – Erik Eidt
            Jan 15 '15 at 1:13












          • Yes, it is, since this event is logged on restart / shutdown.

            – Oz Edri
            Jan 16 '15 at 2:45











          • Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

            – t2d
            May 4 '16 at 12:42












          • @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

            – Oz Edri
            May 8 '16 at 9:03







          • 1





            There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

            – testworks
            Nov 9 '18 at 2:45


















          5














          One workaround might be to write a simple batch file to run the program then shutdown the computer.



          You can shut down from the command line -- so your script could be fairly simple:



          c:directorymyProgram.exe
          C:WINDOWSsystem32shutdown.exe -s -f -t 0





          share|improve this answer






























            4














            If you run GPEdit.MSC you can go to Computer Configuration -> Windows Settings -> Scripts, and add startup /shutdown scripts. These can be simple batch files, or even full blown EXEs. Also you can adjust user configurations for logon and logoff scripts in this same tool. This tool is not available in WIndows XP Home.






            share|improve this answer























            • really useful to know you can run .EXEs, thanks!

              – user533832
              May 28 '13 at 12:38


















            4














            The Group Policy editor is not mentioned in the post above. I have used GPedit quite a few times to perform a task on bootup or shutdown. Here are Microsoft's instructions on how to access and maneuver GPedit.



            How To Use the Group Policy Editor to Manage Local Computer Policy in Windows XP






            share|improve this answer
































              1














              You can run a batch file that calls your program, check out the discussion here for how to do it:
              http://www.pcworld.com/article/115628/windows_tips_make_windows_start_and_stop_the_way_you_want.html



              (from google search: windows schedule task run at shut down)






              share|improve this answer






























                1














                What I can suggest doing is creating a shortcut to the .bat file (for example on your desktop) and a when you want to shutdown your computer (and run the .bat file) click on the shortcut you created. After doing this, edit the .bat file and add this line of code to the end or where needed:



                c:windowssystem32shutdown -s -f -t 00


                What this does it is



                1. Runs the shutdown process

                2. Displays a alert

                3. Forces all running processes to stop

                4. Executes immediately





                share|improve this answer






























                  1














                  On Windows 10 Pro, the batch file can be registered; the workaround of registering cmd.exe and specifying the bat file as a param isn't needed. I just did this, registering both a shutdown script and a startup (boot) script, and it worked.






                  share|improve this answer






















                    Your Answer






                    StackExchange.ifUsing("editor", function ()
                    StackExchange.using("externalEditor", function ()
                    StackExchange.using("snippets", function ()
                    StackExchange.snippets.init();
                    );
                    );
                    , "code-snippets");

                    StackExchange.ready(function()
                    var channelOptions =
                    tags: "".split(" "),
                    id: "1"
                    ;
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function()
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled)
                    StackExchange.using("snippets", function()
                    createEditor();
                    );

                    else
                    createEditor();

                    );

                    function createEditor()
                    StackExchange.prepareEditor(
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader:
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    ,
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    );



                    );













                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f101647%2fhow-to-schedule-a-task-to-run-when-shutting-down-windows%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown

























                    9 Answers
                    9






                    active

                    oldest

                    votes








                    9 Answers
                    9






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    83














                    Execute gpedit.msc (local Policies)



                    Computer Configuration -> Windows settings -> Scripts -> Shutdown -> Properties -> Add






                    share|improve this answer




















                    • 27





                      If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

                      – Dan Stevens
                      Jan 19 '13 at 16:41







                    • 3





                      WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

                      – voji
                      Mar 26 '16 at 12:24












                    • @voji: Is this true for Windows Server as well?

                      – sampathsris
                      Apr 24 '18 at 7:48











                    • how about restart?

                      – dangalg
                      Jun 19 '18 at 5:26















                    83














                    Execute gpedit.msc (local Policies)



                    Computer Configuration -> Windows settings -> Scripts -> Shutdown -> Properties -> Add






                    share|improve this answer




















                    • 27





                      If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

                      – Dan Stevens
                      Jan 19 '13 at 16:41







                    • 3





                      WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

                      – voji
                      Mar 26 '16 at 12:24












                    • @voji: Is this true for Windows Server as well?

                      – sampathsris
                      Apr 24 '18 at 7:48











                    • how about restart?

                      – dangalg
                      Jun 19 '18 at 5:26













                    83












                    83








                    83







                    Execute gpedit.msc (local Policies)



                    Computer Configuration -> Windows settings -> Scripts -> Shutdown -> Properties -> Add






                    share|improve this answer















                    Execute gpedit.msc (local Policies)



                    Computer Configuration -> Windows settings -> Scripts -> Shutdown -> Properties -> Add







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 24 '17 at 20:30









                    Fabian Röling

                    1501417




                    1501417










                    answered Sep 19 '08 at 13:05









                    Dan WilliamsDan Williams

                    3,62493145




                    3,62493145







                    • 27





                      If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

                      – Dan Stevens
                      Jan 19 '13 at 16:41







                    • 3





                      WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

                      – voji
                      Mar 26 '16 at 12:24












                    • @voji: Is this true for Windows Server as well?

                      – sampathsris
                      Apr 24 '18 at 7:48











                    • how about restart?

                      – dangalg
                      Jun 19 '18 at 5:26












                    • 27





                      If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

                      – Dan Stevens
                      Jan 19 '13 at 16:41







                    • 3





                      WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

                      – voji
                      Mar 26 '16 at 12:24












                    • @voji: Is this true for Windows Server as well?

                      – sampathsris
                      Apr 24 '18 at 7:48











                    • how about restart?

                      – dangalg
                      Jun 19 '18 at 5:26







                    27




                    27





                    If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

                    – Dan Stevens
                    Jan 19 '13 at 16:41






                    If you want a batch script to run at Logoff, I found referencing the .bat file directly didn't work. However, if I used C:WindowsSystem32cmd.exe as the Script Name and /C C:pathtobatchscript.bat as the Script Parameters, it did.

                    – Dan Stevens
                    Jan 19 '13 at 16:41





                    3




                    3





                    WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

                    – voji
                    Mar 26 '16 at 12:24






                    WARINING: The group policy startup and shutdown scipts not executed, when using fastboot (enabled by default in windows 8 and up). In this case, only the restart or force shutdown (from command prompt) shut down really the computer. In all other cases (start menu shutdown), the computer kernel hibernated, and revieved on boot, and GPO startup and shutdown scipts are ignored.

                    – voji
                    Mar 26 '16 at 12:24














                    @voji: Is this true for Windows Server as well?

                    – sampathsris
                    Apr 24 '18 at 7:48





                    @voji: Is this true for Windows Server as well?

                    – sampathsris
                    Apr 24 '18 at 7:48













                    how about restart?

                    – dangalg
                    Jun 19 '18 at 5:26





                    how about restart?

                    – dangalg
                    Jun 19 '18 at 5:26













                    33














                    In addition to Dan Williams' answer, if you want to add a Startup/Shutdown script, you need to be looking for Windows Settings under Computer Configuration. If you want to add a Logon/Logoff script, you need to be looking for Windows Settings under User Configuration.



                    So to reiterate what Dan said with this information included,



                    For Startup/Shutdown:



                    1. Run gpedit.msc (Local Policies)


                    2. Computer Configuration -> Windows Settings -> Scripts -> Startup or Shutdown -> Properties -> Add

                    For Logon/Logoff:



                    1. Run gpedit.msc (Local Policies)


                    2. User Configuration -> Windows Settings -> Scripts -> Logon or Logoff -> Properties -> Add


                    Source: http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx






                    share|improve this answer


















                    • 2





                      This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

                      – Seth Spearman
                      Jul 1 '15 at 15:30
















                    33














                    In addition to Dan Williams' answer, if you want to add a Startup/Shutdown script, you need to be looking for Windows Settings under Computer Configuration. If you want to add a Logon/Logoff script, you need to be looking for Windows Settings under User Configuration.



                    So to reiterate what Dan said with this information included,



                    For Startup/Shutdown:



                    1. Run gpedit.msc (Local Policies)


                    2. Computer Configuration -> Windows Settings -> Scripts -> Startup or Shutdown -> Properties -> Add

                    For Logon/Logoff:



                    1. Run gpedit.msc (Local Policies)


                    2. User Configuration -> Windows Settings -> Scripts -> Logon or Logoff -> Properties -> Add


                    Source: http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx






                    share|improve this answer


















                    • 2





                      This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

                      – Seth Spearman
                      Jul 1 '15 at 15:30














                    33












                    33








                    33







                    In addition to Dan Williams' answer, if you want to add a Startup/Shutdown script, you need to be looking for Windows Settings under Computer Configuration. If you want to add a Logon/Logoff script, you need to be looking for Windows Settings under User Configuration.



                    So to reiterate what Dan said with this information included,



                    For Startup/Shutdown:



                    1. Run gpedit.msc (Local Policies)


                    2. Computer Configuration -> Windows Settings -> Scripts -> Startup or Shutdown -> Properties -> Add

                    For Logon/Logoff:



                    1. Run gpedit.msc (Local Policies)


                    2. User Configuration -> Windows Settings -> Scripts -> Logon or Logoff -> Properties -> Add


                    Source: http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx






                    share|improve this answer













                    In addition to Dan Williams' answer, if you want to add a Startup/Shutdown script, you need to be looking for Windows Settings under Computer Configuration. If you want to add a Logon/Logoff script, you need to be looking for Windows Settings under User Configuration.



                    So to reiterate what Dan said with this information included,



                    For Startup/Shutdown:



                    1. Run gpedit.msc (Local Policies)


                    2. Computer Configuration -> Windows Settings -> Scripts -> Startup or Shutdown -> Properties -> Add

                    For Logon/Logoff:



                    1. Run gpedit.msc (Local Policies)


                    2. User Configuration -> Windows Settings -> Scripts -> Logon or Logoff -> Properties -> Add


                    Source: http://technet.microsoft.com/en-us/library/cc739591(WS.10).aspx







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 11 '13 at 17:25









                    Brett PenningsBrett Pennings

                    1,1381219




                    1,1381219







                    • 2





                      This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

                      – Seth Spearman
                      Jul 1 '15 at 15:30













                    • 2





                      This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

                      – Seth Spearman
                      Jul 1 '15 at 15:30








                    2




                    2





                    This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

                    – Seth Spearman
                    Jul 1 '15 at 15:30






                    This is the better answer. When you open GPEditor it shows two nodes as you describe. Since both nodes have a Windows Settings option then the accepted answer is less clear than your answer. Thanks for the tip. Very helpful.

                    – Seth Spearman
                    Jul 1 '15 at 15:30












                    26














                    For those who prefer using the Task Scheduler, it's possible to schedule a task to run after a restart / shutdown has been initiated by setting the task to run after event 1074 in the System log in the Event Viewer has been logged.
                    However, it's only good for very short task, which will run as long as the system is restarting / shutting down, which is usually only a few seconds.



                    • From the Task Scheduler:

                      Begin the task: On an event

                      Log: System

                      Source: USER32

                      EventID: 1074




                    • From the command prompt:


                      schtasks /create /tn "taskname" /tr "task file" /sc onevent /ec system /mo *[system/eventid=1074]





                    Comment: the /ec option is available from Windows Vista and above. (thank you @t2d)



                    Please note that the task status can be:






                    The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (0x800704DD)






                    However, it doesn't mean that it didn't run.






                    share|improve this answer

























                    • Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

                      – Erik Eidt
                      Jan 15 '15 at 1:13












                    • Yes, it is, since this event is logged on restart / shutdown.

                      – Oz Edri
                      Jan 16 '15 at 2:45











                    • Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

                      – t2d
                      May 4 '16 at 12:42












                    • @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

                      – Oz Edri
                      May 8 '16 at 9:03







                    • 1





                      There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

                      – testworks
                      Nov 9 '18 at 2:45















                    26














                    For those who prefer using the Task Scheduler, it's possible to schedule a task to run after a restart / shutdown has been initiated by setting the task to run after event 1074 in the System log in the Event Viewer has been logged.
                    However, it's only good for very short task, which will run as long as the system is restarting / shutting down, which is usually only a few seconds.



                    • From the Task Scheduler:

                      Begin the task: On an event

                      Log: System

                      Source: USER32

                      EventID: 1074




                    • From the command prompt:


                      schtasks /create /tn "taskname" /tr "task file" /sc onevent /ec system /mo *[system/eventid=1074]





                    Comment: the /ec option is available from Windows Vista and above. (thank you @t2d)



                    Please note that the task status can be:






                    The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (0x800704DD)






                    However, it doesn't mean that it didn't run.






                    share|improve this answer

























                    • Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

                      – Erik Eidt
                      Jan 15 '15 at 1:13












                    • Yes, it is, since this event is logged on restart / shutdown.

                      – Oz Edri
                      Jan 16 '15 at 2:45











                    • Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

                      – t2d
                      May 4 '16 at 12:42












                    • @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

                      – Oz Edri
                      May 8 '16 at 9:03







                    • 1





                      There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

                      – testworks
                      Nov 9 '18 at 2:45













                    26












                    26








                    26







                    For those who prefer using the Task Scheduler, it's possible to schedule a task to run after a restart / shutdown has been initiated by setting the task to run after event 1074 in the System log in the Event Viewer has been logged.
                    However, it's only good for very short task, which will run as long as the system is restarting / shutting down, which is usually only a few seconds.



                    • From the Task Scheduler:

                      Begin the task: On an event

                      Log: System

                      Source: USER32

                      EventID: 1074




                    • From the command prompt:


                      schtasks /create /tn "taskname" /tr "task file" /sc onevent /ec system /mo *[system/eventid=1074]





                    Comment: the /ec option is available from Windows Vista and above. (thank you @t2d)



                    Please note that the task status can be:






                    The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (0x800704DD)






                    However, it doesn't mean that it didn't run.






                    share|improve this answer















                    For those who prefer using the Task Scheduler, it's possible to schedule a task to run after a restart / shutdown has been initiated by setting the task to run after event 1074 in the System log in the Event Viewer has been logged.
                    However, it's only good for very short task, which will run as long as the system is restarting / shutting down, which is usually only a few seconds.



                    • From the Task Scheduler:

                      Begin the task: On an event

                      Log: System

                      Source: USER32

                      EventID: 1074




                    • From the command prompt:


                      schtasks /create /tn "taskname" /tr "task file" /sc onevent /ec system /mo *[system/eventid=1074]





                    Comment: the /ec option is available from Windows Vista and above. (thank you @t2d)



                    Please note that the task status can be:






                    The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (0x800704DD)






                    However, it doesn't mean that it didn't run.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 11 '18 at 8:48

























                    answered Dec 6 '14 at 1:59









                    Oz EdriOz Edri

                    41147




                    41147












                    • Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

                      – Erik Eidt
                      Jan 15 '15 at 1:13












                    • Yes, it is, since this event is logged on restart / shutdown.

                      – Oz Edri
                      Jan 16 '15 at 2:45











                    • Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

                      – t2d
                      May 4 '16 at 12:42












                    • @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

                      – Oz Edri
                      May 8 '16 at 9:03







                    • 1





                      There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

                      – testworks
                      Nov 9 '18 at 2:45

















                    • Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

                      – Erik Eidt
                      Jan 15 '15 at 1:13












                    • Yes, it is, since this event is logged on restart / shutdown.

                      – Oz Edri
                      Jan 16 '15 at 2:45











                    • Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

                      – t2d
                      May 4 '16 at 12:42












                    • @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

                      – Oz Edri
                      May 8 '16 at 9:03







                    • 1





                      There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

                      – testworks
                      Nov 9 '18 at 2:45
















                    Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

                    – Erik Eidt
                    Jan 15 '15 at 1:13






                    Thanks for the tip! @Oz, Will this run on restart as well as shutdown? The case I'm trying to cover is Windows Update forces a restart...

                    – Erik Eidt
                    Jan 15 '15 at 1:13














                    Yes, it is, since this event is logged on restart / shutdown.

                    – Oz Edri
                    Jan 16 '15 at 2:45





                    Yes, it is, since this event is logged on restart / shutdown.

                    – Oz Edri
                    Jan 16 '15 at 2:45













                    Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

                    – t2d
                    May 4 '16 at 12:42






                    Please note, that the argument /ec system does not exist, but it is called /ru system. see support.microsoft.com/en-us/kb/814596#bookmark-4

                    – t2d
                    May 4 '16 at 12:42














                    @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

                    – Oz Edri
                    May 8 '16 at 9:03






                    @t2d, while /ec exists in newer versions, /ru refers to a completely different thing. EC allows you to specify an event channel, while ru allows you to run as another user. Nonetheless thank you for your comment. I'll edit my post accordingly.

                    – Oz Edri
                    May 8 '16 at 9:03





                    1




                    1





                    There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

                    – testworks
                    Nov 9 '18 at 2:45





                    There's a typo in the modifier in your example. It should be ... /mo *[system/eventid=1074], not .../mo *[system/evendid=1074]

                    – testworks
                    Nov 9 '18 at 2:45











                    5














                    One workaround might be to write a simple batch file to run the program then shutdown the computer.



                    You can shut down from the command line -- so your script could be fairly simple:



                    c:directorymyProgram.exe
                    C:WINDOWSsystem32shutdown.exe -s -f -t 0





                    share|improve this answer



























                      5














                      One workaround might be to write a simple batch file to run the program then shutdown the computer.



                      You can shut down from the command line -- so your script could be fairly simple:



                      c:directorymyProgram.exe
                      C:WINDOWSsystem32shutdown.exe -s -f -t 0





                      share|improve this answer

























                        5












                        5








                        5







                        One workaround might be to write a simple batch file to run the program then shutdown the computer.



                        You can shut down from the command line -- so your script could be fairly simple:



                        c:directorymyProgram.exe
                        C:WINDOWSsystem32shutdown.exe -s -f -t 0





                        share|improve this answer













                        One workaround might be to write a simple batch file to run the program then shutdown the computer.



                        You can shut down from the command line -- so your script could be fairly simple:



                        c:directorymyProgram.exe
                        C:WINDOWSsystem32shutdown.exe -s -f -t 0






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 19 '08 at 13:06









                        Neil NeymanNeil Neyman

                        1,7231320




                        1,7231320





















                            4














                            If you run GPEdit.MSC you can go to Computer Configuration -> Windows Settings -> Scripts, and add startup /shutdown scripts. These can be simple batch files, or even full blown EXEs. Also you can adjust user configurations for logon and logoff scripts in this same tool. This tool is not available in WIndows XP Home.






                            share|improve this answer























                            • really useful to know you can run .EXEs, thanks!

                              – user533832
                              May 28 '13 at 12:38















                            4














                            If you run GPEdit.MSC you can go to Computer Configuration -> Windows Settings -> Scripts, and add startup /shutdown scripts. These can be simple batch files, or even full blown EXEs. Also you can adjust user configurations for logon and logoff scripts in this same tool. This tool is not available in WIndows XP Home.






                            share|improve this answer























                            • really useful to know you can run .EXEs, thanks!

                              – user533832
                              May 28 '13 at 12:38













                            4












                            4








                            4







                            If you run GPEdit.MSC you can go to Computer Configuration -> Windows Settings -> Scripts, and add startup /shutdown scripts. These can be simple batch files, or even full blown EXEs. Also you can adjust user configurations for logon and logoff scripts in this same tool. This tool is not available in WIndows XP Home.






                            share|improve this answer













                            If you run GPEdit.MSC you can go to Computer Configuration -> Windows Settings -> Scripts, and add startup /shutdown scripts. These can be simple batch files, or even full blown EXEs. Also you can adjust user configurations for logon and logoff scripts in this same tool. This tool is not available in WIndows XP Home.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 19 '08 at 13:07









                            KibbeeKibbee

                            51.5k26133172




                            51.5k26133172












                            • really useful to know you can run .EXEs, thanks!

                              – user533832
                              May 28 '13 at 12:38

















                            • really useful to know you can run .EXEs, thanks!

                              – user533832
                              May 28 '13 at 12:38
















                            really useful to know you can run .EXEs, thanks!

                            – user533832
                            May 28 '13 at 12:38





                            really useful to know you can run .EXEs, thanks!

                            – user533832
                            May 28 '13 at 12:38











                            4














                            The Group Policy editor is not mentioned in the post above. I have used GPedit quite a few times to perform a task on bootup or shutdown. Here are Microsoft's instructions on how to access and maneuver GPedit.



                            How To Use the Group Policy Editor to Manage Local Computer Policy in Windows XP






                            share|improve this answer





























                              4














                              The Group Policy editor is not mentioned in the post above. I have used GPedit quite a few times to perform a task on bootup or shutdown. Here are Microsoft's instructions on how to access and maneuver GPedit.



                              How To Use the Group Policy Editor to Manage Local Computer Policy in Windows XP






                              share|improve this answer



























                                4












                                4








                                4







                                The Group Policy editor is not mentioned in the post above. I have used GPedit quite a few times to perform a task on bootup or shutdown. Here are Microsoft's instructions on how to access and maneuver GPedit.



                                How To Use the Group Policy Editor to Manage Local Computer Policy in Windows XP






                                share|improve this answer















                                The Group Policy editor is not mentioned in the post above. I have used GPedit quite a few times to perform a task on bootup or shutdown. Here are Microsoft's instructions on how to access and maneuver GPedit.



                                How To Use the Group Policy Editor to Manage Local Computer Policy in Windows XP







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Oct 9 '12 at 12:11









                                meagar

                                178k29272288




                                178k29272288










                                answered Sep 19 '08 at 13:09









                                Michael RunyonMichael Runyon

                                6891912




                                6891912





















                                    1














                                    You can run a batch file that calls your program, check out the discussion here for how to do it:
                                    http://www.pcworld.com/article/115628/windows_tips_make_windows_start_and_stop_the_way_you_want.html



                                    (from google search: windows schedule task run at shut down)






                                    share|improve this answer



























                                      1














                                      You can run a batch file that calls your program, check out the discussion here for how to do it:
                                      http://www.pcworld.com/article/115628/windows_tips_make_windows_start_and_stop_the_way_you_want.html



                                      (from google search: windows schedule task run at shut down)






                                      share|improve this answer

























                                        1












                                        1








                                        1







                                        You can run a batch file that calls your program, check out the discussion here for how to do it:
                                        http://www.pcworld.com/article/115628/windows_tips_make_windows_start_and_stop_the_way_you_want.html



                                        (from google search: windows schedule task run at shut down)






                                        share|improve this answer













                                        You can run a batch file that calls your program, check out the discussion here for how to do it:
                                        http://www.pcworld.com/article/115628/windows_tips_make_windows_start_and_stop_the_way_you_want.html



                                        (from google search: windows schedule task run at shut down)







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Sep 19 '08 at 13:04









                                        devinmooredevinmoore

                                        2,49721614




                                        2,49721614





















                                            1














                                            What I can suggest doing is creating a shortcut to the .bat file (for example on your desktop) and a when you want to shutdown your computer (and run the .bat file) click on the shortcut you created. After doing this, edit the .bat file and add this line of code to the end or where needed:



                                            c:windowssystem32shutdown -s -f -t 00


                                            What this does it is



                                            1. Runs the shutdown process

                                            2. Displays a alert

                                            3. Forces all running processes to stop

                                            4. Executes immediately





                                            share|improve this answer



























                                              1














                                              What I can suggest doing is creating a shortcut to the .bat file (for example on your desktop) and a when you want to shutdown your computer (and run the .bat file) click on the shortcut you created. After doing this, edit the .bat file and add this line of code to the end or where needed:



                                              c:windowssystem32shutdown -s -f -t 00


                                              What this does it is



                                              1. Runs the shutdown process

                                              2. Displays a alert

                                              3. Forces all running processes to stop

                                              4. Executes immediately





                                              share|improve this answer

























                                                1












                                                1








                                                1







                                                What I can suggest doing is creating a shortcut to the .bat file (for example on your desktop) and a when you want to shutdown your computer (and run the .bat file) click on the shortcut you created. After doing this, edit the .bat file and add this line of code to the end or where needed:



                                                c:windowssystem32shutdown -s -f -t 00


                                                What this does it is



                                                1. Runs the shutdown process

                                                2. Displays a alert

                                                3. Forces all running processes to stop

                                                4. Executes immediately





                                                share|improve this answer













                                                What I can suggest doing is creating a shortcut to the .bat file (for example on your desktop) and a when you want to shutdown your computer (and run the .bat file) click on the shortcut you created. After doing this, edit the .bat file and add this line of code to the end or where needed:



                                                c:windowssystem32shutdown -s -f -t 00


                                                What this does it is



                                                1. Runs the shutdown process

                                                2. Displays a alert

                                                3. Forces all running processes to stop

                                                4. Executes immediately






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Aug 19 '17 at 11:00









                                                Matthew SmithMatthew Smith

                                                254218




                                                254218





















                                                    1














                                                    On Windows 10 Pro, the batch file can be registered; the workaround of registering cmd.exe and specifying the bat file as a param isn't needed. I just did this, registering both a shutdown script and a startup (boot) script, and it worked.






                                                    share|improve this answer



























                                                      1














                                                      On Windows 10 Pro, the batch file can be registered; the workaround of registering cmd.exe and specifying the bat file as a param isn't needed. I just did this, registering both a shutdown script and a startup (boot) script, and it worked.






                                                      share|improve this answer

























                                                        1












                                                        1








                                                        1







                                                        On Windows 10 Pro, the batch file can be registered; the workaround of registering cmd.exe and specifying the bat file as a param isn't needed. I just did this, registering both a shutdown script and a startup (boot) script, and it worked.






                                                        share|improve this answer













                                                        On Windows 10 Pro, the batch file can be registered; the workaround of registering cmd.exe and specifying the bat file as a param isn't needed. I just did this, registering both a shutdown script and a startup (boot) script, and it worked.







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 5 '18 at 3:54









                                                        Wo'O IdeafarmWo'O Ideafarm

                                                        112




                                                        112



























                                                            draft saved

                                                            draft discarded
















































                                                            Thanks for contributing an answer to Stack Overflow!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid


                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.

                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f101647%2fhow-to-schedule-a-task-to-run-when-shutting-down-windows%23new-answer', 'question_page');

                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                                                            Edmonton

                                                            Crossroads (UK TV series)