How To Run A Script or Command At Logoff in Windows 7 & 8


You can use the Task Scheduler to execute a script or command at startup or during the login process but you can’t use it to do the same during the logoff. In order to do so, you will need to go through the local Group Policy Editor, a much more powerful component unique in Windows.

One of the readers left a comment in a post that shows a trick how to make your computer speak out time at every hour asking if he can run this script at logoff. So let’s see how it works.

Prepare a batch file that runs the VBScript

Create a new batch file (.bat file), and add the following line in the file:

cscript %userprofile%\desktop\time.vbs

Assuming that the VBScript that speaks out the time is saved on user’s desktop. If you are interested in this script, you can download it directly from this link (right-click and save as..).

Then, work on the Group Policy Editor

1. Launch Group Policy Editor, by Win+R, typing in “gpedit.msc“, and pressing Enter.

Win+R gpedit.msc  - How To Run A Script or Command At Logoff in Windows 7 & 8
Launch local group policy editor

2. On the left panel, go to User Configuration → Windows Settings → Scripts (Logon/Logoff).

Group Policy Script 600x362 - How To Run A Script or Command At Logoff in Windows 7 & 8

3. Double click Logoff to open up its properties.

4. Click Add button, and Browser… button.

5. In the Browse window, paste in the batch file you created earlier. And then select it, press Open button.

Logoff batch file in logoff script folder 600x355 - How To Run A Script or Command At Logoff in Windows 7 & 8

6. Click OK again in Add a Script dialog box. You will see a Logoff.bat file shown up in Logoff Properties window. Click OK to save the changes.

Group Policy Logoff Properties - How To Run A Script or Command At Logoff in Windows 7 & 8
Group Policy – Logoff Properties

7. Close the Local Group Policy Editor, run the following command in Command Prompt window to update the group policy just to be sure the change takes affect right away.

gpupdate /force

That’s it. Log off your computer and see how it works.

Note that if you are trying to use it in a domain controlled network, you will need to do the same on a domain controller that has Active Directory installed.


  1. Hi, Mr. Chen. I’m glad that you found the time to find out how to make Windows talk during Log off, I’ve been waiting learn how to do that.

    I will try it now and hopefully it will workout fine.

    By the way, my Windows 8 Pro x32-bit still can’t say the time even after I followed your instructions. Maybe its a Windows 8 bug. If I click the VBScript, a male voice reads it aloud but once I created the task in the task scheduler Windows 8 always shows a pop-up asking what application should it use to open the file.

    I choose the wscript.exe as you instructed but my Windows 8 kept asking what app to open the Script Host.

    Anyway, I will try out this trick on my Windows 7 which have been very cooperative in obeying my command to talk. 🙂

    Thank you very much Mr. Chen. Please keep up the great work!

    God bless…

  2. Hello, Mr. Chen! This Windows Log-Off Trick worked flawlessly on my Windows 7 & 8 PC’s!!!

    Now my Windows 7 & 8 PCs can now talk during Log-On and Log-Off!!!

    It’s an awesome trick, Sir!!! Do you have anymore tricks that you can share? Please, share! 🙂

    Thanks again, Sir!!! 🙂

    By the way, do you have a Next of Windows facebook account? So I can get updates on all Next of Windows posts.

  3. Hello, Mr. Chen;

    Firstly, I want to greet you a belated Merry Christmas and

    a Happy New Year in advance. :0)

    I wrote you to ask if it’s possible to make a Windows 7 or 8

    laptop speak a VBScript everytime the battery power gets Low,

    reaches Critical Level and finally, notifies when the Battery

    is Fully Charged.

    I already made the VBScript that speaks/notifies when the

    battery reaches Low Charge, Critical Level and when Fully Charged

    but I don’t know how to make a scheduled task or whatever

    command that is necessary to make Windows read the VBScript.

    Is it possible to make Windows 7 or 8 speak or notify about

    the state of the battery or is it just wishful thinking on

    my part?

    Thanks again for your time Mr. Chen. Enjoy the Holidays!!!

    May God Bless you and your family…


    • I don’t think there is no such trigger based on the battery level. You may need a 3rd party tool that monitors it in real time. Or you may alter the VBScript to read the battery level and speak out if the level reaches low. Schedule it to run every 5 or 10 minutes, or frequently enough to alert you on time.

  4. I have a vbscript that runs a batch file in the background. Now I followed the Process till the last dot but on log off it shows this error.

    Please help!!!

      • yes, i cross-checked it again and again,copied straight from address bar and also manually but the error wont go away…….
        Is it case sensitive as windows might be looking for
        rather than


Please enter your comment!
Please enter your name here