Valid script which doesn't work in .msi - Advanced Installer Community
noisyfreak
Posts: 13
Joined: Mon Oct 28, 2013 3:05 pm

Valid script which doesn't work in .msi

Hi all,
I've got trouble with one of my VBS script. It took a list of computer's name in entry then fill a property with name + mac address.

Code: Select all

Function getMacAddr(tabname)
	macl=""
	Const OpenAsDefault = -2
	Const FailIfNotExist = 0
	Const ForReading = 1
	tab=Split(tabname,",")
 	Set objShell = CreateObject("WScript.Shell")
	Set FSO = CreateObject("Scripting.FileSystemObject")
	fileTemp = objShell.ExpandEnvironmentStrings("%TEMP%")
	fileTempFile = fileTemp & "\" & FSO.GetTempName
 For each i in tab
	objShell.Run "%comspec% /c nslookup " & i & " | find /i ""."">" & fileTempFile, 0, True
	 Set FTempFile2 = FSO.OpenTextFile(fileTempFile, ForReading, FailIfNotExist, OpenAsDefault)
	 strResults = FTempFile2.ReadAll
	 FTempFile2.Close
	 FSO.DeleteFile (fileTempFile)
	 strResults = Replace(strResults,vbtab, "Address:")
	 arrIP = Split(strResults, "Address:")
	 Set FTempFile2 = Nothing
	 If UBound(arrIP) < 2 Then
		dnsresult = "Unable to get IP"
	 Else
		arrIPTemp = Split(arrIP(2), Chr(13))
		dnsresult = trim(arrIPTemp(0))
		objShell.Run "%comspec% /c nbtstat -a " & dnsresult & ">" & fileTempFile, 0, True
		Set FTempFile3 = FSO.OpenTextFile(fileTempFile, ForReading, FailIfNotExist, OpenAsDefault)
	       strResults = FTempFile3.ReadAll
		FTempFile3.Close
		FSO.DeleteFile (fileTempFile)
		artmp=Split(strResults,"MAC Address =")
		macl = macl & Mid(i,3,Len(i)-2) & " " & Replace(trim(Split(artmp(1),vbCrlf)(0)),"-","") & VbCrlf
		Set FTempFile3 = Nothing
	 End If
 Next
Session.property("MACLIST") = macl 'WScript.echo macl if outside msi
Set objShell = Nothing
Set FSO = Nothing

end function
When i call this function through cscript client, all works well and the output is correct
frrampc049 0022192E5702
frampc052 002219E8DE68
frrampc044 5C260A3F4430

But when this function is called from the msi, with same parameters ( getMacAddr("\\frrampc049,\\frampc052,\\frrampc044") ) , an error is throw an script isn't executed.
By comment / uncomment script's line i found that error comes from this line " strResults = FTempFile3.ReadAll", but i don't know why...

Someone has ever had this kind of problem ?? There's a way to show msi log ?
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Valid script which doesn't work in .msi

Hi,

I'm not sure why you encounter this behavior. I tried to test your VBS code, but I couldn't get a result because I don't have the resources needed by it. A good method to debug custom action is to insert message boxes as much as possible in its code which will display the resulted data for each step.
There's a way to show msi log ?
Yes, when a custom action fails the "FatalError" dialog is displayed and it contains a checkbox called "Show log" which you can check to see the MSI log. In that log you can find a line like follows:
Error ... . There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action GetMacAddress.vbs ...

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
noisyfreak
Posts: 13
Joined: Mon Oct 28, 2013 3:05 pm

Re: Valid script which doesn't work in .msi

Hi,
Yes i found this message "Input past end of file" for the line "strResults = FTempFile3.ReadAll". It's as if the temp file couldn't be created but i don't know why...
You could test this by passing in argument the result of windows command "hostname" which give your computer's name.


Regards.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Valid script which doesn't work in .msi

Hi,

First of all I apologize for my delayed reply.

I tried to debug the custom action and I reproduced the behavior, but unfortunately I couldn't find the problem. It seems that when it is launched from the "msiexec.exe" process, something is blocking it from accessing that temporary file.

It is known that VBS custom actions can cause problems and that is why they are not recommended (they can be used for simple scenarios). So, I would recommend you to create a C# or C++ custom action.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
noisyfreak
Posts: 13
Joined: Mon Oct 28, 2013 3:05 pm

Re: Valid script which doesn't work in .msi

Hi,
There's no problem ;)
Ok I'll try that asap.

Thanks for your time.
Regards.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Valid script which doesn't work in .msi

You're welcome.

Just let us know anytime you need help.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”