|
-
Oct 27th, 2006, 12:56 AM
#1
Thread Starter
Junior Member
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
Radhakrishnan
-
Oct 27th, 2006, 12:59 AM
#2
Re: How to call batch file from VB6.0.
VB Code:
Shell "c:\pathTo.bat", vbNormalFocus
-
Oct 27th, 2006, 01:53 AM
#3
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 27th, 2006, 02:42 AM
#4
Thread Starter
Junior Member
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
-
Oct 27th, 2006, 02:47 AM
#5
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)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 27th, 2006, 02:52 AM
#6
Re: How to call batch file from VB6.0.
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|