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

Event log script issue

Status
Not open for further replies.
Sep 7, 2009
29
US
Hello, I'm trying create an event log script that will let me set the maximum log size. Here is what I have so far and I'm getting errors when I try to run it. Please assist

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:"
& "{impersonationLevel=impersonate,(Security)}!\\" &
strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery
("Select * from Win32_NTEventLogFile")
For each objLogfile in colLogFiles
strLogFileName = objLogfile.Name
Set wmiSWbemObject = GetObject
("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:"
& "Win32_NTEventlogFile.Name=''" & strLogFileName & "''")
wmiSWbemObject.MaxFileSize = 2500000000
wmiSWbemObject.OverwriteOutdated = 14
wmiSWbemObject.Put
Next
 
I'm getting errors
Which errors and where ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Replace this:
Set objWMIService = GetObject("winmgmts:"
& "{impersonationLevel=impersonate,(Security)}!\\" &
with this:
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,(Security)}!\\" &

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You need to use a continuation character, which is an underscore, to break one line of code into multiple lines. Also, you cannot have a space or line break etc between the GetObject and the ("....")
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate,(Security)}!\\" & _ 
   strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
   ("Select * from Win32_NTEventLogFile")

For each objLogfile in colLogFiles
   strLogFileName = objLogfile.Name
   Set wmiSWbemObject = GetObject_
      ("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:" _
      & "Win32_NTEventlogFile.Name=''" & strLogFileName & "''")
   wmiSWbemObject.MaxFileSize = 2500000000
   wmiSWbemObject.OverwriteOutdated = 14
   wmiSWbemObject.Put
Next
 
Sorry, this is block of code I meant to paste:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate,(Security)}!\\" & _ 
   strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile")

For each objLogfile in colLogFiles
   strLogFileName = objLogfile.Name
   Set wmiSWbemObject = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:" _
      & "Win32_NTEventlogFile.Name=''" & strLogFileName & "''")
   wmiSWbemObject.MaxFileSize = 2500000000
   wmiSWbemObject.OverwriteOutdated = 14
   wmiSWbemObject.Put
Next
 
Ok I did that. Now i get this error: Line 2 Char 44 Error: syntax error Code: 800A03EA
 
Hello guitarzan I recieved this error when i run your script. Windows Script Host Line: 9 Char: 4 Error: 0x80041021 Code 80041021
 
You have two single-quotes around

Code:
Win32_NTEventlogFile.Name=[highlight]'[/highlight]" & strLogFileName & "[highlight]'[/highlight]"
 
I removed the two single quotes. Now this code error comes up Line 13 Char 4 Error Object doesn't support this property or method: 'wmiSWbemObject.Put' Code: 800A01B6
Code:
 strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate,(Security)}!\\" & _ 
   strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile")

For each objLogfile in colLogFiles
   strLogFileName = objLogfile.Name
   Set wmiSWbemObject = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:" _
      & "Win32_NTEventlogFile.Name='" & strLogFileName & "'")
   wmiSWbemObject.MaxFileSize = 2500000000
   wmiSWbemObject.OverwriteOutdated = 14
   wmiSWbemObject.Put
Next
 
Google indicates that the proper line of code is
Code:
wmiSWbemObject.Put_

See if that works. If so, this would be an example where the underscore is NOT a continuation character :)
 
an example where the underscore is NOT a continuation character
The continuation characters are SPACE followed by underscore at end of line.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV said:
an example where the underscore is NOT a continuation character
The continuation characters are SPACE followed by underscore at end of line.
Code:
wscript.echo "no. not quite as si" &_
   "mple as that :)"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top