Solved

Using wscript.shell to launch an app from VBScript

Posted on 2004-03-24
5
1,630 Views
Last Modified: 2008-02-26
hi guys,

Ive added a script behind a button on an Outlook form that launches an app if the Save & Close button is clicked. The problem is, the Run command fails on the wscript.shell object. It seems to be an issue with using a spae in the run string. ie. if I put "C:\temp\app.exe" it is fine, but if I put the app in temp 2 and use "C:\temp 2\app.exe" it just opens up the temp folder as if it truncated my run statement ! Here is my code...

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "C:\temp 2\notepad.exe"
Set wshShell = Nothing

...doesnt work but...

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "C:\temp\notepad.exe"
Set wshShell = Nothing

...does

Im running on Windows 2000 and Outlook 2002.
0
Comment
Question by:adders99
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10668693
try adding extra qoutes:

wshShell.Run ""C:\temp 2\notepad.exe""
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 50 total points
ID: 10668717
try this instead:

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run Chr(34) & "C:\temp 2\notepad.exe" & Chr(34)
Set wshShell = Nothing
0
 

Author Comment

by:adders99
ID: 10668792
Tried that one and got 'expected end of statement'
0
 

Author Comment

by:adders99
ID: 10668804
tried your second one and it worked a treat. Many thanks ! Any idea why it works like that ?
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10668821
the chr(34) puts qoutes around the string,otherwise wshShell will think anything after the spaces are parameters.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now