달력

1

« 2015/1 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

' Event Log is Full, Export and Clear (이벤트 기록: ID 9002)

' Event Log: Operations Manager, Event Source: Health Service Script


CONST EventID = 9002

CONST USAGE_LIMIT = 95

CONST MAX_FILES = 5


ScriptName = ""


Set oArgs = WScript.Arguments

TargetBackupPath = ""

If oArgs.Count > 1 Then

  For i = 0 to oArgs.Count-1

    TargetBackupPath = TargetBackupPath & oArgs(i) & " "

  Next

  TargetBackupPath = Trim(TargetBackupPath)

Else

  TargetBackupPath = Trim(oArgs(0))

End If


CONST INFORMATION = 0

CONST ERROR = 1

CONST WARNING = 2


Set oFSO = CreateObject("Scripting.FileSystemObject")


On Error Resume Next


Set objFolder = oFSO.GetFolder(TargetBackupPath)

If Err.Number <> 0 Then

  Set objFolder = NOTHING

  Set oFSO = NOTHING

  WScript.Quit

Else

  Set wshNetwork = WScript.CreateObject( "WScript.Network" )

  strComputerName = Ucase(wshNetwork.ComputerName)

  Set wshNetwork = NOTHING

  

  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")

  Set colItems = objWMIService.ExecQuery ("Select * from Win32_NTEventLogFile Where LogfileName = 'Application' OR LogfileName = 'System'")

  

  For Each Item in colItems

    tmpUsage = Round((Item.FileSize/Item.MaxFileSize)*100,0)

    tmpLogName = Item.LogfileName

    tmpLogExt = Item.Extension

    

    If tmpUsage > USAGE_LIMIT Then

      Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile Where LogFileName='"&tmpLogName&"'")

      For Each objLogfile in colLogFiles

        PreDateTime = cDate(Now)

        PreDateTime = Year(PreDateTime)&Right("0"&Month(PreDateTime),2)&Right("0"&Day(PreDateTime),2)&Right("0"&Hour(PreDateTime),2)&Right("0"&Minute(PreDateTime),2)

        objLogFile.BackupEventLog(TargetBackupPath & "\" & strComputerName & "_" & tmpLogName & "_" & PreDateTime & "." & tmpLogExt)

        objLogFile.ClearEventLog()

        strMessage = tmpLogName & " event log has been cleared. Export path: " & TargetBackupPath & "\" & strComputerName & "_" & tmpLogName & "_" & PreDateTime & "." & tmpLogExt

        Set oAPI = CreateObject("MOM.ScriptAPI")

        Call oAPI.LogScriptEvent(ScriptName, EventID, INFORMATION, strMessage)

        Set oAPI = NOTHING

      Next

      Set colLogFiles = NOTHING

    End If

    

  Next

  Set colItems = NOTHING

  Set objWMIService = NOTHING

  Set colFiles = objFolder.Files

  

  Do While colFiles.Count > MAX_FILES

    Set colFiles = objFolder.Files

    dtmOldestDate = Now

    For Each objFile in colFiles

      If objFile.DateCreated < dtmOldestDate Then

        dtmOldestDate = objFile.DateCreated

        strOldestFile = objFile.Path

      End If

    Next

    oFSO.DeleteFile(strOldestFile)

  Loop

  Set colFiles = NOTHING

  objFolder = NOTHING

  Set oFSO = NOTHING

End If


:
Posted by 커널64

Set oArgs = WScript.Arguments


If oArgs.Count = 0 Then

  WScript.Echo "Argument was not provided."

  WScript.Quit

End If


strDirectory = ""

If oArgs.Count > 1 Then

  For i = 0 to oArgs.Count - 1

    strDirectory = strDirectory & oArgs(i) & " "

  Next

Else

  strDirectory = oArgs(0)

End If


Set oFSO = CreateObject("Scripting.FileSystemObject") 


Set Folder = oFSO.GetFolder(strDirectory)

Set Files = Folder.Files

NumOfFiles = Files.Count


Set Files = NOTHING

Set Folder = NOTHING

Set oFSO = NOTHING


WScript.Echo strDirectory & vbCRLF

WScript.Echo "# of Files: " & NumOfFiles





:
Posted by 커널64
2015. 1. 13. 21:47

VBS - 파일 수정 날짜 쿼리 (매개 변수) Etc.2015. 1. 13. 21:47

Set oArgs = WScript.Arguments


If oArgs.Count = 0 Then

  WScript.Echo "Argument was not provided."

  WScript.Quit

End If


strFilePath = ""

If oArgs.Count > 1 Then

  For i = 0 to oArgs.Count - 1

    strFilePath = strFilePath & oArgs(i) & " "

  Next

Else

  strFilePath = oArgs(0)

End If


Set sFSO = CreateObject("Scripting.FileSystemObject")

Set f = sFSO.GetFile(strFilePath)

FileModifiedDate = cDate(f.DateLastModified)


Set f = NOTHING

Set sFSO = NOTHING


WScript.Echo strFilePath & vbCRLF

WScript.Echo "Modified Date: " & FileModifiedDate



:
Posted by 커널64

On Error Resume Next


Set objFwMgr = CreateObject("HNetCfg.FwMgr")

Set objProfile = objFwMgr.LocalPolicy.CurrentProfile


If Err <> 0 Then

  WScript.Echo "Windows Firewall Service is not running."

  WScript.Quit

End If


If objProfile.FirewallEnabled = True Then

  WScript.Echo "Windows Firewall is enabled."

Else

  WScript.Echo "Windows Firewall is disabled."

End If




:
Posted by 커널64

Const DOMAIN_PROFILE = 1

Const PRIVATE_PROFILE = 2

Const PUBLIC_PROFILE = 4


Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")


CurrentProfile = fwPolicy2.CurrentProfileTypes

Select Case CurrentProfile

  Case DOMAIN_PROFILE

    WScript.Echo "현재 프로필: 도메인"

  Case PRIVATE_PROFILE

    WScript.Echo "현재 프로필: 개인"

  Case PUBLIC_PROFILE

    WScript.Echo "현재 프로필: 공용"

End Select


WScript.Echo "==================="


If fwPolicy2.FirewallEnabled(DOMAIN_PROFILE) = TRUE Then

  WScript.Echo "도메인 프로필: 사용"

Else

  WScript.Echo "도메인 프로필: 사용 안 함"

End If


If fwPolicy2.FirewallEnabled(PRIVATE_PROFILE) = TRUE Then

  WScript.Echo "개인 프로필: 사용"

Else

  WScript.Echo "개인 프로필: 사용 안 함"

End If


If fwPolicy2.FirewallEnabled(PUBLIC_PROFILE) = TRUE Then

  WScript.Echo "공용 프로필: 사용"

Else

  WScript.Echo "공용 프로필: 사용 안 함"

End If


Set fwPolicy2 = NOTHING




:
Posted by 커널64
2015. 1. 8. 11:07

VBS - Windows 업데이트 설정 쿼리 Etc.2015. 1. 8. 11:07

Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")

Set objSettings = objAutoUpdate.Settings


WUSetting = objSettings.NotificationLevel


Set objSettings = NOTHING

Set objAutoUpdate = NOTHING


Select Case WUSetting

  Case 1

    strSetting = "업데이트를 확인하지 않음"

    strState = "GOOD"

  Case 2

    strSetting = "업데이트를 확인하지만 다운로드 및 설치 여부는 직접 선택"

    strState = "GOOD"

  Case 3

    strSetting = "업데이트를 다운로드하지만 설치 여부는 직접 선택"

    strState = "GOOD"

  Case 4

    strSetting = "업데이트 자동 설치"

    strState = "BAD"

End Select



WScript.Echo strSetting

WScript.Echo strState





:
Posted by 커널64