VBネタ


「サーバのCドライブが少ないぞ」

o(`ω´*)oプンスカプンスカ!!

といわれて調査したところ、



I I S の ロ グ が 溜 ま り っ 放 し



でした。なんと8GBも...( ´ロ`)てへっ。

ということで削除するVBSを作成することに...

で、出来たのがρ(・д・*)コレ

とりあえず該当サーバのスタートアップに放置

する予定。


Call Main

Sub Main()
'////////////////////////////////////////////////////////////////////////////////
'関数 :IISのログファイルで設定した日付以前のファイルを削除
'引数 :
'戻り値:
'環境 :Windows2000 SP2, IE5.5 SP1, Microsoft Access 2000 SP1
'備考 :IISサーバ上で上記環境がないと使えません
'////////////////////////////////////////////////////////////////////////////////
Const NAME_MACHINE = "localhost" '対象マシン(というかIISマシン上でしか使えない)
Const NAME_IIS_SERVICE = "W3SVC" 'IISサービス
Const DEL_INTERVAL = "m" 'yyyy(年) m(月) d(日) h(時) n(分) s(秒)
Const DEL_INTERVALVALUE = "-1" '← が-1で上がmなら1月前を削除対象とするの意
Dim strProcessName 'As String
Dim blnCheck 'As Boolean
Dim objIISAdmin 'As Variant
Dim strIISLogPath 'As String
Dim fsoSys 'As New Scripting.FileSystemObject
Dim appAccess 'As New Access.Application
Dim varFoundFile 'As Variant
Dim i 'As Integer
Dim fleTemp 'As Scripting.File
Dim wshShell 'As New IWshRuntimeLibrary.wshShell

' On Error Resume Next

blnCheck = False

'--On VB Script--
Set appAccess = CreateObject("Access.Application")
Set fsoSys = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

'IISAdminオブジェクトの取得
If Not blnCheck Then
strProcessName = "GetObject = IIS://" & NAME_MACHINE & "/" & NAME_IIS_SERVICE
Set objIISAdmin = GetObject("IIS://" & NAME_MACHINE & "/" & NAME_IIS_SERVICE)
If Not IsObject(objIISAdmin) Then
blnCheck = True
End If
End If

'IISログディレクトリを取得し実パスへ変換
If Not blnCheck Then
strIISLogPath = objIISAdmin.LogfileDirectory
strProcessName = "ConvertLogDir = " & strIISLogPath

strIISLogPath = wshShell.ExpandEnvironmentStrings(strIISLogPath)
End If

'IISログディレクトリチェック
If Not blnCheck Then
strProcessName = "CheckLogPath"
If Not fsoSys.FolderExists(strIISLogPath) Then
blnCheck = True
End If
End If

'ログファイルの検索と日付比較と削除
If Not blnCheck Then
strProcessName = "SearchLogFile = " & strIISLogPath

With appAccess.FileSearch
.NewSearch
.LookIn = strIISLogPath
.SearchSubFolders = True
.FileName = "*.log"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Set fleTemp = fsoSys.GetFile(.FoundFiles(i))
If DateAdd(DEL_INTERVAL, CInt(DEL_INTERVALVALUE), Now()) >= fleTemp.DateLastModified Then
fleTemp.Delete True
End If
Next
End If
End With
End If

If blnCheck Then
MsgBox strProcessName, , "IIS W3SVC Log Delter"
End If

Set objIISAdmin = Nothing
Set appAccess = Nothing
Set fsoSys = Nothing
Set wshShell = Nothing
End Sub