How to: Execute a file/program in VBScript

Put this one in your utilities scripts to include when needed:

Sub Run(ByVal sFile)
Dim shell

    Set shell = CreateObject("WScript.Shell")
    shell.Run Chr(34) & sFile & Chr(34), 1, false
    Set shell = Nothing
End Sub

Then to use it include the script and call it as follows:

' Execute the file MyFile.exe
Run "C:Program FilesMyFile.exe"

Or, use it to execute a file in the app that is registered to handle files of that type:

' Open the file MyFile.doc in Word
Run "C:My DocumentsMyFile.doc"

 

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Hi Ryan and All Guys,

    Could anyone tell me how to execute a .vbs file in HTML??
    Its very urgent and your suggestion is appreciated.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!