一、

try
{
//方法一
//调用自己的exe传递参数
//Process proc = new Process();
//proc.StartInfo.FileName = @"D:\\hotelsoft\\zk.exe";
//proc.Start();
//Thread.Sleep(3000);//暂停3秒
//foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("zk"))
//{
// 查找并关闭进程
// pro.Kill();
//} //方法二
ProcessStartInfo startInfo = new ProcessStartInfo(@"D:\\hotelsoft\\zk.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}

二、

//调用外部程序导cmd命令行
    Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.CreateNoWindow = false;
    p.Start(); 
    / /向cmd.exe输入command 
    p.StandardInput.WriteLine("cd C:\\Inetpub\\wwwroot\\Paicdom\\PaWebService\\PaWeb\\Manage\\Exportcsv");
    //cmd又调用了ociuldr.ex
    p.StandardInput.WriteLine("ociuldr.exe");
    p.StandardInput.WriteLine("exit"); //需要有这句,不然程序会挂机
    //string output = p.StandardOutput.ReadToEnd(); 这句可以用来获取执行命令的输出结果

我在ASP.NET中调用,一直想看看到执行窗口,但无论怎么设置参数,都看不到。不知如何。

三、

C#程序作为调用这需要生成一个Progress类,该类提供了调用EXE可执行文件所用到的属性和事件.System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process();
pExecuteEXE.StartInfo.FileName = @"E:\Delphi.exe";
pExecuteEXE.StartInfo.Arguments = "'paramstr1 paramstr2,paramstr3'";
pExecuteEXE.Start();
pExecuteEXE.WaitForExit();//无限期等待完成
//pExecuteEXE.WaitForExit(10000);//等待最长10秒钟完成。Delphi可执行程序作为被调用程序,主要是接收参数信息,执行程序,由于程序执行程序完毕不能返回给调用程序信息,只能将信息写入某一位置等待调用者读取。
procedure    TForm1.Button1Click(Sender:    TObject);   
    
var   
       i:integer;   
begin   
     self.Caption   :='';   
    for i:=0 to paramcount do
     begin   
         self.Caption   :=self.Caption+ '['+inttostr(i)+':'+paramstr(i)+']';   
     end;   
    
end;   

完成后退出。

这里是一个简单的调用例子,可以效仿:
*   功         能:通过C#程序调用   Windows   记事本程序   编辑一个
*   名为   test.txt   的文本文件。
*
*   在整个程序中   System.Diagnostics.Process.Start(Info)  
*   为主要语句。
*   如果只是单独执行一个外部程序,可用一条如下代码即可:
*   System.Diagnostics.Process.Start(
*   "外部程序名","启动参数");
*/

using   System;

class   test
{
static   void   Main()
{

//声明一个程序信息类
System.Diagnostics.ProcessStartInfo   Info   =   new   System.Diagnostics.ProcessStartInfo();

//设置外部程序名
Info.FileName   =   "notepad.exe";

//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments   =   "test.txt";

//设置外部程序工作目录为   C:\
Info.WorkingDirectory   =   "C:\\";

//声明一个程序类
System.Diagnostics.Process   Proc   ;

try
{
//
//启动外部程序
//
Proc   =   System.Diagnostics.Process.Start(Info);
}
catch(System.ComponentModel.Win32Exception   e)
{
Console.WriteLine("系统找不到指定的程序文件。\r{0}",   e);
return;
}

//打印出外部程序的开始执行时间
Console.WriteLine("外部程序的开始执行时间:{0}",   Proc.StartTime);

//等待3秒钟
Proc.WaitForExit(3000);

//如果这个外部程序没有结束运行则对其强行终止
if(Proc.HasExited   ==   false)
{
Console.WriteLine("由主程序强行终止外部程序的运行!");
Proc.Kill();
}
else
{
Console.WriteLine("由外部程序正常退出!");
}
Console.WriteLine("外部程序的结束运行时间:{0}",   Proc.ExitTime);
Console.WriteLine("外部程序在结束运行时的返回值:{0}",   Proc.ExitCode);
}
}

ASP.NET、C#调用外部可执行exe文件--多种方案的更多相关文章

  1. Matlab中调用VS编译的exe文件并传递变量 的方法

    经历::在网上找了很多方法,都没有实现在matlab中调用vs的exe文件并且能够传递变量参数,一些小细节花费了自己很多时间,比喻忽略了一些空格!  网上很多的方法都是纯粹复制别人的方法,自己都没有去 ...

  2. Python:构建可执行exe文件

    学习自: Python 程序打包成 exe 可执行文件 - 不夜男人 - 博客园 Python生成Windows可执行exe文件 - 韩小北 - 博客园 pyinstaller参数介绍以及总结_Bea ...

  3. c# Winform 调用可执行 exe 文件

    c#是一个写windows桌面小工具的好东西,但有个时候,我们需要在 winform 程序中调用其他的 exe 文件,那么该如何实现呢? 如果只是拉起一个 exe 文件,可以参考如下方法实现: str ...

  4. linux上jenkins连接windows并执行exe文件

    1.如果要通过ssh的方式来连接windows的话,首先需要在windows上安装freesshd来配置启动.配置ssh(win10上自带了openssh可以进行安装使用,但我机器装不上) 1.1.下 ...

  5. linux系统执行.exe文件

    首先要了解一下Wine: Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如 Linux,Mac OSX 及 ...

  6. Python生成Windows可执行exe文件

    环境 python3.6.5 pyinstaller3.5 windows 10 下载地址 python:https://www.python.org/ftp/python/3.6.5/python- ...

  7. python制作电脑可执行exe文件

    python获取IP.主机名.mac地址 关注公众号"轻松学编程"了解更多. 制作get_IP.py文件: import socket import uuid # 获取主机名 ho ...

  8. shell调用sqlplus批量执行sql文件

    在最近的工作中,经常需要批量执行一些DML, DDL, PL/SQL语句或导入一些Function, Procedure.因为support的国家比较多,常常需要一个登陆到一个国家的数据库上执行完成后 ...

  9. python生成可执行exe文件

    为什么要生成可执行文件 不需要安装对应的编程环境 可以将你的应用闭源 用户可以方便.快捷的直接使用 打包工具 pyinstaller 安装pyinstaller pip install pyinsta ...

随机推荐

  1. uC/OS-II应用程序代码

    /*************************************************************************************************** ...

  2. css007 margin padding border

    css007 margin padding border 1.理解盒模型(盒模型:就是把一些东西,包括html各种标签都包含在一个 看不见的盒子里) 1/在web浏览器中任何标签都是一个盒子,内容的周 ...

  3. 使用MVC过滤器保存操作日志

    //定义过滤器 public class  LogAttribute : ActionFilterAttribute { /// <summary> /// 以逗号间隔 /// </ ...

  4. jQ选择器学习片段(JavaScript 部分对应)

    $()函数在大多的JavaScript类库中都被作为一个选择器函数来使用,在jQuery中就是. $("#id")通过id来获取元素,用来代替document.getElement ...

  5. BIOS设置第一启动项

    在电脑的Bois中怎样去设置第一启动项.. 对于很多新手朋友来说,BIOS满屏英文,生涩难懂,话说我原来也很排斥BIOS,界面太丑,光看界面就没什么兴趣,更谈不上深入研究,大多数人在电脑城装机的时候都 ...

  6. fcc的中级算法题

    核心提示:这是网上开源编程学习项目FCC的javascript中级编程题(Intermediate Algorithm Scripting(50 hours)),一共20题.建议时间是50个小时,对于 ...

  7. C++ 生成 dll 和调用 dll 的方法实例(转)

    1)生成dll 建立两个文件 xxx.h , xxx.cpp xxx.h内容如下: #ifdef BUILD_XXX_DLL#define EXPORT __declspec(dllexport)#e ...

  8. <?xml version="1.0" encoding="utf-16"?>. use different encoding

    public string Serialize<T>(T serializeClass) { string xmlString = string.Empty; try { if (seri ...

  9. msbuild FileSysExcludeFiles

    <?xml version="1.0" encoding="utf-8"?> <!-- This file is used by the pu ...

  10. PageBase

    namespace Webform.App { public class PageBase : System.Web.UI.Page { } public interface IService< ...