asp.net调用exe并传递参数然后关闭exe[转]
2013-09-18 07:58
429 查看
/article/4789824.html
先用C#写个简单的exe,这里我就用winForm
Program.cs这里加了个启动参数
大气象
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(args));
}
}
}
大气象
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(string[] s)
{
InitializeComponent();
if (s.Length > 0)
MessageBox.Show(s[0]);
if (s.Length > 1)
MessageBox.Show(s[1]);
}
}
}
大气象
protected void btnCount_Click(object sender, EventArgs e)
{
//调用记事本
//System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");
try
{
//调用自己的exe传递参数
Process proc = new Process();
string sPath = Request.MapPath("~");//取得物理路径
proc.StartInfo.FileName = sPath + @"\hi.exe";
proc.StartInfo.Arguments = "参数1 参数2";
proc.Start();
Thread.Sleep(5000);//暂停3秒
foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("hi"))
{
pro.Kill();
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
大气象
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FileInfo f = new FileInfo(@"D:\hi.txt");
StreamWriter w = f.CreateText();
string s = "0";
if (args.Length > 0)
s = "123";
w.WriteLine("dddd" + s);
w.Close();
}
}
}
大气象
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
[DllImport("shell32.dll ")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder("hi"), new StringBuilder("jjj"), new StringBuilder(@"D:\"), 1);
return "Hello World";
}
}
这是目前asp.net调用exe找到的正确运行的方法。放在IIS中正确运行。
先用C#写个简单的exe,这里我就用winForm
Program.cs这里加了个启动参数
大气象
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(args));
}
}
}
大气象
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(string[] s)
{
InitializeComponent();
if (s.Length > 0)
MessageBox.Show(s[0]);
if (s.Length > 1)
MessageBox.Show(s[1]);
}
}
}
大气象
protected void btnCount_Click(object sender, EventArgs e)
{
//调用记事本
//System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");
try
{
//调用自己的exe传递参数
Process proc = new Process();
string sPath = Request.MapPath("~");//取得物理路径
proc.StartInfo.FileName = sPath + @"\hi.exe";
proc.StartInfo.Arguments = "参数1 参数2";
proc.Start();
Thread.Sleep(5000);//暂停3秒
foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("hi"))
{
pro.Kill();
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
大气象
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FileInfo f = new FileInfo(@"D:\hi.txt");
StreamWriter w = f.CreateText();
string s = "0";
if (args.Length > 0)
s = "123";
w.WriteLine("dddd" + s);
w.Close();
}
}
}
大气象
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
[DllImport("shell32.dll ")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder("hi"), new StringBuilder("jjj"), new StringBuilder(@"D:\"), 1);
return "Hello World";
}
}
这是目前asp.net调用exe找到的正确运行的方法。放在IIS中正确运行。
相关文章推荐
- asp.net调用exe并传递参数然后关闭exe
- asp.net调用exe并传递参数然后关闭exe
- ASP.net动态调用非托管DLL的参数传递问题
- asp.net中调用用户控件中的函数并传递参数
- PHP通过传递对象参数调用asp.net Webservice 服务
- asp.net中调用用户控件中的函数并传递参数
- 【问题】Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数
- 再谈 asp.net 客户端调用服务器端事件并传递参数
- ASP.net动态调用非托管DLL的参数传递问题
- Asp.net ajax 调用WebService 用userContext 传递不了参数的错误
- asp.net中网页间传递参数用什么方法比较
- 使用Ext.net或者ExtJS时,如何在调用Grid.save()或者Store.save()传递更多的参数到后台
- asp.net之页面参数传递
- Asp.net页面之间传递参数的几种方法
- ASP.NET网页间传递参数
- ASP.net使用URL传递中文参数
- Asp.net页面之间传递参数的几种方法
- Asp.net页面之间传递参数的几种方法
- ASP.NET 参数传递,长度限制,及使用注意事项。
- C# ASP.NET Webservice调用外部exe无效的解决方法