run a batch file at logout?

not sure if this is poss but here goes:

I would like a batch file to run when the user logs out of XP or selects to Restart/Shut Down.
it's a very quick batch to run which copies the contents of a folder to a logfile on a fileshare - i have this running at startup but would like it to run at logout too, to identify a problem we're having with locally stored files disappearing.

Anyone?
LVL 18
Sham HaqueSenior SAP CRM ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LongbowCommented:
Start / Run / gpedit.msc / OK
Go to Computer Configuration / Windows Settings / Scripts (Startup / Shutdown)
Double clic Shutdown on the right pane and add your script.
I am not sure it will run when the user log off
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LongbowCommented:
You can synchronize files at log off :
%windir%\Help\mobsync.chm
0
Sham HaqueSenior SAP CRM ConsultantAuthor Commented:
thanks for quick responses but neither solution will work, as the users' PCs are locked down for setting file synchronization and group policy
(perhaps I should've said b4 :-/ )

i guess what I was looking for was a folder or a reg entry to trigger a program at logout / shutdown time.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

LongbowCommented:
Copy your batch to one or more of these directories :
C:\WINDOWS\system32\GroupPolicy\User\Scripts\Logoff
C:\WINDOWS\system32\GroupPolicy\User\Scripts\Logon
C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup
C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Shutdown
If you copy it elsewhere you need to give the full path. See registry example.

Check next key for Startup / Shutdown :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts

Check next key for Logon / Logoff :
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts

I will do the job on one computer with same OS and export one of those keys.
Then apply in the user's registry.

Here an example of the registry for Logon & Logoff.
Compare with yours and modify :

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff]

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

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

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon]


Here an example of the registry for Startup and Shutdown.
Compare with yours and modify :

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\Machine"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0]
"Script"="run2.bat"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\1]
"Script"="run3.bat"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\Machine"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0\0]
"Script"="C:\\LDClient\\LDISCN32.EXE"
"Parameters"="/NTT=Nautilus:5007 /S=\"Nautilus\" /I=\\\\Nautilus\\LDLOGON /NOUI /W=10"
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

0
LongbowCommented:
Check these keys as well.
Note the logoff script with the user's SID in HKLM.
You better have to unlock this computer ?

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\Scripts

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts

HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-507921405-1563985344-725345543-313210\Scripts
0
Sham HaqueSenior SAP CRM ConsultantAuthor Commented:
great answer longbow - but been unable to try this out, as it looks like our Desktop Mgrs have done a pretty good job:

1) No access to create New Folder in group policy (this is currently empty)
2) this area of registry is out of bounds

it looks like we cannot do it with user permissions as set - unless anyone has any more ideas...I'll give it a few days but it looks like Longbow gets the points (i'll try it out on a machine with admin rights.....)

Shammy
0
TheDefiantCommented:
It is possible you could still have a batch file run at startup/shutdown or logon/logoff.  If you put the batch file in the appropriate folder, as mentioned by Longbow, you also need to edit a hidden scripts.ini file in the scripts folder (previous folder from the startup/shutdown, logon/logoff folders).  The layout of this file, for shutdown, is as follows:

[Shutdown]
0Program=myBatchFile.bat
0Parameters=/doThis

1Program=LogFiles.cmd
1Parameters=/MyDocs /TempFolders /etc

(Verify the "Program" line, first.  I think it's Program, but it might be something else, like Command.)
0
Sham HaqueSenior SAP CRM ConsultantAuthor Commented:
the gpedit did work perfectly on a machine with admin rights, so this does answer my question. (there are entries for logoff and shutdown there)

i'll just have to go and get pally with our Desktop Management guys.....

Shammy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.