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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shutdown Maintenance

Status
Not open for further replies.

scriptomatic

Technical User
Sep 21, 2006
3
US
I'm looking for a way to run chkdsk and defrag on the Windows 2000 and WinXP workstations in my Windows 2003 domain.

I'd like to run them as either Logoff or Shutdown scripts in Active Directory. If it's a logoff script, a shutdown command would be included in the script.

And what I'd really like is to run the chkdsk command only a couple days a week and the defrag would run at logoff or shutdown only if that occured after 3pm in case someone reboots earlier in the day.

I previously ran a chkdsk batch file as a scheduled task, but that requires a user with a consistent password and defrag won't work without admin privileges (and defrag.exe won't work at all in W2k).

I believe no elevated privileges are required if the script runs from AD.

Here's my chkdsk.bat file:

-----------------------------------------------------------
@echo off
echo %date% %time% Start of chkdsk operation >> c:\chkdsk.log
echo Y|%SystemRoot%\system32\chkdsk.exe /f c: 1>>c:\chkdsk.log 2>&1
echo %date% %time% End of chkdsk operation >> c:\chkdsk.log
echo. ----------------------- >> c:\chkdsk.log

-----------------------------------------------------------

I'm not sure if it' possible to simply call this from a VBScript, and I'm not sure how to test for times and dates.

I realize I have a lot here, so I'll say thanks in advance for any pieces anyone has to offer -- or any places you can point me to.
 
For Windows XP you can schedule the defrag to run when you want. For WIndows 2000 you will want to get a copy of AutoDefrag which will allow you to schedule defrag on Windows 2000.

For your chkdsk the code is somehting like this:

Code:
Set WshShell = CreateObject("wscript.Shell")
WshShell.Run ("CMD.EXE /C Chkdsk.exe C: /F")


Checking the time is easy enough, here is an example:

Code:
If Hour(Time) => 15 Then
	WScript.Echo "After 3:00"
End If


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top