?
Solved

A problem in <oShell.Run>

Posted on 2003-03-13
5
Medium Priority
?
1,585 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
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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

612 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