?
Solved

Execute Script On Shutdown BEFORE network connections close

Posted on 2009-12-17
10
Medium Priority
?
1,694 Views
Last Modified: 2012-05-08
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?
0
Comment
Question by:ClaudeWalker
  • 5
  • 4
10 Comments
 
LVL 99

Accepted Solution

by:
John Hurst earned 1000 total points
ID: 26074319
The way that policy works (I use it to disconnect drives amongst other things), I don't think so.

So if I were faced with this, I think what I would do is put a line in the script in front of the copy to map the specific drive, and then a line after the copy to disconnect the same drive.
... Thinkpads_User
0
 

Author Comment

by:ClaudeWalker
ID: 26074515
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
0
 

Author Comment

by:ClaudeWalker
ID: 26074685
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?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 5

Assisted Solution

by:micalkin
micalkin earned 1000 total points
ID: 26074812
how about running the script at logoff instead of at shutdown?
0
 

Author Comment

by:ClaudeWalker
ID: 26075110
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?
0
 
LVL 99

Expert Comment

by:John Hurst
ID: 26075614
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
0
 
LVL 99

Expert Comment

by:John Hurst
ID: 26075907
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
0
 

Author Comment

by:ClaudeWalker
ID: 26075986
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

0
 

Author Closing Comment

by:ClaudeWalker
ID: 31667464
Thanks a bunch
0
 
LVL 99

Expert Comment

by:John Hurst
ID: 26076009
Thanks and good luck. ... Thinkpads_User
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

829 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