Link to home
Start Free TrialLog in
Avatar of ClaudeWalker
ClaudeWalker

asked on

Execute Script On Shutdown BEFORE network connections close

I have a script I want to run at shutdown that copies a select few (important) employee's .pst(s) to a mapped "drive" on the network.  

This is being in lieu of an exchange server to have a tape backup of their very important e-mail.  

The problem is when I run a script from the group policy "on shutdown" the network connections close before scripts are run.

Any ideas on how to run this script on a shutdown event but before network connections close?
ASKER CERTIFIED SOLUTION
Avatar of John
John
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ClaudeWalker
ClaudeWalker

ASKER

PERFECT!!!!

Thank you very much!

NET USE Q: \\PHDATA\Josephk

del "Q:\Backup\TEAC\*.*" /q

del "Q:\Backup\My Documents\*.*" /q

del "Q:\Backup\OutlookBackup\*.*" /q

del "Q:\Backup\TEAC\*.*" /q

Copy "C:\Documents and Settings\josephk.PHI\My Documents\*.*" "Q:\Backup\My Documents\"

Copy "C:\Documents and Settings\josephk.PHI\Local Settings\Application Data\Microsoft\Outlook\*.*" "Q:\Backup\OutlookBackup\"

Copy "C:\Documents and Settings\josephk.PHI\Desktop\*.*" "Q:\Backup\Desktop\"

Copy "C:\TEAC\*.*" "Q:\Backup\TEAC\"

net use Q: /delete /YES
Uh Oh.

I spoke too soon.  When running the script by itself it works fine.  But running on shutdown it won't connect the drive after the network connections are closed.

Any ideas?  Is this because it disconnects from the domain?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It works!  Is this a global policy or something that would have to be set up per user (logon)?

The running at logoff worked the only problem now is it won't copy all contents of the folder (directories).

Copy "C:\Documents and Settings\josephk.PHI\My Documents\*.*" "Q:\Backup\My Documents\"

Any ideas?
If the script works (I use this kind of script frequently), then the issue of copying contents is probably a permissions issue within My Documents.  Also, you said you were copying .PST files (Email) and Outlook has to be closed completely for this to work.

Take subsets of files and test in pieces to see which files are not copying. It will have something to do with the above. ... Thinkpads_User
Another (different and alternative) way to approach this is to make your own shutdown button. Make a batch file with your scripts that assumes the user has not shutdown. Add a shutdown command as the last line. Put a shortcut to the batch file on the user's Desktop. Ask the users to activate the desktop command to shutdown rather than use the Start button. Once they realize it is for their own safety, they will likely comply. My clients would. ... Thinkpads_User
It was basically all the directories.  The final and fully functional solution is to run the script at logoff.  This way we are not disconnected from the Domain.  Then I used xcopy which is more robust than copy and was able to copy subdirectories and all files.

This connects the network drive, deletes the network backup directories w/o prompt, then copies files w/o overwrite prompt and subdirectories, to be safe I disconnect the network drive.

Thanks a bunch this is exactly what I was looking for.


NET USE Q: \\PHDATA\Josephk

del "Q:\Backup\My Documents\*.*" /q

del "Q:\Backup\OutlookBackup\*.*" /q

del "Q:\Backup\Desktop\*.*" /q

xCopy "C:\Documents and Settings\josephk.PHI\My Documents\*.*" "Q:\Backup\My Documents\" /q /s

xCopy "C:\Documents and Settings\josephk.PHI\Local Settings\Application Data\Microsoft\Outlook\*.*" "Q:\Backup\OutlookBackup\" /q /s

xCopy "C:\Documents and Settings\josephk.PHI\Desktop\*.*" "Q:\Backup\Desktop\" /q /s

net use Q: /delete /YES

Open in new window

Thanks a bunch
Thanks and good luck. ... Thinkpads_User