Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using wscript.shell to launch an app from VBScript

Posted on 2004-03-24
5
Medium Priority
?
1,637 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

636 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