Kaveh_1972 10-18-2003, 07:25 AM 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
passel 10-18-2003, 07:56 AM Perhaps this will help.
http://www.visualbasicforum.com/showthread.php?t=92130
Kaveh_1972 10-19-2003, 05:05 AM 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.
cliff_m01 10-19-2003, 05:46 AM 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.
HiTmAN 10-19-2003, 06:30 AM 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:
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:
ShortPath = GetShortName(LongPath)
Hope it helps
cliff_m01 10-19-2003, 02:04 PM Thanks Hitman. You solution is definately more elegant than my potential solution. I will try this out in my project.
Kaveh_1972 10-20-2003, 04:49 AM Thank you HiTmAN! I'll try on it.
Kaveh_1972 10-20-2003, 09:21 AM 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!
Kaveh_1972 10-26-2003, 01:52 AM Well, It seems I can find the best way. Which is using ShellExecute() API funcion.
Ross02 10-26-2003, 02:41 AM yea go with the shellExecute...
ShellExecute GetDesktopWindow, "open", "d:\program files\acd system\acdsee\5.0\acdsee5.exe", "", "D:\", 5
-Ross
|