Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run defrag.exe on shutdown by script?

Status
Not open for further replies.

Turb

Technical User
Feb 11, 2003
154
US
All,
I am a complete novice to VB scripting. Well, maybe not a complete novice, but I'm not sure if MS Access counts. [bigsmile]
I need a shutdown script for use with a GPO that will , on restricted user shutdown of the PC, run WinXP's defrag.exe as the local admin and then proceed to shutdown the computer.
Please help!


Ind. Engineering Tech.
 
I am afraid you will not be able to do this. The shutdown process will shutdown the defrag before it completes.

You are better off just scheduling the defrag. If you are on Windows 2000 you can schedule this with the use of AutoDefrag. On Windows 2003 you can schedule it via the control panel scheduled tasks.

I hope you find this post helpful.

Regards,

Mark
 
The problem here is that ShutDown.exe will time out everything and execute the shutdown.

I hope you find this post helpful.

Regards,

Mark
 
marcdmac,
Although this solution isn't VB, perhaps someone could code it.
I've found that this batch file will work to defragment the HD on shutdown, if placed as a shutdown script using Group Policy.
It has the added benefit of keeping open a DOS command window with a descriptive title so the user can see what is happening
(and pressing "CTRL-C" will allow cancellation of the script).
I must admit though, that I haven't figured out a way around the "Restricted User" angle yet.
Perhaps "calling" this batch file from a "runas" batch file would work. Hmmm...
Anyway, here's the code:
Code:
@ECHO OFF
START "Defragmenting Hard Drive Before Shutting Down" /WAIT defrag.exe c: -f
Maybe it will help some others looking to do the same thing.
I'll post the entire code when I find a way to run this under "Restricted User".
Turb

Ind. Engineering Tech.
 
Well now,
It seems that I had undo worry over the "Restricted User" account.
Evidently because the batch file is being called from GP as a shutdwon script, it runs no matter who was logged on.
Sweet! Problem solved!
Thanks to all!
Turb

Ind. Engineering Tech.
 
Very nice, I did not think it would work.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top