挽星

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

调用计算器:System.Diagnostics.Process.Start("calc.exe");
调用word程序:System.Diagnostics.Process.Start("WINWORD.exe");
调用计事本:System.Diagnostics.Process.Start("notepad.exe");
调用Excel: System.Diagnostics.Process.Start("excel.exe");
调用SQL2005:System.Diagnostics.Process.start("SqlWb.exe");

---------------------------------------------------------------------------------

将你的net use \\172.16.17.1 /user:username password写到bat文件中,然后运行下面代码就可以了。
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.CreateNoWindow = false;
            process.StartInfo.FileName = "d:\\netuse.bat";
            process.Start();

程序控制参数方法:

lovevsnet(编程一把手)提到:

System.Diagnostics.ProcessStartInfo psi =
       new System.Diagnostics.ProcessStartInfo();
//prompt
psi.FileName = @"C:\WINDOWS\system32\cmd.exe"; // Path for the cmd prompt
psi.Arguments
=@"net use \\172.16.17.1 /user:username password";
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(psi);
就是用进程启动cmd.exe

使用Process类运行ShellExecute的一个问题(点击查看引用)
只有在STA线程上ShellExecute 才能确保工作无误。在Process的实现中,并没有考虑到这个问题,所以使用Process类运行ShellExecute可能会出错。如果你不能保证调用Process.Start的线程的ApartmentState,可以使用如下的代码来避免这个问题:

using System;
using System.Threading;
public class Foo {
    public static void OpenUrl()    {
        System.Diagnostics.Process.Start(@"
http://www.google.com");
    }
    public static void Main() {
        ThreadStart openUrlDelegate = new ThreadStart(Foo.OpenUrl);
        Thread myThread = new Thread(openUrlDelegate);
        myThread.SetApartmentState(ApartmentState.STA);   
        myThread.Start();
        myThread.Join();
    }
}

-----------------------------------------------------------------------

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName= "notepad.exe";
proc.Start();
proc.WaitForExit();

来源:(http://blog.sina.com.cn/s/blog_62822a7f0100fk32.html) - C#调用Windows应用程序 System.Diagnostics.Process_thinker_新浪博客

posted on 2010-06-23 14:52  挽星  阅读(4533)  评论(0)    收藏  举报