'PRECONDITION
'Create log files under e.g. c:\cleanup.log and c:\defrag.log
'*************************************************
'Script Name:Script Cleanup.vbs
'Author: Kenneth Værsland
'Created: 25/11/2008
'Description:This script schedules the execution of the Cleanup utility
'at 20:00 on the first day of each month. This utility removes unnecessary
'files from the local disk drive.
'*************************************************
'Initialization section
Option Explicit
Dim WshShl, FsoObject, LogFile
Set WshShl = WScript.createObject("WScript.Shell")
Set WshShl = WScript.CreateObject("Scripting.fileSystemObject")
'Main Processing Section
CheckForCleanupLog()
PerformCleanup()
WScript.Quit()
'Procedure Section
'This procedure enures that a cleanup.log file exists
Sub CheckForCleanupLog()
If (FsoObject.FileExists ("C:\cleanup.log")) Then
Set LogFile = FsoObject.openTextFile("C:\Cleanup.log", 8)
LogFile.WriteLine "Cleanup process started on" & Date & " at " & Time
Else
Set LogFile = FsoObject.OpenTextFile("C:\cleanup.log", 2 ,"True")
LogFile.WriteLine "Cleanup process started on" & Date & " at " & Time
End If
End Sub
'This procedure execute the Cleanup utility
Sub PerformCleanup()
WshShl.Run "C:\windows\System32\cleanmgr /sagerun:1"
End Sub '*********************************************************************
'*************************************************
'Script Name:Script defrag.vbs
'Author: Kenneth Værsland
'Created: 25/11/2008
'Description:This script schedules the execution of the Windows defrag.exe
'at 22:00 on the first day of each month. This Utility defrags disk drivers
'*************************************************
'Initialization section
Dim WshShl, FsoObject, LogFile
Set WshShl = Wscript.CreateObject ("WScript.Shell")
Set FsoObject = Wscript.CreateObject("Scripting.FileSystemObject")
'Main Processing Section
CheckForDefragLog()
PerformDefrag()
Wscript.Quit()
'Procedure Section
'This procedure enures that a defrag.log exists
Sub CheckForDefragLog()
if (FsoObject.FileExists("c:\defrag.log")) Then
Set LogFile = FsoObject.OpenTextFile("c:\defrag.log", 8)
Logfile.Writeline "Defrag.exe Started on" & Date & " at " & time
Else
Set LogFile = FsoObject.OpenTextfile("c:\defrag.log", 2,"True")
LogFile.Writeline "Defrag.exe Started on" & DATE & " at " & Time
END IF
end sub
'This procedure executes the defrag.exe cmd line utility
Sub PerformDefrag()
WshShl.Run "%SystemRoot%\System32\defrag.exe c: /f"
End Sub
'********************************************************************
'WORKING WITH THE SCHEDULED TASK WIZARD
'1.)Click start /all programs/accessories/system tools and then scheduled Task Wizard. The scheduled Tasks folder opens
'2.)Double -click on the add scheduled task icon. The scheduled task wizard appears. Click Next
'3.)A list of Windows apps is displayed. Click browse , locate your script, and click on Open.
'4.)Type a descriptive name ofr the scheduled task, select a time frame for its execution and click next.
'5.) Specify addtional execution time frame options, and click next.
'6.) Next, you will be prompted to specify an optional user name and password. Click next
'
'
'
'
'*************************************************
'Script Name:Schedule.vbs
'Author: Kenneth Værsland
'Created: 25/11/2008
'Description:This script schedules the execution of the Windows
'Cleanup.exe utility
'*************************************************
'Initialization section
Option Explicit
Dim WshShl
'Instantiate the WshShell object
Set WshShl = Wscript.CreateObject("WScript.Shell")
'Main Processing Section
ScheduleScripts()
WScript.Quit()
'Procedure Section
'This procedure schules the execution of other VBScripts
Sub ScheduleScript()
'Use the WshShell object's RUN() method to run the at cmd
WshShl.Run "at 20:00 /every:1 c:\cleanup.vbs"
WshShl.Run "at 22:00 /every:1 c:\defrag.vbs"
End Sub
EDIT: EBGREEN - Indentation and code tags are your friends.
<message edited by ebgreen on Tuesday, November 25, 2008 3:53 AM>