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'.

cutrightjm
  • 4,424

6 Answers6

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.

Tim Brigham
  • 1,152
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).

Oz Edri
  • 435
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

cwin
  • 121
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.

afrazier
  • 23,505
1

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

cutrightjm
  • 4,424
0

Start -> Run and type "gpedit.msc"

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

Layticia
  • 516