?
Solved

run a batch file at logout?

Posted on 2004-11-05
8
Medium Priority
?
30,179 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:Sham Haque
  • 4
  • 3
8 Comments
 
LVL 10

Accepted Solution

by:
Longbow earned 500 total points
ID: 12502681
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
 
LVL 10

Expert Comment

by:Longbow
ID: 12502714
You can synchronize files at log off :
%windir%\Help\mobsync.chm
0
 
LVL 18

Author Comment

by:Sham Haque
ID: 12502826
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:Longbow
ID: 12502998
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
 
LVL 10

Expert Comment

by:Longbow
ID: 12503100
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
 
LVL 18

Author Comment

by:Sham Haque
ID: 12503132
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
 
LVL 1

Expert Comment

by:TheDefiant
ID: 12504510
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
 
LVL 18

Author Comment

by:Sham Haque
ID: 12522198
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question