VBS script to check and install MSI

Hi guys

Im trying to use a script to deploy this MSI file, im not able to get the script to work

it should check if the software is already installed and install the MSI file

i removed the MSI installer parts with echo to test the script


'Function CheckSoftware(name)
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")

CheckSoftware = False
For Each objItem In colItems
					If InStr(objItem.Name, "Best Authority" ) > 0 Then
					
					if objItem = 
					
					if instr
					
						WScript.Echo "BA installing"
		
					else
					
						WScript.Echo "BA is already installed"
				
                                CheckSoftware = True
                                Exit For
                                End If
Next

'End Function

Open in new window


Thanks in advance
Rat ZuluAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Does this help?
Function CheckSoftware(strName)
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")
	CheckSoftware = False
	For Each objItem In colItems
		If InStr(objItem.Name, strName) > 0 Then
			CheckSoftware = True
			Exit For
		End If				
	Next
End Function

strName = "Best Authority"
If CheckSoftware(strName) Then
	WScript.Echo "BA is already installed"
Else
	WScript.Echo "BA installing"
	REM Insert your msi call here:
End If

Open in new window

0
Rat ZuluAuthor Commented:
Thanks That worked

Im using

WshShell.Run "\\ckfs01\Shares\BA_MasterFiles\BAINSYALL.bat",0,true

Open in new window


to call  a batch file to install the MSI, it doesn't work, is there a way to elevate and install the MSI?

BAINSYALL.bat
msiexec.exe /i "\\ckfs01\Shares\Softwares and Drivers\Best Authority Ver. 3\BestAuthority_3_001_3006_8937.msi" /QN /L*V "C:\Temp\msilog.log"

Open in new window

0
oBdACommented:
Function CheckSoftware(strName)
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")
	CheckSoftware = False
	For Each objItem In colItems
		If InStr(objItem.Name, strName) > 0 Then
			CheckSoftware = True
			Exit For
		End If				
	Next
End Function

strName = "Best Authority"
strExe = "C:\Windows\system32\msiexec.exe"
strArguments = " /i " & Chr(34) & "\\ckfs01\Shares\Softwares and Drivers\Best Authority Ver. 3\BestAuthority_3_001_3006_8937.msi" & Chr(34) & " /QN /L*V " & Chr(34) & "C:\Temp\msilog.log" & Chr(34)

If CheckSoftware(strName) Then
	WScript.Echo "BA is already installed"
Else
	WScript.Echo "BA installing"
	Set objShell = WScript.CreateObject("WScript.Shell")
	strCommand = chr(34) & strExe & chr(34) & strArguments
	objShell.Run strCommand, 1, True
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.