Login / Register  search  syndication

          CRM Developer

Ryan Farley on CRM Development for SalesLogix, SageCRM, MSCRM, .NET - and all things geek

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 Files\MyFile.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 Documents\MyFile.doc"

 

What's This?
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX Corporation and the creator of slxdeveloper.com.


Related Content
   Populating AutoComplete Strings
I recently had a project which required me to populate the strings collection in an AutoComplete control
Posted on Jul 01, 2009 by Jason Buss to The Customization Blog
 
   Using the Forms collection in the SalesLogix LAN client
From time to time, you may find that you want to reference a control or script on a form other than the o
Posted on Jun 24, 2009 by Jason Buss to The Customization Blog
 
   Utilizing Spell-Check functionality in SalesLogix 7.5 LAN
If you've ever wanted to implement some sort of Spell Check functionality within your SalesLogix data
Posted on Jun 11, 2009 by Jason Buss to The Customization Blog
 
   Extracting Reports from the SalesLogix Plugin Table from External Applications
There are many reasons why extracting a SalesLogix Report from the SalesLogix database might be useful. T
Posted on May 29, 2009 by Ryan Farley to CRM Developer
 
   Setting conditions for Crystal Reports in SalesLogix LAN
I wanted to quickly outline a process for passing a condition to a Crystal report in two simple steps. S
Posted on May 27, 2009 by Jason Buss to The Customization Blog
 
Comments

 

Adam Theaker said:

Thank You,

I am just learning to develop in SalesLogix and finiding examples on how todo things is like pulling your own teeth. I have plenty of experince with VB6 and ASP, and i am still trying to wrap my head around slxVB.

thanks again

Adam
March 10, 2004 9:51 AM
 

Tim said:

This was clear and simple, thanks.

Question: does the executed program run "in line" so the statement after Run "C:\Program Files\MyFile.exe" waits until MyFile.exe is done?

Or does MyFile.exe run asynchronously, sort of like a forked process?

Thanks again.
Tim
August 12, 2004 1:08 PM
 

Ryan Farley said:

Tim,

That's what the last parameter is for, whether or not it is launched asynchronously or not. The example above sets the last parameter to False, so it is not blocking. You could change that to true to achieve the opposite result.

-Ryan
November 3, 2004 1:47 PM
 

Denise Goodheart said:

Hi Ryan,

Thank you for posting your very useful utility script. It helped me enormously. I used your code to execute media player sound files; such as .wav sound files. My question is how can I have the media player software appear on the screen while the sound file is running based on the Windows Folder Option File Type? For instance, a .wav file would be associated with Windows Media Player.

Thank you very much,
Denise Goodheart
July 25, 2005 10:36 PM
 

Sean said:

Hi i would appreciate if you could let me know if i can get the screen shot instead of the message on prompt for the following code..

' Declare variables
Dim WSHShell,strRegKey
' Create the Wscript Shell object, which contains the Registry methods
Set WSHShell = WScript.CreateObject("WScript.Shell")
strRegKey="HKLM\Software\XYZ\Installed\APPNAME\MSI Release Version"
WScript.Echo "Current MSI Version is: " & WSHShell.RegRead(strRegKey)
Wscript.quit(0)

appreciate your help in advance
January 14, 2008 12:14 PM
 

Brandon said:

Can you run the application async and pass data back into SLX?
January 22, 2008 3:38 PM
 

bonald said:

I can't use space with the run command
exemple: gpupdate /force

how can i make this work?
January 29, 2008 8:11 AM
 

Nicolas Galler said:

That is actually very neat - for some weird reason I always felt the neat to do something like shell.run "cmd /c " & file... good to know that I can make it a bit shorter

April 15, 2008 10:11 AM
 

Jenny pretty said:

Very nice utility script in VBScript that I ever saw. Thanks very much for sharing this short script with us.

April 17, 2008 1:39 PM
 

JohnDoe said:

Thank You for sharing your Scripts....

April 25, 2008 5:48 AM
 

Márcio said:

One question: could you give a example of a vbscript that checks if the program is already opened, so it doesn't open it again?

And thanks for the script. Nice and simple.

May 28, 2008 4:01 PM
 

Wyn said:

Thanks for sharing this script. I'm trying to use this script to run some registry keys to be registered under the windows registry. Is there a way to run these registry keys using this script with out any user interaction? Thanks in advance.

June 27, 2008 8:59 AM
 

Wyn said:

Thanks for sharing this script. I'm trying to use this script to run some registry keys to be registered under the windows registry. Is there a way to run these registry keys using this script without any user interaction? Thanks in advance.

June 27, 2008 9:00 AM
 

Ryan Farley said:

Wyn,

You don't need to execute the reg files to read/write to the registry. Just read and write the values as needed. See customerfx.com/.../39077.aspx

Optionally, you could use the "/s" switch when executing the reg files to do it silently.

-Ryan

June 27, 2008 10:05 AM
 

John Lowe said:

How can I run the script remotley, ie from IIS5 so that I can run a program via a webpage?

Thanks.

July 8, 2008 4:48 AM
 

Script to share multiple folders said:

Pingback from  Script to share multiple folders

August 20, 2008 10:43 AM
 

Josh said:

Nice 'n simple script. Thanks Chris Farley! ;)

August 20, 2008 12:43 PM
 

Dmitry said:

thnx, it helped =)

September 3, 2008 1:30 AM
 

foxhenry said:

short script  but good.. thanks

December 11, 2008 12:26 AM
 

Swordstoo said:

WOW! it worked straight up! although i got kinda freaked out when my nortan internet sequrity came up! i thought the stuff was a scam and virus, but i took the risk and it worked! TY! and as a bonus i didnt have to do anything, nothing incorrect!

January 5, 2009 4:33 AM
 

Swordstoo said:

WOW! it worked straight up! although i got kinda freaked out when my nortan internet sequrity came up! i thought the stuff was a scam and virus, but i took the risk and it worked! TY! and as a bonus i didnt have to do anything, nothing incorrect!

January 5, 2009 4:33 AM
 

Swordstoo said:

WOW! it worked straight up! although i got kinda freaked out when my nortan internet sequrity came up! i thought the stuff was a scam and virus, but i took the risk and it worked! TY! and as a bonus i didnt have to do anything, nothing incorrect!

January 5, 2009 4:33 AM
 

Frostfire said:

Great Script!

To add attributes you can modify it like this instead:

Sub Run(ByVal sFile,sAttr)

Dim shell

   Set shell = CreateObject("WScript.Shell")

   shell.Run Chr(34) & sFile & Chr(34) & sAttr, 1, false

   Set shell = Nothing

End Sub

Run "cmd.exe", "/K query farm > farms.txt"

January 21, 2009 8:48 AM
 

links for 2009-02-12 « Yesure said:

Pingback from  links for 2009-02-12 « Yesure

February 12, 2009 11:58 AM
 

Egon said:

Nice Comand Ryan

Now Im try to install a program into the script how I make the instalation with out the next bottons,

I want the script install all the program for me automatically

could yo helpme with this ?

June 26, 2009 12:49 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2009 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783
 Follow us on Twitter @CustomerFX






Login / Register