RuudHartog
Posts: 2
Joined: Wed Aug 30, 2023 3:43 pm

Setting install parameter based on operating system name

Hi,

I have an install parameter (property) which I would like to modify based on the operating system name

Tried a custom action with below VB script

Code: Select all

prop = Session.Property("ISVDI")
propNew = Session.Property("ISVDI")

If prop = "false" Then
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set OSName = objWMIService.ExecQuery ("Select Name from Win32_OperatingSystem")
  If OSName.Contains("Virtual") Then
			propNew = "true"
	End If
End If

Session.Property("ISVDI") = propNew 
But somehow this fails.
Anyone have a clue what's wrong ?
Liviu
Posts: 1325
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: Setting install parameter based on operating system name

Hello and welcome to our forums,

There is a problem with your script. I have tested the vbscript outside the Advanced Installer and it does not work.

The error you're encountering seems to be related to the use of the Contains method. The error message "Object doesn't support this property or method: 'OSName.Contains'" suggests that the Contains method is not supported on the object type you're using.

To achieve the desired functionality, you might need to modify your script. Here's a revised version that uses the InStr function to check if the string "Win" is contained within the Name property:

Code: Select all

prop = Session.Property("TEST")
propNew = Session.Property("TEST")

If prop = "false" Then
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set OSName = objWMIService.ExecQuery ("Select Name from Win32_OperatingSystem")

	For Each os In OSName
		If InStr(os.Name, "Win") > 0 Then
			propNew = "true"
			Exit For
		End If
	Next
End If

Session.Property("TEST") = propNew 
vbscript.png
vbscript.png (165.93 KiB) Viewed 4026 times
In this version, the InStr function is used to check if the string "Win" is present in the Name property of each operating system instance.

Replace the TEST property name with your property name.

Please give this modified script a try and see if it resolves the error you're encountering.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
RuudHartog
Posts: 2
Joined: Wed Aug 30, 2023 3:43 pm

Re: Setting install parameter based on operating system name

Thanks Liviu,
Works great !

Appreciate your support
Liviu
Posts: 1325
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: Setting install parameter based on operating system name

You're very welcome!

I'm glad to hear that it worked for you.

If you have any more questions or need further assistance in the future, don't hesitate to reach out. Have a great day!

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”