?
Solved

Using wscript.shell to launch an app from VBScript

Posted on 2004-03-24
5
Medium Priority
?
1,636 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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