如何使用c#.net windows服务执行bat文件? [英] How to execute bat file, using c# .net windows service?

查看:345
本文介绍了如何使用c#.net windows服务执行bat文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



如何通过c#.net windows服务执行bat文件?



我有一个bat文件,我想运行bat文件,当我的Windows服务它将启动。



怎么可能。



请帮帮我。

谢谢

Ankit Agarwal。

Hello,

How to execute bat file, through c# .net windows service?

I have a bat file, I want to run bat file, when my windows service it will be start.

How could that possible.

Please help me.
Thanks
Ankit Agarwal.

推荐答案

只需将其作为Process.Start的目标提供:

Just provide it as a target of Process.Start:
System.Diagnostics.Process.Start(@"C:\MyBatchFiles\MyBatch.bat");


C# Process.Start [ ^ ]

System.Diagnostic.Process.Start-Process类 [ ^ ]



C# Process.Start[^]
System.Diagnostic.Process.Start-Process class[^]

using System.Diagnostics;

class Program
{
    static void Main()
    {
    //
    // Use Process.Start here.
    //
    Process.Start("C:\Users\pant\Documents\myfile.bat");
    }
}


这篇关于如何使用c#.net windows服务执行bat文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆