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

Clean Badmail folder exchange 2000 Server 2003 vbscript

Status
Not open for further replies.

d1novak

Instructor
Jul 21, 2003
27
US
I have a script that stops the smtp service for 10 secs moves the BadMail folder to c:\Program files\crap\"hour_old".
restarts the service and on a certain hour at night deletes and recreates the c:\program files\crap folder.

the entire script works except deleting the crap folder. no matter how I adjust the permissions, I get the error permission denied. The script can move the Badmail folder and create the new crap folder just not delete the old one.

Any help is greatly appreciated
Thank You

strComputer = "."
strService = "smtpsvc"
Set oService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Service.Name='" & strService & "'")
oService.StopService
On Error Resume Next

wscript.sleep(10000)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
For Each objItem in colItems

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\Program Files\BadMail" , "C:\Program Files\crap\" & objItem.Hour & "_old"
Set objFolder = objFSO.CreateFolder("C:\Program Files\BadMail")
Next

oService.StartService

If objFSO.FolderExists("C:\Program Files\crap\8_old") Then
objFSO.DeleteFolder("C:\Program Files\crap")
objFSO.CreateFolder("C:\Program Files\crap")
End If
 
Looks like your problem is here:

If objFSO.FolderExists("C:\Program Files\crap\8_old") Then

Just curious, why are you making this "crap folder"

Here is the script I use to clean out items in the badmail folder based on file age. I just schedule this to run in the Control Panel Scheduled Tasks.

This also cleans up the Quarantine folders made by our Spam filter.

if you want to delete files sooner than 30 days just change the number to how long you want to keep files.

Code:
'==========================================================================
'
' VBScript Source File -- 
'
' NAME: CleanBadMail.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]	
' Copywrite (c) 2003 All rights reserved
' DATE  : 09/10/2003
'
' COMMENT: 
'
' This script will list all filtered and quarantined SPAM mail, check that 
' the files are more than 30 days old and then delete them.
' This file is to be scheduled to run each day.
'=====================================

Path1 = "E:\Program Files\Exchsrvr\Mailroot\vsi 1\BadMail"
Path2 = "E:\Program Files\Trend\SMCF\Quarantine"


Dim fso 
Dim oFolder
Dim oFile
Dim oSubFolder

  Set fso = createobject("Scripting.FileSystemObject")
  
   Set oFolder = fso.GetFolder(Path1)
  
   For Each oFile In oFolder.files

'start debug
'msgbox oFile.name
'End debug

   	If DateDiff("d", oFile.DateCreated,Now) > 30 Then
      
           oFile.Delete True
      
      	End If
  Next


Set oFolder = fso.GetFolder(Path2)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
   	If DateDiff("d", oSubFolder.DateCreated,Now) > 30 Then
		fso.DeleteFolder(oSubFolder)
		
	End If

Next

Set oSubFolder = Nothing
Set oFolder = Nothing
Set fso = Nothing

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top