Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I tried using the following 1

Status
Not open for further replies.

pgk

Programmer
Jul 19, 2002
262
US
Hi,
I tried using the following Windows Script code but it is giving me problems:

Set WiSh=CreateObject("WScript.Shell")
lRet = WiSh.Run("C:\Program Files\myExe.exe",1,True)

The Run method fails when I try to run the above code snippet. However, it runs when folders with no spaces in their names are used.

lRet = WiSh.Run("C:\ProgramFiles\myExe.exe",1,True) works fine.

So I believe the problem is with the spaces in folder names. Any ideas as to how to overcome this would be very much welcome.

Thanks in advance.

Hope it helps. Let me know what happens.
With regards,
PGK
 
Code:
' using the FileSystemObject:

Option Explicit

Private Sub Command1_Click()
  Dim sFile As String
  
  sFile = "C:\Program Files\Microsoft Office\Office\WINWORD.EXE"
  
  Debug.Print sFile
  
  Debug.Print DOSName(sFile)
End Sub

Private Function DOSName(sFile As String) As String
  Dim oFSO As Object
  Dim oFile As Object
  
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  Set oFile = oFSO.GetFile(sFile)
  DOSName = oFile.ShortPath
  Set oFile = Nothing
  Set oFSO = Nothing
End Function
 
Code:
' using API

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Public Function GetShortPath(strFileName As String) As String
    'KPD-Team 1999
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim lngRes As Long, strPath As String
    'Create a buffer
    strPath = String$(165, 0)
    'retrieve the short pathname
    lngRes = GetShortPathName(strFileName, strPath, 164)
    'remove all unnecessary chr$(0)'s
    GetShortPath = Left$(strPath, lngRes)
End Function
Private Sub Form_Load()
    MsgBox GetShortPath("c:\Program Files\")
End Sub
 
Hi,
Thanks for the info. As a mark of my appreciation, I give you the only thing that is possible right now, a star. Hope it helps. Let me know what happens.
With regards,
PGK
 
Hi,
One more question: Will I able to use the File System Object library and the Windows Shell Scripting library on all Windows machines irrespective of whether VB is installed or not? Hope it helps. Let me know what happens.
With regards,
PGK
 
am not sure but I think the Windows Shell Scripting object comes with IE 5.5 or later

I had some problems once with the FileSystemObject on some Win 98 machines but was able to just replace the scrrun.dll with mine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top