'Omschrijving: Dit vb script roteerd de logfile als hij te groot is geef het volledig path van de logfile op
'              Dit script kan maximaal 1 keer per dag gescheduled worden.

Set args = WScript.Arguments
arg_count = args.Count()
If(args.Count() <> 3) Then
 Wscript.echo "Usage rotate_logfile file_name max_size_mb service_name"
 Wscript.echo "service_name geen betekend dat er geen service gestopped hoeft te worden"
 Wscript.quit()
End If

file_name = args.Item(0)
max_size_mb = cint(args.Item(1))
service_name = args.Item(2)
Dim objShell
set objShell = WScript.CreateObject("WScript.Shell")

set objFSO = createobject("Scripting.FileSystemObject")
If Not objFSO.FileExists(file_name) Then
 wscript.echo "file " & file_name & " does not exists"
 wscript.quit()
End If

set objFile = objFSO.GetFile(file_name)

file_size_mb = cint(objFile.Size / (1024 * 1024))
'wscript.echo "size = " & file_size_mb & " max_size_mb = " & max_size_mb
If( file_size_mb > max_size_mb ) Then
 wscript.echo "rotating logfile " & file_name
 my_date = YEAR(NOW()) & "-" & MONTH(NOW()) & "-" & DAY(NOW())
 If(service_name <> "geen") Then
  wscript.echo "Stopping service " & service_name
  os_cmd = "net stop """ & service_name & """"
'wscript.echo "os_cmd = [" & os_cmd & "]"
  objShell.run(os_cmd)

 End If

 'Moving the file dit kan alleen maar 1 keer per dag
 objFSO.MoveFile file_name, file_name & "." & my_date

 If(service_name <> "geen") Then
  wscript.echo "Starting service " & service_name
  os_cmd = "net start """ & service_name & """"
'wscript.echo "os_cmd = [" & os_cmd & "]"
  objShell.run(os_cmd)

 End If


End If
'wscript.echo "klaar"