在.NET2003窗口模式下运行外部程序(*.exe文件),该用什么方法啊???不要WEB模式下的!!

解决方案 »

  1.   

    System.Diagnostics.Process 类可以帮你
      

  2.   

    System.Diagnostics.Process   类
    应该怎么弄出来???
    我在.NET2003下面找不到这个空间名
      

  3.   

    //WinXP + VS2003using System;
    using System.Text;
    using System.Data;
    using System.Threading;
    using System.Diagnostics;namespace Class1
    {
    class ExcelProgram
    {
    [STAThread]
    static void Main(string[] args)
    {
    System.Diagnostics.Process process = new Process();
    process.StartInfo.FileName = @"D:\Chat.exe";
    process.Start(); Thread.Sleep(2000);
    Console.WriteLine("Process was created!"); Console.ReadLine();
    } }}
      

  4.   

    //WinXP   +   VS2003:Windows CE 
    如果是在Windows CE 下面呢???
    在他的下面有using   System.Diagnostics; 这个空间名,但是他的下面没有process这个类在Windows CE 下面运行外部程序(*.exe文件),该用什么方法啊???
      

  5.   

    //WinCE下估计需要通过P/Invoke调用API了
    //你看下面的代码是否可以,我通过CE的模拟器测试通过using System;
    using System.Drawing;
    using System.Collections;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;namespace SmartDevice
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
                    //First, import ce API
    static string strAppName = "Start"; [DllImport("coredll.dll")]
    public static extern int CreateProcess(string pszImageName, string pszCmdLine,
    int Res1, int Res2, int Res3, CREATE_FLAG fdwCreate,
    int Res4, int Res5, int Res6,
    ref PROCESS_INFORMATION pProcInfo); [DllImport("coredll.dll")]
    public static extern int
    CreateProcess(string pszImageName, int pszEmptyPath,
    int Res1, int Res2, int Res3, CREATE_FLAG fdwCreate,
    int Res4, int Res5, int Res6,
    ref PROCESS_INFORMATION pProcInfo); [DllImport("coredll.dll")]
    public static extern int CloseHandle(IntPtr hObject); [DllImport("coredll.dll")]
    public static extern int GetLastError();
    public struct PROCESS_INFORMATION
    {
    public IntPtr hProcess;
    public IntPtr hThread;
    public int dwProcessId;
    public int dwThreadId;
    }; public enum CREATE_FLAG
    {
    CREATE_SUSPENDED = 4,
    CREATE_NEW_CONSOLE = 0x10,
    }

    private System.Windows.Forms.Button button1;

    public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    }
    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    base.Dispose( disposing );
    }
    #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(48, 176);
    this.button1.Size = new System.Drawing.Size(144, 32);
    this.button1.Text = "外部程序";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.ClientSize = new System.Drawing.Size(242, 263);
    this.Controls.Add(this.button1);
    this.Text = "Form1"; }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary> static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
                            //Second, call pword throgh ce API
    string strPath = @"\Windows\pword.exe";
    PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
    int bOk = CreateProcess(strPath, 0, 0, 0, 0, 0, 0, 0, 0,
    ref pi);
    if (bOk > 0)
    {
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    }
    else
    {
    MessageBox.Show("CreateProcess Failed", strAppName);
    } }
    }
    }