?
Solved

A problem in <oShell.Run>

Posted on 2003-03-13
5
Medium Priority
?
1,578 Views
Last Modified: 2012-05-04
Hello friends,

The following is my code. oShell.Run returns an error
<Method 'Run' of object 'IWshShell3' failed', I think
it is because there is a blank in "My Directory" ,
do you know how can I solve it?

sub main()
    Dim oShell As Object
    Dim nRet As Long
       
    Set oShell = CreateObject("WSCript.shell")
    nRet = oShell.Run("C:\My Directory\RMS.exe", , False)
    Set oShell = Nothing
end sub

Thanks,
--Bita
0
Comment
Question by:bitaoo
[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
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
appari earned 120 total points
ID: 8134456
if longfile name is the problem then try to use shortpath.
you can convert long path to shortpath using following API

add the following declaration in a module.

Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

and modify your code as follows


sub main()
   Dim oShell As Object
   Dim nRet As Long
Dim x As String , l As long
x = String(255, " ")
l=GetShortPathName("C:\My Directory\RMS.exe", x, l)
       
   Set oShell = CreateObject("WSCript.shell")
   nRet = oShell.Run(x, , False)
   Set oShell = Nothing
end sub


0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8135816
Appari's method will work except replace the line

l=GetShortPathName("C:\My Directory\RMS.exe", x, l)

with

l=GetShortPathName("C:\My Directory\RMS.exe", x, 254)
0
 

Author Comment

by:bitaoo
ID: 8137418
Thank for your response but the problem is because of
blank between "My" and "Directory. How can I solve that?

Thanks,
--Bita
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8137608
appari already give you solution. Use GetShortPathName function
0
 

Author Comment

by:bitaoo
ID: 8138270
Thanks a lot.
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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

765 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