A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 章坚 黑马帝   /  2011-11-7 12:51  /  2144 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

最近在标签打印程序中   需要开启WINDOWS服务
不多说   代码  
private void StartService()
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            string a = "net start " + "\"Commander Service\"";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();
            p.StandardInput.WriteLine(a);

            p.StandardInput.WriteLine("exit");  
            p.WaitForExit();
            p.Close();
        
        }

评分

参与人数 1技术分 +1 收起 理由
陈涛 + 1 赞一个!

查看全部评分

1 个回复

倒序浏览
不错, 以后肯定能用到.
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马