Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Problem with Shell() Command


Reply
 
Thread Tools Display Modes
  #1  
Old 10-18-2003, 07:25 AM
Kaveh_1972's Avatar
Kaveh_1972 Kaveh_1972 is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Iran
Posts: 209
Default 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
Reply With Quote
  #2  
Old 10-18-2003, 07:56 AM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

Reply With Quote
  #3  
Old 10-19-2003, 05:05 AM
Kaveh_1972's Avatar
Kaveh_1972 Kaveh_1972 is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Iran
Posts: 209
Default

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
Reply With Quote
  #4  
Old 10-19-2003, 05:46 AM
cliff_m01 cliff_m01 is offline
Regular
 
Join Date: Oct 2003
Location: Penticton, B.C. Canada
Posts: 83
Default

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.
Reply With Quote
  #5  
Old 10-19-2003, 06:30 AM
HiTmAN's Avatar
HiTmAN HiTmAN is offline
Contributor
 
Join Date: Mar 2003
Location: The FSB
Posts: 570
Default

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
__________________
MSDN is your friend.

3L Designs
Reply With Quote
  #6  
Old 10-19-2003, 02:04 PM
cliff_m01 cliff_m01 is offline
Regular
 
Join Date: Oct 2003
Location: Penticton, B.C. Canada
Posts: 83
Default

Thanks Hitman. You solution is definately more elegant than my potential solution. I will try this out in my project.
Reply With Quote
  #7  
Old 10-20-2003, 04:49 AM
Kaveh_1972's Avatar
Kaveh_1972 Kaveh_1972 is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Iran
Posts: 209
Default

Thank you HiTmAN! I'll try on it.
__________________
Nobody's perfect
Reply With Quote
  #8  
Old 10-20-2003, 09:21 AM
Kaveh_1972's Avatar
Kaveh_1972 Kaveh_1972 is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Iran
Posts: 209
Default

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
Reply With Quote
  #9  
Old 10-26-2003, 01:52 AM
Kaveh_1972's Avatar
Kaveh_1972 Kaveh_1972 is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Iran
Posts: 209
Default

Well, It seems I can find the best way. Which is using ShellExecute() API funcion.
__________________
Nobody's perfect
Reply With Quote
  #10  
Old 10-26-2003, 02:41 AM
Ross02 Ross02 is offline
Regular
 
Join Date: Oct 2003
Posts: 85
Default

yea go with the shellExecute...

Code:
ShellExecute GetDesktopWindow, "open", "d:\program files\acd system\acdsee\5.0\acdsee5.exe", "", "D:\", 5

-Ross
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with shell command bzeela General 3 09-18-2003 08:27 AM
shell command - process termination holdemfoldem General 2 08-29-2003 11:42 AM
Problem with Shell command fandecine General 5 08-20-2003 12:07 PM
Problem with shell command and perl Wendigo2002 General 2 08-18-2003 09:02 AM
Problem with shell command! Latac General 16 06-25-2003 12:37 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->