rem 结束程序进程
TASKKILL /F /IM test.exe
rem 删除C:\test下的文件
del C:\test\*.* /f/s/q/a
rem 从局域网共享目录拷贝程序文件
xcopy \\192.168.1.1\test\*.* C:\test\ /s /e
rem 启动程序服务
net start testService
c# call bat
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Test
{
class UpdateIDL
{
public static void Update()
{
Process proc = null;
try
{
string targetDir = string.Format(@"C:\Users\Administrator\Desktop\");//这是bat存放的目录
string targetDir1 = AppDomain.CurrentDomain.BaseDirectory; //或者这样写,获取程序目录
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "update.bat";//bat文件名称
proc.StartInfo.Arguments = string.Format("10");//this is argument
//proc.StartInfo.CreateNoWindow = true;
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//这里设置DOS窗口不显示,经实践可行
proc.Start();
proc.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
}
}
}
}