 |

10-18-2003, 07:25 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Iran
Posts: 209
|
|
Problem with Shell() Command
|
Hi everybody,
I’m using Shell command to run some applications from within my program, but this command is very primitive and DOS related! (i.e. it can’t run a command like this because of spaces between paths:
Shell(“d:\program files\acd system\acdsee\5.0\acdsee5.exe c:\temporary\t.jpg”)
Is there any other way to run applications like this?
Thanks
|
__________________
Nobody's perfect
|

10-18-2003, 07:56 AM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|

10-19-2003, 05:05 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Iran
Posts: 209
|
|
|
Hi,
You know, my problem is because of having spaces between directory names Shell() can't understand the parameters and get "File Not Found" message. I even use a syntax like the following, but it doesn't work either:
Shell "'d:\program files\acd system\acdsee\5.0\acdsee5.exe' 'c:\temporary directory\t.jpg'"
I have a file manager procedure and when user DblClick on a file name, the program search registery and gets related program with the file and run that program to open the file. everything is ok but the shell() command.
|
__________________
Nobody's perfect
|

10-19-2003, 05:46 AM
|
|
Regular
|
|
Join Date: Oct 2003
Location: Penticton, B.C. Canada
Posts: 83
|
|
|
If you find a good solution please tell me too. I am considering a workaround at the moment where I copy the file I need to a temporary directory (where the path has no spaces), and rename the file if it has any spaces, and then execute my shell command. For me this cleans up the problem, but I am looking for a cleaner solution. Maybe the workaround will work for you. I'll post if I find anything else interesting.
|
|

10-19-2003, 06:30 AM
|
 |
Contributor
|
|
Join Date: Mar 2003
Location: The FSB
Posts: 570
|
|
Code:
Private Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Put the above in the general declarations of your form (the bit at the top), and put the below anywhere in it:
Code:
Private 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
Then, to get the short path name, just do:
Code:
ShortPath = GetShortName(LongPath)
Hope it helps
|
|

10-19-2003, 02:04 PM
|
|
Regular
|
|
Join Date: Oct 2003
Location: Penticton, B.C. Canada
Posts: 83
|
|
|
Thanks Hitman. You solution is definately more elegant than my potential solution. I will try this out in my project.
|
|

10-20-2003, 04:49 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Iran
Posts: 209
|
|
|
Thank you HiTmAN! I'll try on it.
|
__________________
Nobody's perfect
|

10-20-2003, 09:21 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Iran
Posts: 209
|
|
|
Hi Again!
I've faced a strange thing. I'll give you the complete example I used:
Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Const LANG_NEUTRAL = &H0
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Private Sub ShowError()
Dim Buffer As String
Buffer = Space(200)
FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, GetLastError, LANG_NEUTRAL, Buffer, 200, ByVal 0&
MsgBox Buffer
End Sub
Public Function GetShortPath(strFileName As String) As String
Dim lRetVal As Long, sShortPathName As String, iLen As Integer
sShortPathName = Space(5)
iLen = Len(sShortPathName)
lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
If lRetVal = 0 Then Call ShowError
GetShortName = Left(sShortPathName, lRetVal)
End Function
Private Sub Form_Load()
MsgBox GetShortPath("d:\Program Files\")
End Sub
When I run this program, lRetVal is 0 and strShortPath is empty, but the ShowError method return "The Operation Completed Successfully." message!
|
__________________
Nobody's perfect
|

10-26-2003, 01:52 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Iran
Posts: 209
|
|
|
Well, It seems I can find the best way. Which is using ShellExecute() API funcion.
|
__________________
Nobody's perfect
|

10-26-2003, 02:41 AM
|
|
Regular
|
|
Join Date: Oct 2003
Posts: 85
|
|
yea go with the shellExecute...
Code:
ShellExecute GetDesktopWindow, "open", "d:\program files\acd system\acdsee\5.0\acdsee5.exe", "", "D:\", 5
-Ross
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|