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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell and Long File Name problem

Status
Not open for further replies.

dotnetprogrammer

Programmer
Aug 17, 2000
77
US
One of my VB projects uses SHELL command to execute another executable.
Up until now, it had been working fine.
It began to refuse to execute long file names.
Short file names still executes fine.
Does anyone know why?
Your input will be appreciated.
 
Hello

What version of VB are you using (I had the same issue with 16 Bit VB4 applications but not with any higher versions)?

The only way I know of is this;
Stick the following in a module then call it
Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Public Function GetShortName(ByVal sLongFileName As String) As String
Dim lRetVal As Long, sShortPathName As String, iLen As Integer
'Set up buffer area for API function call return
sShortPathName = Space(255)
iLen = Len(sShortPathName)

'Call the function
lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
'Strip away unwanted characters.
GetShortName = Left(sShortPathName, lRetVal)
End Function

Hope this helps
 
Well, in that case you shouldn't have any problems.

Are you sure the path is exactly correct?
Try the following;
Call Shell("D:\Program Files\Microsoft Visual Studio\VB98\vb6.exe", vbNormalFocus)

(try to run the main vb exe)

If all else fails you can either use the above to make it work OR the following
*******************
Code:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

this needs to be on the button
Dim hFile As Long

hFile = ShellExecute(Me.hwnd, "Open", "d:\temp\manual.pdf", vbNullString, CurDir, 5)
If hFile < 32 Then
    MsgBox &quot;error&quot;
End If
*******************

This is certain to run anything.
 
The path is positively-correct.
ShellExecute did not Unload calling program (that needs to be unloaded).
Thanks,
fred
 
Wild guess...
Some things have a hard time with spaces in the filename. Quotes usually clear it up.

Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top