Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Installing an Application Using VBScript

Updated: 13 May 2008 | 5 comments
Eshwar's picture
+30 30 Votes
Login to vote

Did you know you can install an application with VBScript using the "Run" method.

Here's a sample script illustrating how we do it (and how we also write return codes to the eventlog):

object.Run(strCommand, [intWindowStyle],[bWaitOnReturn])  

'INSTALL MS INTERNET EXPLORER 7 USING VBScript    
Set objShell = WScript.CreateObject("WScript.Shell")
spath = objShell.CurrentDirectory

If fso.FileExists(spath & "\IE7-WindowsXP-x86-enu.exe") Then
	path = """" & spath & "\IE7-WindowsXP-x86-enu.exe" & """ /passive /norestart /update-no"
	objShell.Run(path, 1 ,True)
	i = 0
	'INSTALL MICROSOFT INTERNET EXPLORER 7    
	i = objShell.Run(path, 1 ,True)
	If (i = 0) Or (i = 3010) Then 
		'WRITE EXIT CODE [0-success/3010-success&requires reboot] TO EVENTLOG
		objShell.LogEvent vbLogSuccess, sLogHeader & "Microsoft Internet Explorer 7 installation completed successfully." & VbCrLf & "Exit code: " & i
	Else
		MsgBox "The installation of Microsoft Internet Explorer 7 returned an error: " & i & VbCrLf & _
		"Please contact IT Support to report this error.", vbOKOnly
		objShell.LogEvent vbLogError, sLogHeader & "Installation returned failure code: " & VbCrLf & "Exit code: " & i
	End If
	
Else
	WScript.Quit (1)
End If

set fso = Nothing
set WSHShell = Nothing
Wscript.Quit

The main purpose of the Exit code is to inform Altiris that the package has been installed successfully.

Comments

mocarski's picture
15
May
2008
0 Votes 0
Login to vote

WSH Errors

We occasionally run into issues where Windows Scripting Host is corrupted on a system and similar code that we use fails on that system. I would love to see the code for checking this in your script and also to find out recommendations for autorepairing WSH.

Eshwar's picture
16
Oct
2008
20 Votes +20
Login to vote

WSH repair

Try restoring Windows Script Host settings to Defaults:

1. Start --> Run --> c:\WINDOWS\system32\wscript.exe
2. Check the option “Stop script after specified number of seconds”
3. Click on the button “Restore to Defaults”

If that doesn’t solve the issue then we can try manually registering vbscript.dll & jscript.dll
In the command prompt try executing the following commands.

1. Start --> Run --> regsvr32.exe vbscript.dll
2. Start --> Run --> regsvr32.exe jscript.dll

Sorry for the late reply

Good luck

Thanks,
Eshwar

Eshwar's picture
16
Oct
2008
19 Votes +19
Login to vote

Get current folder path

objShell.CurrentDirectory will fetch you the current directory but when i executed the vbscript in a command prompt, it doesn't execute. I tried replaing
spath = objShell.CurrentDirectory
with the below specified script. It worked for me.
---------------------------------------------------
'GET CURRENT FOLDER PATH
spath = fso.GetParentFolderName(WScript.ScriptFullName)
If Right(spath, 1) <> "\" Then spath = spath & "\"
---------------------------------------------------

Now we can remove "\" from "\IE7-WindowsXP-x86-enu.exe" from the main script


Symantec Juice

Thanks,
Eshwar

KSchroeder's picture
17
Oct
2008
21 Votes +21
Login to vote

To check for corrupt WSH/WMI...

At the beginning of your script when you have your CreateObject() calls, after each one (or after all of them) add the following:

If Err.Number <> 0 Then 
   MsgBox "Error creating required script objects!"
   Wscript.Quit(1)
End If

Thanks,
Kyle
Symantec Trusted Advisor

For Forum threads, please click "Mark as Solution" if answered.
For all content, please give a thumbs up if you agree with or support the post.

Sidd's picture
03
Dec
2008
12 Votes +12
Login to vote

Define ......

Don't forget to define the necessary variables in the main script. and sLogHeader = "Your application Name". Otherwise you will end up with error if you don't define sLogHeader.

Thanks
Sid