/build/static/layout/Breadcrumb_cap_w.png

Logging help!

Heya guys,

My bosses have asked me to start logging our package installations on computers. MSIEXEC /L doesn't give me a "lite" version of a log file. /Lv contains just too much information.

What I would like to have is something that gives me something like this:

%DATE%, %TIME%, %PRODUCTNAME% Installed.
%DATE%, %TIME%, %PRODUCTNAME% Installed.
%DATE%, %TIME%, %PRODUCTNAME% Uninstalled.

etc etc...

Can you guys help me out? I havn't had any luck trying to use ECHO's in my CMD files yet... So I'm open to all suggestions!

0 Comments   [ + ] Show comments

Answers (18)

Posted by: anonymous_9363 16 years ago
Red Belt
0
"This is a job for.........VB Script!"

Seriously, you could use DOS echos for date and time but the other data you specify isn't available in DOS (natively) so I don't think there's any alternative to using some sort of script. Does your deployment process not have logging of some kind?
Posted by: Fau 16 years ago
Senior Purple Belt
0
Yeah, but the problem with it is the following: the logging is kept server side on our SMS server. First. Second, the logs are kept for each software. It's not kep in a single file, which we would like.

Ok, so I guess VB it will be! I'll bug my VB knowing friend! :-)

Thanks!
Posted by: Fau 16 years ago
Senior Purple Belt
0
Heum... Ok so seems my colleague is going out for the next two weeks, so I'm alone on this! hehe

Do you by any chance have any web sites which are very helpful for a total VB Script noob? :-)
Thanks again!
Posted by: anonymous_9363 16 years ago
Red Belt
0
ORIGINAL: Fau
Do you by any chance have any web sites which are very helpful for a total VB Script noob? :-)
As a reference tool for the language, it'd be hard to beat DevGuru http://www.devguru.com/technologies/vbscript/index.asp

Other than that, I don't think there's any substitute for looking at other people's stuff. So,
http://www.computerperformance.co.uk/vbscript/index.htm and
http://cwashington.netreach.net/depo/default.asp?topic=repository&scripttype=vbscript

I'm sure you could find others but these are the ones I keep returning to.

Lastly, of course, you can pose your scripting questions here http://www.appdeploy.com/messageboards/tt.asp?forumid=6
Posted by: Tone 16 years ago
Second Degree Blue Belt
0

@ECHO OFF
SET MSI=CIS-TFTPserver-1-R01-4311
SET LOG=Installed %MSI% %DATE% %TIME%
msiexec /i %msi%.msi /qb! & echo %LOG% >> C:\%MSI%.log
Would create a file called CIS-TFTPserver-1-R01-4311.log

Log would read
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:22.35
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:23.69
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:24.31
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:24.70
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:25.03
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:25.57
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:25.93
Installed CIS-TFTPserver-1-R01-4311 11/04/2008 23:41:26.28


or you could use && so no log is written if msi fails, but this might not work with a succesful install that returns an error..
Posted by: anonymous_9363 16 years ago
Red Belt
0
Tony, whilst the command file you show is OK in itself, it is too simplistic. On a very basic level, for example, like so much of what I see, it assumes success at every level - there is ZERO error-trapping. If the installation fails, the log file will show that it *was* installed. One could go to the trouble of adding ERRLEVEL traps but, if one is going to do that, it may as well be done properly, i.e. in a proper scripting environment, where actual results can be shown, as opposed to a simple failure message. My own preference would be VB Script as that is an area in which I have a good deal of experience but it could be Powershell, Kix, Perl, REXX (anyone?!? LOL...), ya-di-da-di-da.
Posted by: spartacus 16 years ago
Black Belt
0
It seems to me that much of the logging information you need already takes place from Windows Installer's records to the Application Event log. So another approach would be to look at retrieving the information from there (using WMI).

Here's a short script I wrote that may meet (some of) your requirements.

Option Explicit
Dim oFSO, oFile, oWMI, oEvent, oSWbem
Dim strComputer, sfile, sdate, sReadableDateTime
Dim ievent, iRecNum, colEvents
Const sLogFile = "C:\WMIEvents.log" 'Path and name of log file, alter as needed
Const iConfigSuccessEvent = 11728 'Event code for successful maintenance operation
Const iRemoveSuccessEvent = 11724 'Event code for successful uninstallation operation
Const iInstallSuccessEvent = 11707 'Event code for successful installation operation
Const iRemoveFailEvent = 11725 'Event code for failed uninstallation operation
Const iConfigFailEvent = 11729 'Event code for failed maintenance operation
Const iInstallFailEvent = 11708 'Event code for failed installation operation
'Set up some working counters
ievent = 1
iRecNum = 1
'Set up computer name to run WMI queries against - defaults to local computer
strComputer = "."
' Instantiate object for CIM Date Time manipulation
Set oSWbem = CreateObject("WbemScripting.SWbemDateTime")
'Set up Log file handling
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Clear any existing log file
If oFSO.FileExists(sLogFile) Then
oFSO.DeleteFile sLogFile,True
End If
' Create a fresh log file
Set sfile = oFSO.CreateTextFile(sLogFile, True)
'Now for The WMI stuff
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colEvents = oWMI.ExecQuery ("Select * from Win32_NTLogEvent Where Logfile = 'Application'" )
ievent = 1
' Write any of the Windows Installer Specific Events found in the Application log to the report log file
For Each oEvent in colEvents
If (oEvent.EventCode = iConfigSuccessEvent) OR _
(oEvent.EventCode = iRemoveSuccessEvent) OR _
(oEvent.EventCode = iInstallSuccessEvent) OR _
(oEvent.EventCode = iRemoveFailEvent) OR _
(oEvent.EventCode = iConfigFailEvent) OR _
(oEvent.EventCode = iInstallFailEvent) Then
' Convert WMI DateTime format to something more friendly to read
oSWbem.Value = oEvent.TimeWritten
sReadableDateTime = oSWbem.GetVarDate(False)
sfile.WriteLine ("Timestamp:- " & sReadableDateTime)
sfile.WriteLine ("Message:- " & oEvent.Message)
sfile.WriteLine (" ")
iRecNum = iRecNum +1
End if
ievent = ievent + 1
Next
' Tidy up objects and finish gracefully
set osWbem = Nothing
set oFSO = Nothing
WScript.Quit



Regards,

Spartacus
Posted by: tubs_1 16 years ago
Senior Yellow Belt
0
Hi Spartacus

Just seen the VB script you did for this guy and wanted to ask if you me trying to make use of it, only I am after something along these lines too.

Need either a command line or vbs to create a log file if an MSI install fails with some form of identifier.

I have taken the liberty of running this on a VM machine here and it creates a log file and shows all installs, is there any way i can add it to an existing bat file or vbs to run at the end

hope you can advise

Cheers[8|]
Posted by: applereaper 16 years ago
Senior Yellow Belt
0
Have you thought about logging to the event viewer? This will already have the time/date and the user who installed it.

The script is below for it:
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
"Application XXX has been installed."
Posted by: tubs_1 16 years ago
Senior Yellow Belt
0
Have you thought about logging to the event viewer? This will already have the time/date and the user who installed it

Would this allow me to identify which ones failed easily tho, the idea I am after is:
I have an MSI installation to do and need to have some method generating a log of all machines that fail to install.
I have done command line to a file but this writes if sucess or fail.

so looking for someway of something.msi > success or fail to log file, maybe even with the file name having an identifier by computer name as file name

i know asking a lot, knew to scripting here

cheers
Posted by: jmcfadyen 16 years ago
5th Degree Black Belt
0
just write a tag into the registry in install .

HKLM\Software\Packages\[ProductName]\InstallDate = [DATE]

My next blog topic will cover this cr@p in detail... most likely will do it over the weekend.
Posted by: tubs_1 16 years ago
Senior Yellow Belt
0
HKLM\Software\Packages\[ProductName]\InstallDate = [DATE]

Sorry to be a pain
I am nont upto speed with all this stuff, so how do I include this in the installation of the MSI and port to a log file

Cheers
Posted by: anonymous_9363 16 years ago
Red Belt
0
Richard,

Do you want the data recorded on the machines or some central store?

You need do nothing to create installation data: it already exists in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\[ProductCode]

Most of the replies here will record stuff locally and, if your wish is to create some sort of inventory, your script would need to walk the machines in your domain, interrogating either the registry or event logs. If, however, you want a central log, created AT install time, you either need to explore your deployment mechanism's logging, if available, or set up a property in your MSIs to point at a central store (to which your users have write-access) and then write the Product Name, product Code, date/time whatever via a Custom Action placed after InstallFinalize.
Posted by: tubs_1 16 years ago
Senior Yellow Belt
0
point at a central store (to which your users have write-access) and then write the Product Name, product Code, date/time whatever via a Custom Action placed after InstallFinalize.

This is exactly what I need
point at a central store (to which your users have write-access) and then write the Product Name, date/time whatever via a Custom Action placed after InstallFinalize.

I just want a line with the application, computername and sucess or fail either by command line or VB or anything really
Posted by: anonymous_9363 16 years ago
Red Belt
0
ORIGINAL: tubs_1
I just want a line with the application, computername and sucess or fail either by command line or VB or anything really
Richard, what Graham (Spartacus) posted contains the bones of what you want. Option Explicit
Dim oFSO,
Dim strComputer, oFile, strMsg, strProductName

Const intFSOForReading = 1
Const intFSOForWriting = 2
Const intFSOForAppending = 8
Const intFSOTristateFalse = 0

Const sLogFile = "\\server_name\share_name\SoftwareInstall.log"

With Session
strComputer = .Property("[%COMPUTERNAME]")
strProductName = .Property("ProductName")
End With

'Set up Log file handling
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sLogFile, intFSOForAppending, FailIfNotExist, OpenAsDefault)
strMsg = strProductName & " installed on " & strComputer & " at " & Now()
oFile.WriteLine strMsg

' Tidy up objects and finish gracefully
set oFile = Nothing
set oFSO = Nothing
This is untested! I just knocked it up quickly to give you an idea of how to proceed. Add it as an embedded script in Execute Immediate sequence, right before InstallFinalize, with a condition 'If Installed AND Not REMOVE~="ALL"'

If you wanted to go the walk-the-machines route, a quite thorough documentor can be found at http://cwashington.netreach.net/depo/view.asp?Index=894. You'd need to adapt it to log to a file (IIRC, it outputs to an IE window...) but you can use the code above to do that.
Posted by: tubs_1 16 years ago
Senior Yellow Belt
0
[font="courier new"]Still having probs, think its down to my knowledge tho and not your or others scripts.
[font="courier new"]
[font="courier new"]I have a machine named xpws1234 and will be installing an application called Relupgrade.msi
[font="courier new"]I want to run this with an MST
[font="courier new"]I need to run it as a login script of SMS batch file type thing; and when it fails of completes to write a file or line in a file with the machine name (success or fail)
[font="courier new"]
[font="courier new"]I only started reading up on vb and command line recently.
[font="courier new"]
[font="courier new"]RIch
Posted by: anonymous_9363 16 years ago
Red Belt
0
Rich, To be honest, I doubt anyone here has the time to do what you REALLY want, i.e. to write the script from start to finish. We all have our own jobs to do, unfortunately. You have the building blocks already: you just need to mix the mortar, stack the bricks and build the wall. For the task you outline, my psuedo-code, FWIW:

- open the MSI and get the product name and any other details you might want from it
- use the WSShell object to kick-off MSIExec.EXE with the name of your MSI and MST as arguments, in the normal way.
- interrogate the registry of the target machine to see if the product is installed. Use the WindowsInstaller.Installer object for the latter.
- record success or failure in your shared log file.

You can d/l examples of ALL the above, to save you from having to start from scratch.
Posted by: Tone 16 years ago
Second Degree Blue Belt
0
ORIGINAL: VBScab

Tony, whilst the command file you show is OK in itself, it is too simplistic. On a very basic level, for example, like so much of what I see, it assumes success at every level - there is ZERO error-trapping. If the installation fails, the log file will show that it *was* installed. One could go to the trouble of adding ERRLEVEL traps but, if one is going to do that, it may as well be done properly, i.e. in a proper scripting environment, where actual results can be shown, as opposed to a simple failure message. My own preference would be VB Script as that is an area in which I have a good deal of experience but it could be Powershell, Kix, Perl, REXX (anyone?!? LOL...), ya-di-da-di-da.


To be fair someone suggested vbscript and OP said he wanted a simple script so your own preference wasnt what was been asked for - so simple it is, I would never user it but I also wasnt going to go the trouble of finding all the error levels for a successful install...
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ