c# 调用cmd带参数 读取配置文件 2021-10-29

c# 调用cmd及参数

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Web;

namespace WebApplication2
{
    /// <summary>
    /// runexe 的摘要说明
    /// </summary>
    public class runexe : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            try
            {
                //string exe_path = "D:\\dll\\test_dll6\\test_dll\\test_dll.exe";  // 被调exe
                //string[] the_args = { "D:\\dll\\test_dll6\\test_dll\\input.txt" };   // 被调exe接受的参数
                string exe_path = ConfigurationManager.AppSettings["exe"].ToString();
                string[] the_args = ConfigurationManager.AppSettings["args"].ToString().Split(';');

                StartProcess(exe_path, the_args);
                context.Response.Write("Hello World");
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        // 调用exe的函数
        public bool StartProcess(string runFilePath, params string[] args)
        {
            string s = "";
            foreach (string arg in args)
            {
                s = s + arg + " ";
            }
            s = s.Trim();
            Process process = new Process();//创建进程对象    
            ProcessStartInfo startInfo = new ProcessStartInfo(runFilePath, s); // 括号里是(程序名,参数)
            process.StartInfo = startInfo;
            process.Start();
            return true;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
V10 2.05 修复了一下小bug,应某些人要求将CMD窗口封装起来了,以便更好的读取错误信息,当已经连接错误弹出时程序不再自动关闭。。 By Zhangzhezh 2010-11-20 V9 2.05 当勾选了自动连接并且已经连接至互联网的情况下程序不会再自动连接也不会关闭了,修正了界面里IP信息显示超界的问题, 当自动连接失败时会返回主界面,界面体验的优化,加入了IPV6 ISATAP隧道快速设置功能(测试)。。 By Zhangzhezh 2010-11-20 V8 2.05 修正自动连接功能的返回消息错误,重新布局界面,添加快速访问网络连接路径, 应大众要求讲dialerconfig.xml中的密码加密了,不再明文保存了,还有些小Bug优化。。 By Zhangzhezh 2010-11-19 V7 2.05 修复在Win7 64位下自动创建拨号点出错的问题!! 主界面重新排版,IP设置界面加入了例外处理,加入链接状态显示,加入断开连接功能,再次增加检测等待时间,以免遇到不准确的连接不成功提示。。 优化了部分代码,修正一下小Bug。。 By Zhangzhezh 2010-11-10 V6 2.05 将MAC修改功能用C#实现了,可能还不太完善,浏览器调用默认的,不启动IE了,完善主机客户机设置功能,允许设置不同的主机。。 加入网卡选择判断机制,不会连虚拟机网卡的MAC和IP也改了,抓取网卡准确度也提高了,拨号点每次会自动建立,不用再手工创建了。。 By Zhangzhezh 2010-11-6

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值