Batch file execution

i have been running a program in VB that zips a bunch of files from different locations and ftp's the resulting file to multiple ftp sites. I have the program execute a batch file which runs several txt files within the ftp protocal.

Recently win 2k was updated on the network, now the dos window will only stay alive for less then a second before it is destroyed. From what i can tell, none of the commands are run anymore (tested this using a simple net send to my own machine)

The app works fine still on XP, any ideas???

martynlathAsked:
Who is Participating?
 
moduloConnect With a Mentor Commented:
PAQed - no points refunded (of 125)

modulo
Community Support Moderator
0
 
sirbountyCommented:
How are you calling the batch file?
Precede it with
 CMD /C
if not already...

To test it though- precede with CMD /K (window stays open)...
0
 
martynlathAuthor Commented:
Shell (App.Path & "\ftp.bat")
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
martynlathAuthor Commented:
could you be more clear on where to put CMD /K or /C please?



0
 
sirbountyCommented:
Try shell ("CMD /K " & App.Path & "\ftp.bat")
This should at least leave the window open so you can determine where it's failing...
Can you post ftp.bat here or is it lengthy?
0
 
martynlathAuthor Commented:
batch file example:

cd\
ftp -s:"C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript.txt"
ftp -s:"C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript2.txt"
ftp -s:"C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript3.txt"
exit

example of txt file:

open 69.93.83.218
anonymous
me@you.com
binary
cd pub
cd work
put "C:\Documents and Settings\Profile 1\Desktop\dailyupdate.zip"
bye
0
 
martynlathAuthor Commented:
the problem appears to be that the batch file is being called from a directory with a space in the name. Any ideas how to stop make the whole path into a string in vb.

Dim t As String
t = """"
Shell ("CMD /K " & t & App.Path & t & "\ftp.bat")

This does not appear to work and i am unsure of another solution
0
 
martynlathAuthor Commented:
the reason the file batch file above worked is because there is no spaces in the file name. when testing it on the win 2k machine it became evident.
0
 
sirbountyCommented:
A couple of different ways to do it - but probably the easiest would be

Shell ("CMD /C " & chr(34) & app.path & "\ftp.bat" & chr(34))
This will enclose the string in quotes...
0
 
martynlathAuthor Commented:
that did not seem to improve the issuse.

it still stops at "C:/Program"

its trying to find the program files directory
0
 
sirbountyCommented:
Strange - that works for me...
Could you paste that line here - also, what does App.path resolve to?
0
 
sirbountyCommented:
This code should generate the LFN for you...
'[BEGIN CODE]
Option Explicit

Const MAX_PATH = 206

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
   
Private Declare Function GetModuleFileName Lib "kernel32" _
    Alias "GetModuleFileNameA" (ByVal hModule As Long, _
    ByVal lpFileName As String, ByVal nSize As Long) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" _
    Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long
   
Private Declare Function GetSystemDirectory Lib "kernel32" _
    Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long

Private Declare Function GetShortPathName Lib "kernel32" _
    Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
    ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long


Private Sub Form_Load()
 Dim myHandle As Long, myResult As Long, strLFNPath As String
 strLFNPath = Space$(MAX_PATH)
 myHandle = GetModuleHandle(App.EXEName)
 myResult = GetModuleFileName(myHandle, strLFNPath, MAX_PATH)
 MsgBox strLFNPath
End Sub
'[END CODE]
0
 
martynlathAuthor Commented:
app.path = C:\program files\temp files
lfn = C:\program files\temp files\vbzip.exe
bat file = C:\program files\temp files\ftp.bat
 
0
 
martynlathAuthor Commented:
although it says thats the error, ive noticed that the prompt points at the correct directory. so if we can carrage return the file name part. maybe that will improve the situation?
0
 
sirbountyCommented:
vbcrlf will do that...but I'm not certain I follow what you meant there...
The shell prompt from cmd /k brings you to the right path?
0
 
martynlathAuthor Commented:
yes. although it suggests the error is in the path. though it wont run the file name. but if you type it in manually after it runs the batch file
0
 
sirbountyCommented:
martynlath,
Try specifying the full path for ftp in your batch file...
Something like

%systemroot%\system32\ftp -s "C:\PROJECT-WORK\PROGRAMS\COMBINED-ZIP-FTP\myscript.txt"

0
 
martynlathAuthor Commented:
good news got it working. though CMD /C doesnt run. Any idea why?

i ran it without the app.path. as it is already in the directory by default.
easy fix for that issuse :-)

/c doesnt appear to run at all though. not even in system processes.

nearly there..
0
 
sirbountyCommented:
CMD /C doesn't run?  Have you tried it just from a command line?
Do you get an error?  Probably irrelevant now though.
When you say nearly there... what's left?
0
 
martynlathAuthor Commented:
correction. it needs the app path. it will only run first time otherwise. then the path is incorrect afterwards
0
 
sirbountyCommented:
So, it's still not working?  I'm a bit confused now... :(

Can you step through your code and try a debug.? of the following line:

debug.? "CMD /C " & chr(34) & app.path & "\ftp.bat" & chr(34)

Thanx.
0
 
martynlathAuthor Commented:
the APP  works correctly the first time round. but from then on the folder path cannot be changed. keeps saying internal or external command not recognised. i even tried spliting the commands up over 3 batch files

Dim d, e, f As String
d = Left$(App.Path, 2)
e = Right$(App.Path, (Len(App.Path) - 3))
f = Left$(e, (Len(e) - 8))

'8 = length of "\ftp.bat"

Shell ("CMD /K" & d & "|" & "EXIT" & "|")
Shell ("CMD /K" & "cd/" & "|" & "EXIT" & "|")
Shell ("CMD /K" & "cd/" & f & "|" & "EXIT" & "|")
Shell ("CMD /K " & d & "/" & f & "ftp.bat")

 

i need a piece of code that will get me to that file given any senario, including the prompt starting on a different drive letter. I believe my close, but not quite sure what im doing wrong.
0
 
JSunnCommented:
Instead of cmd /c in scripting use %COMSPEC% /C
This is a environmental varialble for your cmd.exe file. Better to use this when the script will
be run on multiple OS types.
What is the exact path to the files you want to access?
0
 
sirbountyCommented:
Hmm - I'd hate to see this one trashed after all the time put into it...
martynlath - any update?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.