For Programmers: Free Programming Magazines  


Home > Archive > VBScript > November 2004 > Executing a number of programs









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Executing a number of programs
Liam Mac

2004-11-23, 3:56 pm

Hi there,
I'm new to the world of scripting, but have some VB experience. What I'm
trying to do is to write a script that will allow me to launch a number of
programs in sequence. having create diffculty finding vbscript to do this.
The program I'm launching are third party windows applications.
Been trying simple script like below to work, but no joy. Any help on
assistance on how to launch an application in vbscript would be great.
thanks,
Liam

oShell = WScript.CreateObject("WScript.Shell");
oShell.Run( "command.com /K dir c:\\windows");
oShell.Run( "wordpad.exe");
WScript.Echo( "Done" );


Scott Fenstermacher

2004-11-23, 3:56 pm

2 Parts:
First, this is one of the scripts I use to install an application. I'll
modify this to fit whichever application I need to install.
========================================
==
Option Explicit

Dim ApplicationToInstall
If IsLaptop Then
ApplicationToInstall = "R:\VPN\VPN405 silent.exe"
Else
WScript.Quit(0)
End If

Const HideWindow = 0
Const ActivateWindow = 1
Const WaitOnReturn = True
Const DontWaitOnReturn = False

Wscript.echo "Installing " & ApplicationToInstall
Dim Shell
Set Shell = WScript.CreateObject("WScript.Shell")
Dim FSO
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Dim iReturnResult
If FSO.FileExists(ApplicationToInstall) Then
iReturnResult = Shell.Run("""" & ApplicationToInstall & """",
ActivateWindow, DontWaitOnReturn)
Else
WScript.Echo "Unable to locate application!"
WScript.Quit(1)
End If
WScript.Quit(iReturnResult)

Function IsLaptop
Dim oWMI, oChassis, ChassisType

Set oWMI = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
For Each oChassis in oWMI
ChassisType = oChassis.ChassisTypes(0)
If ChassisType > 7 And ChassisType < 15 Then
IsLaptop = True
Else
IsLaptop = False
End If
Next
End Function
========================================
=======================
Second, the above script and its brethren are all in a directory, each name
beginning with a number (01,02,03,etc) so they can be executed in order by
the following piece of another script: (Note that this script will execute
not only vbs files, but also a few other varieties depending on the
extension). This script is actually called at the tail end of my automated
XP installation to load up the usual standard batch of
applications/patches/whatever.
========================================
=======================

Dim oComSpec
oComSpec = oShell.ExpandEnvironmentStrings("%COMSPEC%") & Space(1) & "/C"

Dim oFilePath
For Each oFile in ScriptsToRun
oFilePath = ScriptFolder & "\" & oFile

Select case UCase(Right(oFile,4))
Case ".INF"
iReturnResult = oShell.Run(oComSpec & Space(1) & "rundll32.exe
setupapi,InstallHinfSection DefaultInstall 132 " &
oFilePath,ActivateWindow,WaitOnReturn)
Case ".REG"
iReturnResult = oShell.Run(oComSpec & Space(1) & "regedit /s " &
oFilePath,ActivateWindow,WaitOnReturn)
Case ".VBS"
iReturnResult = oShell.Run(oComSpec & Space(1) & ScriptingEngine &
Space(1) & oFilePath,ActivateWindow,WaitOnReturn)
Case ".CMD"
iReturnResult = oShell.Run(oComSpec & Space(1) &
oFilePath,ActivateWindow,WaitOnReturn)
Case ".BAT"
iReturnResult = oShell.Run(oComSpec & Space(1) &
oFilePath,ActivateWindow,WaitOnReturn)
Case Else
wscript.echo "Unhandled file type - " & oFilePath
End Select
iReturnResult = 0
Next
========================================
===================
Good luck!
--
Scott Fenstermacher
Network Engineer
Levi, Ray and Shoup, INC

"Liam Mac" <LiamMac@discussions.microsoft.com> wrote in message
news:159089A9-AE12-4668-9D88-DA0B0F172519@microsoft.com...
> Hi there,
> I'm new to the world of scripting, but have some VB experience. What I'm
> trying to do is to write a script that will allow me to launch a number of
> programs in sequence. having create diffculty finding vbscript to do this.
> The program I'm launching are third party windows applications.
> Been trying simple script like below to work, but no joy. Any help on
> assistance on how to launch an application in vbscript would be great.
> thanks,
> Liam
>
> oShell = WScript.CreateObject("WScript.Shell");
> oShell.Run( "command.com /K dir c:\\windows");
> oShell.Run( "wordpad.exe");
> WScript.Echo( "Done" );
>
>



Jeff Cochran

2004-11-23, 8:55 pm

On Tue, 23 Nov 2004 10:35:04 -0800, "Liam Mac"
<LiamMac@discussions.microsoft.com> wrote:

>Hi there,
> I'm new to the world of scripting, but have some VB experience. What I'm
>trying to do is to write a script that will allow me to launch a number of
>programs in sequence. having create diffculty finding vbscript to do this.
>The program I'm launching are third party windows applications.
>Been trying simple script like below to work, but no joy. Any help on
>assistance on how to launch an application in vbscript would be great.
>thanks,
>Liam
>
>oShell = WScript.CreateObject("WScript.Shell");
>oShell.Run( "command.com /K dir c:\\windows");
>oShell.Run( "wordpad.exe");
>WScript.Echo( "Done" );


Technically, it's WSH and not VBScript. Your syntax is off though:

Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run( "wordpad.exe")

Also, if you had run your scfript without the SET in the first line of
code, you should have gotten an error, object does not support method
or something. In the future, post the error so we don't have to
guess.

Jeff
Tom

2004-11-24, 3:55 am

Jeff Cochran wrote:
> On Tue, 23 Nov 2004 10:35:04 -0800, "Liam Mac"
> <LiamMac@discussions.microsoft.com> wrote:
>
>
>
>
> Technically, it's WSH and not VBScript. Your syntax is off though:



Looks like JScript/Javascript to me.
Leave out the semi-colons too.



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com