-
September 19th, 2007, 05:27 AM
#1
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.
-
September 19th, 2007, 06:11 AM
#2
Re: How to make Batch file(.bat) through vb?
Try This
Code:
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
Code:
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 !!!
-
September 19th, 2007, 06:56 AM
#3
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.
Insomnia is a simple byproduct of "it can't be done"
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
|