?
Solved

VB6 - Problem using the shell command to kick off a batch file.

Posted on 2003-02-25
4
Medium Priority
?
920 Views
Last Modified: 2008-02-26
Hi,

I'm running the following code from a VB6 application -
it's meant to kick off a ftp batch file I've created:

Shell App.Path & "\ftp.bat", vbNormalFocus

I'm using NT 4 and when I run the VB code the DOS window appears for a split second then disappears without executing the commands inside.  The ftp batch file should take around 20 seconds to process.  

If I manually double-click the batch file it works fine.
Any ideas?
0
Comment
Question by:rbruce5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:rbruce5
ID: 8015534
I've managed to get my initial problem working.  I used:

####
Shell "cmd /K" & App.Path & "\ftp.bat", vbNormalFocus
####

However, there appears to be a long filename issue.  The content of the batch file is:

#####
C:\winnt\system32\ftp.exe -v -s:"C:\Program Files\EPFU Packager\temp\ftp.txt"
#####

 - it uses a text file that contains the ftp commands:



The whole thing works fine if I put my batch file and txt file in a directory with a short filename - e.g., c:\ftptest\, but as soon as I try running it from Program Files\EPFU Packager\ directory it doesn't work.



0
 
LVL 2

Expert Comment

by:IeuanJ
ID: 8015788
sometimes command line operationg have problems with directories containing spaces.  e.g. c:\program files\, so it is best to contain them within quotes e.g. "c:\program files\".

you do this within your bat file but not within the VB code, try something like.

Shell "cmd /K """ & App.Path & "\ftp.bat""", vbNormalFocus

Can't guarentee this is your problem without taking a closer look but is a small change and worth a try.
0
 
LVL 1

Accepted Solution

by:
xThorx earned 200 total points
ID: 8016240
In fact most of the time, it's better to use small path to files. So you have to give the dos based path to the function Shell. You can use this code to retreive the short path to a file:

As you might see, this code wasn't mine but it works perfectly.


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: http://www.allapi.net/
    '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

Hope this help.

Regards
0
 

Author Comment

by:rbruce5
ID: 8016481
xThorx,

Bingo!  Thanks for your help - it works perfectly.

Thanks to all who commented

rbruce
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question