Dim psi As New ProcessStartInfo("C:\batch.exe or .bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim process As Process = Process.Start(psi)
Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process
startInfo = New System.Diagnostics.ProcessStartInfo("C:\my.bat")
pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()
Date :
2016-08-24 10:59:06
By :
mr.win
No. 3
Guest
D:\ = คือไดร์ที่อยู่ของ bat file
testbat.bat : คือชื่อ bat file
------------------------------------------ C# Source Code Code (C#)
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process proc = null;
try
{
string batDir = string.Format(@"D:\");
proc = new Process();
proc.StartInfo.WorkingDirectory = batDir;
proc.StartInfo.FileName = "testbat.bat";
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
MessageBox.Show("Bat file executed !!");
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
}
}
}
}
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim proc As Process = Nothing
Try
Dim batDir As String = String.Format("D:\")
proc = New Process()
proc.StartInfo.WorkingDirectory = batDir
proc.StartInfo.FileName = "testbat.bat"
proc.StartInfo.CreateNoWindow = False
proc.Start()
proc.WaitForExit()
MessageBox.Show("Bat file executed !!")
Catch ex As Exception
Console.WriteLine(ex.StackTrace.ToString())
End Try
End Sub
End Class