batch files

thexero

Active member
Joined
Jan 27, 2007
Messages
26
Programming Experience
3-5
hi

how can i create a program in vb.net with a form and when you click a button executes a batch file?
 
my windup program works :)

it starts up and says windows has been updated and needs to restart lol and i am going to put it in the startup objects of my brothers comp lol

VB.NET:
Shell(shutdown -r[SIZE=2])[/SIZE]

thanx
 
Last edited:
instead of using Shell() I would recamend using System.Diagnostics.Process.Start() as it's the .Net way of achieving this, but also you get more flexibility should you need to have your current code do more later
 
thanks for your help

how do i get my program to create the batch file? would it be something like this

system.diagnostics.process.open("c:\bat.bat")
system.diagnostics.process.write("c:\bat.bat" "netstat")

thanx
 
HERE IS ONE WAY:

Dim ShellCommand As String
'create the batch file
ShellCommand += "sort "
ShellCommand += Input_To_Sort_File_4
ShellCommand += " /o "
ShellCommand += Production_xxxxx_File_1
'
OpenOutput_Batch_Sort_File_5()
PrintLine(5, Directory & vbCrLf & ShellCommand)
FileClose(5)
Try
Shell(Batch_Sort_File_5, AppWinStyle.MinimizedNoFocus, _
True, 100000)
Catch ex As Exception
MsgBox("Unable to Run Batch Sort - " & ex.ToString, _
MsgBoxStyle.RetryCancel, _
".bat or .txt or .srt File Problem? Name? Location?")
End Try


================================
Where 'Batch_Sort_File_5', 'Directory',
'Input_To_Sort_File_4', and 'Production_File_1'
are defined previously .
As:
Public Directory As String = _
"C:\xxxxx\zzzzzzz\"
Public Production_xxxxx_File_1 As String = _
Directory & "xx.txt"
Public Input_To_Sort_File_4 As String = _
Directory & "xx.srt"
Public Batch_Sort_File_5 As String = _
Directory & "xsort.bat"
 
VB.NET:
Imports System.IO
'NameSpace required to be imported to work with files
Public Class Form1 Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
Dim fs as New FileStream("file.doc", FileMode.Create, FileAccess.Write)
'declaring a FileStream and creating a word document file named file with 
'access mode of writing
Dim s as new StreamWriter(fs)
'creating a new StreamWriter and passing the filestream object fs as argument
s.BaseStream.Seek(0,SeekOrigin.End)
'the seek method is used to move the cursor to next position to avoid text to be
'overwritten
s.WriteLine("This is an example of using file handling concepts in VB .NET.")
s.WriteLine("This concept is interesting.")
'writing text to the newly created file
s.Close()
'closing the file
End Sub
End Class

Just change the extentions to .bat and you are good to go... just use the write line to insert your Netstart commands or whatever...
I got this from http://www.startvbdotnet.com/files/default.aspx
 
Back
Top