Installshield Vbscript Custom Action

Installshield Vbscript Custom ActionInstallshield Script

Hi guys I'm trying to run the below vbs script inside a custom action on an InstallShield.vbs. The script runs fine if i run it on its own, however when i run it. Calling a VBScript in a msi Custom Action; Calling a VBScript in a msi Custom Action. How helpful is this to you? If you have to have the script sleep.

I understand from within InstallShield there are times when VBScript namespace does not need to be identified. For example, this is perfectly valid on the desktop: Set wshShell = WScript.CreateObject('WScript.Shell') But the same line becomes this within a VBScript CA in InstallShield: Set wshShell = CreateObject('WScript.Shell') In my Basic MSI project, I have a VBScript CA which is throwing a 1720 error code. I’m trying use WMI to manipulate a service post-install. The following two lines are pertinent to the problem and the second line below is line is throwing the 1720: Dim objWMI: Set objWMI = GetObject('winmgmts: ' & sName & ' root CIMV2') Dim objService: Set objService = objWMI.Get('Win32_Service.Name='Message Handler') I’m not qualifying the GetObject with a namespace. Also, and I’m assuming here because there are no errors thrown on the first line of script posted above, that objWMI does indeed get an instance of the CIMV2 provider. And if it does then why does the second line error out? Is it because of the Get method?

Is there any way to use WMI via a VBScript CA from within a Basic MSI project? Suggestions are greatly appreciated. I understand from within InstallShield there are times when VBScript namespace does not need to be identified.

For example, this is perfectly valid on the desktop: Set wshShell = WScript.CreateObject('WScript.Shell') But the same line becomes this within a VBScript CA in InstallShield: Set wshShell = CreateObject('WScript.Shell')I think you misunderstand the docs here. The WScript object is ONLY available when the script is run by CScript.exe or WScript.exe. Other programs with scripting don't know about the WScript object, eg. If you create a web page you'll notice that the WScript object doesn't exist either. On the other hand, when a script is run within Msiexec you'll have the Installer object allowing you access to properties etc. Indeed, such scripts would fail in WScript.exe. The following two lines are pertinent to the problem and the second line below is line is throwing the 1720: Dim objWMI: Set objWMI = GetObject('winmgmts: ' & sName & ' root CIMV2') Dim objService: Set objService = objWMI.Get('Win32_Service.Name='Message Handler') I’m not qualifying the GetObject with a namespace.

Also, and I’m assuming here because there are no errors thrown on the first line of script posted above, that objWMI does indeed get an instance of the CIMV2 provider. And if it does then why does the second line error out? Is it because of the Get method? Is there any way to use WMI via a VBScript CA from within a Basic MSI project? Your best bet is to use the error handling capabilities of Windows Scripting: Look at the Err object.

Code: '============================================================================= ' Purpose: Stops a service using WMI '============================================================================= Function stopService( serviceName ) Dim objWMIService, objService if existsService( serviceName ) then Set objService = GetObject('winmgmts:. Rick Derringer All American Boy Rar. Root cimv2:Win32_Service.Name='& serviceName & '') objService.StopService() Set objService = Nothing else MsgBox 'Service: ' & serviceName & ' doesn't exist. Could not stop this service.' End if End Function '============================================================================= ' Purpose: Starts a service using WMI '============================================================================= Function startService( serviceName ) Dim objWMIService, objService Dim nReturn if existsService( serviceName ) then Set objService = GetObject('winmgmts:. Root cimv2:Win32_Service.Name='& serviceName & '') nReturn = objService.InterrogateService() nReturn = objService.StartService() If nReturn = 14 Then objService.ChangeStartMode 'Automatic' nReturn = objService.StartService() End If Set objService = Nothing else MsgBox 'Service: ' & serviceName & ' doesn't exist. Could not start this service.' End if End Function '============================================================================= ' purpose: check to make sure a service exists using WMI '============================================================================= Function existsService( serviceName ) On Error Resume Next Dim objService Dim nReturn, nIntSvc nReturn = TRUE Set objService = GetObject('winmgmts:.

Root cimv2:Win32_Service.Name='& serviceName & '') if err.number 0 then err.Clear nReturn = FALSE end if Set objService = Nothing existsService = nReturn End Function.