Event Logging - Advanced Installer Community
ruck64
Posts: 57
Joined: Wed Jul 24, 2019 8:46 pm

Event Logging

Attached I have my vbs file and my .aip file. Im trying to determine right after it makes a call to stop a service if it even attempts to go into pending. However, I get a return value of 0

This it the output

Code: Select all

MSI (s) (18:94) [12:37:12:605]: Doing action: Event_Logging
Action 12:37:12: Event_Logging. 
Action start 12:37:12: Event_Logging.
1: Personal Logs:Microsoft Windows [Version 10.0.18362.356] 
Action ended 12:37:13: Event_Logging. Return value 0.
Well I cant attach my script so Ill paste it here

Code: Select all

Function WriteToLog
Const MsgType = &H04000000
Set rec = Installer.CreateRecord(1)
Set ObjShell = Createobject("WScript.shell")
Set ObjExec = ObjShell.Exec("cmd.exe nssm status GoDCA")
dim strFromProc
	strFromProc = ObjExec.StdOut.ReadLine()
rec.StringData(1) = CStr("Personal Logs:" & strFromProc)
'rec.StringData(1) = CStr("Any type of message can be wrote here")
Session.Message MsgType, rec
WriteToLog = 0
End Function
Attachments
DCA.aip
(54.73 KiB) Downloaded 385 times
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Event Logging

Hello Luther,

First of all, please accept my apologies for the delayed reply.

Yes, the custom action does returns value 0 in the log, meaning that it executed successfully. However, it does not print something because the content of it is quite wrong.

First of all, in order to run a command line, "/c" or "/k" arguments must be used.

- /c argument will run the command and then will exit the command line

- /k argument will run the command and then will wait for an input from the user in order to exit

Additionally, have you tested the following command:

Code: Select all

nssm status GoDCA
in a command line? Did it work?

I have downloaded and instlaled NSSM and the above command line did not work for any of my services. I had to give the full path to the NSSM executable.

Basically, here is a "semi-working" script:

Code: Select all

Function WriteToLog
Const MsgType = &H04000000
Set rec = Installer.CreateRecord(1)
Set ObjShell = Createobject("WScript.shell")
Set ObjExec = ObjShell.Exec("cmd.exe /c C:\Users\Catalin\Downloads\nssm-2.24\nssm-2.24\win64\nssm.exe status MyService")
dim strFromProc
	strFromProc = ObjExec.StdOut.ReadAll
rec.StringData(1) = CStr("Personal Logs:")
rec.StringData(1) = CStr(strFromProc)
Session.Message MsgType, rec
WriteToLog = 0
End Function
This time, the event will be written in the log file. However, I noticed a problem for which I couldn't find any solution. In the log file, only the first letter of the output will be printed (which is "S" from "SERVICE_RUNNING" / "SERVICE_STOPPED").

I have tested this with a lot of other commands and everything worked as expected, except for this command.

In the above script, do not forget to replace the name with your Service name and also the path to your NSSM executable.

Hope this helps somehow.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”