How to run a command when Windows is closing?

Preben Reventlow 0 Reputation points
2024-10-07T17:23:24.36+00:00

How to trigger a command when the user select to close windows 11?

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-10-08T01:31:12.2266667+00:00

    Hi,

    You can create a group policy like Darrell mentioned above or use the Task Scheduler to create a task to run a specific command.

    1. Open Task Scheduler: You can do this by typing "Task Scheduler" in the Windows search bar and selecting it from the results.
    2. Create a New Task: In the Task Scheduler, click on "Create Task" in the Actions pane on the right.
    3. Name Your Task: Give your task a name and description that clearly indicates its purpose.
    4. Set the Trigger: Go to the "Triggers" tab and click "New". In the "Begin the task" dropdown, select "On an event". Then, set the "Log" to "System", "Source" to "User32", and "Event ID" to "1074". This event ID corresponds to system shutdown.
    5. Set the Action: Go to the "Actions" tab and click "New". In the "Action" dropdown, select "Start a program". Then, browse to the script or program you want to run when the system is shutting down.
    6. Configure Conditions and Settings: If needed, you can configure additional conditions and settings for your task under the "Conditions" and "Settings" tabs.
    7. Save the Task: Click "OK" to save your task.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.
    0 comments No comments

  2. Darrell Gorter 2,731 Reputation points
    2024-10-07T20:28:55.36+00:00

    Hello,

    there is a group policy for running shutdown scripts

    User's image

    Try this and see if it works for

    Darrell


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.