Help need in modifying the script

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

Hello All,

I am a newbie in vbscripting.

I am in testing field using QTP. The primary responsibility is if any upgrades in any application(like microsoft, windows, or any dotcom application is to be tested before launching on users pc i need to ensure that the application is working in testing environment. As the part of the process, one of the steps is to check the event viewer if the applicatin is loaded after successful build of the machine. I go to MSI installer under application in Event viewer and check physically one by one for the application is build on testing environment by looking for event loaded successfully. I am trying to get the information in the form of log file but i am getting for all the users on the machine where i am testing. I would like to generate the report based on user and would like to know how i can check for application # i am looking for.

Thanks for your help in advance.
On Error Resume NextDim strComputer, debug, path Dim objWMIServiceDim propValueDim objItemDim SWBemlocatorDim UserNameDim PasswordDim colItemsDim objFSODim objTextStream
Const fsoForAppend = 8
debug = False
strComputer = "."UserName = ""Password = ""strFilePath = "C:logsWelcome.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")Path = objFSO.GetAbsolutePathName(strFilePath)If objFSO.FileExists(Path) Then' Cretae the text file Set objTextStream = objFSO.OpenTextFile(strFilePath, fsoForAppend)Else 'Open the text file Set objTextStream = objFSO.CreateTextFile(strFilePath, True)
End If


Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")Set objWMIService = SWBemlocator.ConnectServer(strComputer,"rootCIMV2",UserName,Password)Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where Logfile = 'Application' and EventCode = '11728' and user='OFFICEABCUser'",,48)For Each objItem in colItems If objItem.EventType = 3 then objTextStream.WriteLine("Category: " & objItem.Category _ & " string " & objItem.CategoryString) objTextStream.WriteLine("ComputerName: " & objItem.ComputerName) objTextStream.WriteLine("Logfile: " & objItem.Logfile _ & " source " & objItem.SourceName) objTextStream.WriteLine("EventCode: " & objItem.EventCode) objTextStream.WriteLine("EventType: " & objItem.EventType) objTextStream.WriteLine("Type: " & objItem.Type) objTextStream.WriteLine("User: " & objItem.User) objTextStream.WriteLine("Message: " & objItem.Message) objTextStream.WriteLine (" ")
If Debug = True Then WScript.Echo "Category: " & objItem.Category WScript.Echo "CategoryString: " & objItem.CategoryString WScript.Echo "ComputerName: " & objItem.ComputerName for each propValue in objItem.Data WScript.Echo "Data: " & propValue next WScript.Echo "EventCode: " & objItem.EventCode WScript.Echo "EventIdentifier: " & objItem.EventIdentifier WScript.Echo "EventType: " & objItem.EventType for each propValue in objItem.InsertionStrings WScript.Echo "InsertionStrings: " & propValue Next WScript.Echo "Logfile: " & objItem.Logfile WScript.Echo "Message: " & objItem.Message WScript.Echo "RecordNumber: " & objItem.RecordNumber WScript.Echo "SourceName: " & objItem.SourceName WScript.Echo "TimeGenerated: " & objItem.TimeGenerated WScript.Echo "TimeWritten: " & objItem.TimeWritten WScript.Echo "Type: " & objItem.Type WScript.Echo "User: " & objItem.User End If End If Next
'Close the file and clean upobjTextStream.CloseSet objTextStream = NothingSet objFSO = NothingWScript.Quit
User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

Hello All,

I am a newbie in vbscripting.

I am in testing field using QTP. The primary responsibility is if any upgrades in any application(like microsoft, windows, or any dotcom application is to be tested before launching on users pc i need to ensure that the application is working in testing environment. As the part of the process, one of the steps is to check the event viewer if the applicatin is loaded after successful build of the machine. I go to MSI installer under application in Event viewer and check physically one by one for the application is build on testing environment by looking for event loaded successfully. I am trying to get the information in the form of log file but i am getting for all the users on the machine where i am testing. I would like to generate the report based on user and would like to know how i can check for application # i am looking for.

Thanks for your help in advance.
On Error Resume NextDim strComputer, debug, path Dim objWMIServiceDim propValueDim objItemDim SWBemlocatorDim UserNameDim PasswordDim colItemsDim objFSODim objTextStream
Const fsoForAppend = 8
debug = False
strComputer = "."UserName = ""Password = ""strFilePath = "C:logsWelcome.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")Path = objFSO.GetAbsolutePathName(strFilePath)If objFSO.FileExists(Path) Then' Cretae the text file Set objTextStream = objFSO.OpenTextFile(strFilePath, fsoForAppend)Else 'Open the text file Set objTextStream = objFSO.CreateTextFile(strFilePath, True)
End If


Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")Set objWMIService = SWBemlocator.ConnectServer(strComputer,"rootCIMV2",UserName,Password)Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where Logfile = 'Application' and EventCode = '11728' and user='OFFICEABCUser'",,48)For Each objItem in colItems If objItem.EventType = 3 then objTextStream.WriteLine("Category: " & objItem.Category _ & " string " & objItem.CategoryString) objTextStream.WriteLine("ComputerName: " & objItem.ComputerName) objTextStream.WriteLine("Logfile: " & objItem.Logfile _ & " source " & objItem.SourceName) objTextStream.WriteLine("EventCode: " & objItem.EventCode) objTextStream.WriteLine("EventType: " & objItem.EventType) objTextStream.WriteLine("Type: " & objItem.Type) objTextStream.WriteLine("User: " & objItem.User) objTextStream.WriteLine("Message: " & objItem.Message) objTextStream.WriteLine (" ")
If Debug = True Then WScript.Echo "Category: " & objItem.Category WScript.Echo "CategoryString: " & objItem.CategoryString WScript.Echo "ComputerName: " & objItem.ComputerName for each propValue in objItem.Data WScript.Echo "Data: " & propValue next WScript.Echo "EventCode: " & objItem.EventCode WScript.Echo "EventIdentifier: " & objItem.EventIdentifier WScript.Echo "EventType: " & objItem.EventType for each propValue in objItem.InsertionStrings WScript.Echo "InsertionStrings: " & propValue Next WScript.Echo "Logfile: " & objItem.Logfile WScript.Echo "Message: " & objItem.Message WScript.Echo "RecordNumber: " & objItem.RecordNumber WScript.Echo "SourceName: " & objItem.SourceName WScript.Echo "TimeGenerated: " & objItem.TimeGenerated WScript.Echo "TimeWritten: " & objItem.TimeWritten WScript.Echo "Type: " & objItem.Type WScript.Echo "User: " & objItem.User End If End If Next
'Close the file and clean upobjTextStream.CloseSet objTextStream = NothingSet objFSO = NothingWScript.Quit
User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

i want to be specific to what i am looking for and i knew its like a story.

I would like to pull out from event viewer under msi installer based on user on the computer who logged.

thanks for ur help in advance.
User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

Thanks for the guidance the script worked. I got the log file consisting of applications successfully installed. Is it possible to get by app#. I know I can hard code it but would like to use the same script for different applications. For eg: If i am testing today APP00780 and tomorrow APP00783. I would like to get the log pertaining to what i am testing. As if i am testing today for APP00780 i should get the log file information pertaining to this.

Appreciate your help once again..

User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

Thanks for the guidance I will incorporate this and test it.

User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

I am getting clean compile but the welcome.txt file is still blank and not picking any from the event viewer. I had the AP00095 entered in the input box but still the log file empty. The record infact is present in the event viewer.

Thank you once again...
On Error Resume NextDim strComputer, debug, path Dim objWMIServiceDim propValueDim objItemDim SWBemlocatorDim UserNameDim PasswordDim colItemsDim objFSODim objTextStreamDim appNameConst fsoForAppend = 8debug = FalsestrComputer = "."UserName = ""Password = ""
strFilePath = "C:logsWelcome.txt"Set objFSO = CreateObject("Scripting.FileSystemObject")Path = objFSO.GetAbsolutePathName(strFilePath)If objFSO.FileExists(Path) Then' Create the text file Set objTextStream = objFSO.OpenTextFile(strFilePath, fsoForAppend)Else 'Open the text file Set objTextStream = objFSO.CreateTextFile(strFilePath, True)End If
strAppNumber = inputbox("Type in the Application #")Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")Set objWMIService = SWBemlocator.ConnectServer(strComputer,"rootCIMV2",UserName,Password)Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where NAME LIKE '" & strAppNumber & "'" ,,48)
For Each objItem in colItems If objItem.EventType = 3 then objTextStream.WriteLine("Category: " & objItem.Category _ & " string " & objItem.CategoryString) objTextStream.WriteLine("ComputerName: " & objItem.ComputerName) objTextStream.WriteLine("Logfile: " & objItem.Logfile _ & " source " & objItem.SourceName) objTextStream.WriteLine("EventCode: " & objItem.EventCode) objTextStream.WriteLine("EventType: " & objItem.EventType) objTextStream.WriteLine("Type: " & objItem.Type) objTextStream.WriteLine("User: " & objItem.User) objTextStream.WriteLine("Message: " & objItem.Message) objTextStream.WriteLine (" ") If Debug = True Then WScript.Echo "Category: " & objItem.Category WScript.Echo "CategoryString: " & objItem.CategoryString WScript.Echo "ComputerName: " & objItem.ComputerName for each propValue in objItem.Data WScript.Echo "Data: " & propValue next WScript.Echo "EventCode: " & objItem.EventCode WScript.Echo "EventIdentifier: " & objItem.EventIdentifier WScript.Echo "EventType: " & objItem.EventType for each propValue in objItem.InsertionStrings WScript.Echo "InsertionStrings: " & propValue Next WScript.Echo "Logfile: " & objItem.Logfile WScript.Echo "Message: " & objItem.Message WScript.Echo "RecordNumber: " & objItem.RecordNumber WScript.Echo "SourceName: " & objItem.SourceName WScript.Echo "TimeGenerated: " & objItem.TimeGenerated WScript.Echo "TimeWritten: " & objItem.TimeWritten WScript.Echo "Type: " & objItem.Type WScript.Echo "User: " & objItem.User End If End If Next'Close the file and clean upobjTextStream.CloseSet objTextStream = NothingSet objFSO = NothingWScript.Quit

User avatar
jdelatorre@hfinc.com
Posts: 54
Last visit: Wed Jan 30, 2008 1:42 am

Help need in modifying the script

Post by jdelatorre@hfinc.com »

If that query works then we will work on how to input that into a Inputbox
User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

Appreciate your help Joel. But its still getting the blank welcome.txt log file.
User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

Thanks joel. it worked well. it pulled out the 3 records and infact there are three records with different dates for the same application. is it possible to pull out the current one i mean if the build is done @ 9 am and normally the process takes around 2 hrs to complete. is it possible to pull out only that record for build done.

thanks once again and appreciate your help.

User avatar
porabai
Posts: 14
Last visit: Fri Mar 28, 2008 1:09 am

Help need in modifying the script

Post by porabai »

i had incorporated some change in the code to pull the event from event viewer date wise but i had to hardcode the date. but unfortunately i deleted the eventlog by running delete event log file script.
is there anyway i can incorporate this way.

if i run the script now it should get the event log from event viewer for the last 2 hours or so.
Appreciate your help in advance.
thanks

this is the code.....

Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")DateToCheck = CDate("2/18/2002") ' this part is hardcoded'dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIMEdtmEndDate.SetVarDate DateToCheck + 1, CONVERT_TO_LOCAL_TIME
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")Set objWMIService = SWBemlocator.ConnectServer(strComputer,"rootCIMV2",UserName,Password)Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where logfile = 'Application' and eventcode = '11728' and Sourcename = 'MsiInstaller' and message like '%AP00790%' and TimeWritten >= '" & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
This topic is 16 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked