Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

VB script error


3 replies to this topic

Peter Bi

Peter Bi
  • Members
  • 68 posts

Posted 26 September 2001 - 18:32

Hi,

I am running vbscript to get an installed product code. The code is as following.
-----------------------------------
Option Explicit
Public installer, prod, fso, x, list

Set fso = CreateObject("Scripting.FileSystemObject")

' Connect to Windows Installer object
Set installer = CreateObject("WindowsInstaller.Installer")
x=0
For Each prod In installer.products
  if installer.productinfo (prod, "InstalledProductName")= "Myproductname"
then
      list = list & prod & ";"
      x=x+1
  end if
Next

if len(list)>0 then
   list = left(list, len(list)-1)
   x=x-1
end if

if x>0 then
   Property("FOUNDOLDER") = 0
else if x=-1 then
   Property("FOUNDOLDER")=-1
else
   Property("FOUNDOLDER") = 1
   Property("INSTALLEDCODE") = list
end if
'MsgBox list
-----------------------

The last MsgBox could print right product code when I blocked the code using
Property("..")=..., otherwise I got the compile error "Variable is
undefined: Property". I use Property in this way because I had a small CA
which run VBScript with location set as "Stored directly in the custom
action", and the code it has only one line  --
Property("MYDIR")=Property("ProgramFilesFolder") + "new\dir" --, it works
fine, i.e Property is accepted. What's wrong with my vb code above? I also tried to store it directly
in the custom action, and also tried to block "Option explicit" option, but
didn't work at all...


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 26 September 2001 - 21:14

I think the value must be a string, not a number. Does this work:
Property("FOUNDOLDER") = "0"
or this:
Session.Property("FOUNDOLDER") = "0"

dkingston

dkingston
  • Members
  • 10 posts

Posted 27 September 2001 - 21:39

If you are trying to run this code in a CA, it won't work because you have created an instance of an installer object that has no relation to the currently executing package.  To obtain a reference to the current package, try

For Each oProduct In Session.Installer.Products
 If you are trying to run this code outside of a CA, you need to open a package first.

Dim oSession, oInstaller
Set oInstaller = CreateObject("WindowsInstaller.Installer")
Set oSession = oInstaller.OpenPackage "c:\mypackage.msi"

Then you should be able to access the Properties from Session.Property("..").  I'm not sure if you can permanently change the properties in this fashion, though.

Hope this helps.