8

I have a batch file that makes a directory on H:\ and copies all of my CS work from I:\ to H:\ ( our I:\ drive isn't always available ). Is there a way to possibly run this batch file on logoff so that my files are always updated, WITHOUT using gpedit.msc (access denied)?

I am on a student computer, so most likely installing software won't to practical, but I could try. And help would be much appreciated =)

Or is there a way to run a batch file, and not have the commands run until like.. 8:50 before the bell rings, so I could just put it in the Startup folder and it could run at that time?

I thought about it some more, and the easiest way would be to set a scheduled task at 8:50 for it to run.. but it would still be nice if I knew how to to do in a batch file. I don't have access to the shutdown -l commands, and I don't believe that would help anyways because I want the script to run when I click 'Log Off'.

6 Answers 6

5

This should do the trick. Save as a REG file and import, unless that is blocked as well. This effectively creates a logoff script entry.

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0]
"Script"="H:\your-script-here.bat"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00 ,00,00,00,00,00

Save your script to do the copy under the root of your H: drive.

1
  • 1
    Can I use it if my O.S (Windows 7 Home Premium) doesn't have a pre-installed gpedit.msc? Commented Dec 23, 2014 at 9:52
4

Another similar option to what Tim Brigham already suggested is to save the text below as a .reg file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Logoff\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\Windows\System32\GroupPolicy\User"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"
"PSScriptOrder"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Logoff\0\0]
"Script"="H:\yourScriptFileName.bat"
"Parameters"=""
"IsPowershell"=dword:00000000
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

This is similar to doing it yourself from the Group Policy Editor tool (gpedit.msc).

3
  • 1
    Welcome to Super User! You've got a great answer for a new user, better than a lot of others I've seen. If you need help, be sure to follow the tour and check out the help center. We hope you enjoy participating on Stack Exchange!
    – bwDraco
    Commented Dec 6, 2014 at 3:14
  • @Oz, (or Tim-Brigham), adding a logoff script via a REG IMPORT cmd doesn't seem to work in Windows 10 (Build 10240), even though a REG QUERY shows the exact same data as when I create the logoff script via gpedit.msc. I performed a reboot, but no difference. Any ideas?
    – atreyu
    Commented Aug 15, 2017 at 14:37
  • 1
    Ah...nm. Solved it myself using Regshot to track all changes to the registry before and after using gpedit.msc, and also, crucially, to %WINDIR%\System32\GroupPolicy\User\Scripts\scripts.ini.
    – atreyu
    Commented Aug 15, 2017 at 16:03
2

you can put that line at the end of your batch file

shutdown -l

this will log you off as soon as the script is done

1
  • I know this is a late comment, but I didn't use this command because A) I don't have the access rights and b) I wouldn't want another user in the next class period to use my computer if it were to take longer than usual
    – cutrightjm
    Commented Mar 25, 2012 at 3:53
1

I'm not sure which version of Windows added this program, but you could use the waitfor command to pause a batch file for 3,000 seconds (i.e. 50 minutes), then continue with your copy command.

It's definitely available in Windows 7, almost certainly in Vista, and not in XP. However, it may be available in the Windows 2003 Resource Kit Utilities that are available to download, which will run on XP.

There's probably some batch trickery that's possible to pause a script for a particular amount of time too.

1

I eventually just used Scheduled Tasks and set the batch file to run at 8:50, that should work.

0

Start -> Run and type "gpedit.msc"

Under User Configuration -> Windows Settings -> Scripts (Logon/Logoff) you can add your scripts

2
  • 1
    The OP explicitly stated that access to gpedit.msc was denied.
    – afrazier
    Commented Oct 11, 2011 at 13:37
  • 1
    I upvoted this answer just to make sure that it stays here as a reference. I know it's weird to give an answer which the OP (specifically) doesn't want. But it's good that it's here IMO. Commented Oct 10, 2014 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .