How to call batch file from VB6.0.
Hi,
I have created batch file (plz see bellow). This batch file copy the text file from FTP server.
I have bellow query:
1. This bellow batch file how to call from VB6.0 application (Not in .Net appln).
2 .And how to copied file (from FTP) has to store in specific folder in local pc.
3. Can i use the same batch file for SFTP server also to do the same job.
Batchfile:
open 2.121.121.23
userid
password
lcd d:\ etc...
get test.txt
bye
Many thanks in Advance :thumb:
Radhakrishnan
Re: How to call batch file from VB6.0.
VB Code:
Shell "c:\pathTo.bat", vbNormalFocus
Re: How to call batch file from VB6.0.
Or if your file path will have spaces in it then you will need to double up on the double quotes depending on its needs or just use ShellExecute API.
VB Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMINIMIZED As Long = 2
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Sub Command1_Click()
On Error GoTo MyError
Dim lRet As Long
lRet = ShellExecute(Me.hwnd, "Open", "CMD.exe", "C:\Test.bat", "C:\", SW_SHOWNORMAL)
If lRet <= 32 Then
MsgBox "Error Shelling bat file"
End If
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description
End Sub
Re: How to call batch file from VB6.0.
Thanks a lot for your reply. Your code working fine.
Can you give the direction to do the following :
I want to create batch file from VB6.0 application. In that creating batch file i have to pass the userid, password, FTP server Ip address.
Thank you once again..
Radhakrishnan
Re: How to call batch file from VB6.0.
Using basic File I/O you can write the bat file. Its nothing more then a text file with a bat extension.
VB Code:
Open "C:\Test.bat" For Output As #1
Print #1, "Dir C:\"
Close #1
'...
'/K keeps the console window open (optional)
lRet = ShellExecute(Me.hwnd, "Open", "CMD.exe", " /K C:\Test.bat", "C:\", SW_SHOWNORMAL)
Re: How to call batch file from VB6.0.
Quote:
Originally Posted by RadhakrishnanR
Thanks a lot for your reply. Your code working fine.
Can you give the direction to do the following :
I want to create batch file from VB6.0 application. In that creating batch file i have to pass the userid, password, FTP server Ip address.
Thank you once again..
Radhakrishnan
Something like this, maybe?
VB Code:
Option Explicit
Private Sub CreateBatch(ByVal SaveAs As String, ByVal FTPServer As String, ByVal UserID As String, ByVal Password As String)
Dim lonFF As Long, strBatch As String
strBatch = "open " & FTPServer & vbNewLine
strBatch = strBatch & "user " & UserID & vbNewLine
strBatch = strBatch & "pass " & Password & vbNewLine
lonFF = FreeFile
Open SaveAs For Binary Access Write As #lonFF
Put #lonFF, , strBatch
Close #lonFF
strBatch = ""
End Sub
Private Sub cmdMakeBatch_Click()
CreateBatch "C:\batch.bat", "localhost", "userid", "password"
End Sub