Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Work with console commands

Status
Not open for further replies.

nandoliveira

Programmer
Jun 18, 2008
5
LT
Hi, I'm new using VB and I need some help creating a little program to make backup of my servers...

My application need to execute some commands in the console, check if they are executed with success or not (register all this in one file) and after close the console, all this should be automatic without need of the user do anything.

So the application should be something like:
--> in the console stop two server [net stop (server name)]
--> if that is successful it will execute other commands... if they are successful other more... and so on...

==>> At the same time i should write in one file something like:
Command XXXX ==>> executed or fail, start processing: 10h30m end processing 11h20m

I never use VB to write and read from the console, so i would be very grateful if someone can help...

Thanks for the attention

 
Have a look at System.Diagnostics.Process and the various properties of the StartInfo class. That should give you all you need.

[vampire][bat]
 
Is possible to give some example where one command is executed and after the result read?
 
A quick example, not specifically what you are looking for, but should point you in the right direction:

Code:
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		RichTextBox1.Clear()
		Dim p As New Process
		Dim psi As ProcessStartInfo = p.StartInfo
		psi.Arguments = "/C Dir C:\"
		psi.FileName = "cmd"
		psi.RedirectStandardOutput = True
		psi.UseShellExecute = False
		p.Start()
		p.WaitForExit()
		RichTextBox1.AppendText(p.StandardOutput.ReadToEnd)
		RichTextBox1.AppendText(Environment.NewLine + "================================================" + Environment.NewLine)
		psi.Arguments = "/C Dir ""C:\Program Files\"""
		p.Start()
		p.WaitForExit()
		RichTextBox1.AppendText(p.StandardOutput.ReadToEnd)

	End Sub
End Class



[vampire][bat]
 
thanks... it was looking for one example to get the idea of how it works :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top