How to make Batch file(.bat) through vb?
Hello,
Now I want to make one batch file through vb application. and than after completion of creating batch file, it wiil be called through vb application.
I have tried some code but it didint work:
Private Sub CmdTrial_Click()
Dim Str11 As String
Str11 = "cd C:\Dev\tti\build"
Open "c:\unregister.bat" For Append As #1
Write #1, Str11
Write #1, "Pause"
Close
End Sub
Thanks in advance.
# 1 Re: How to make Batch file(.bat) through vb?
Try This
Public Function Create_Batch_File(byval path as string, byval filename as string ) As Boolean
On Error GoTo X
Dim FSO As FileSystemObject
Dim F1 As TextStream
Set FSO = New FileSystemObject
Set F1 = FSO.OpenTextFile( path & filename , ForWriting, True, TristateFalse)
'' what ever you want to write in it
F1.WriteLine "@ECHO OFF"
F1.WriteLine "cd C:\Dev\tti\build"
F1.WriteLine "PAUSE"
F1.WriteBlankLines 1
F1.Close
Set F1 = Nothing
Set FSO = Nothing
Create_Batch_File = True
Exit Function
X:
If Err.Number <> 0 Then
Create_Batch_File = False
End If
End Function
After this you can call this function
if Create_Batch_File ( "C:\" , "unregister.bat" ) then
'' Now call the batch file
Shell "c:\unregister.bat ", vbNormalFocus
end if
It work for me , should work for you !!!
# 2 Re: How to make Batch file(.bat) through vb?
Try Print vs Write. Print won't add the quotes around the lines which is causing your batch to fail. Then use the Shell command to activate the batch.