C#应用程序之参数传递,进程查找

1、查找当前exe应用程序是否在进程管理器

public static Boolean SearchProcess(string str)
        {
            int i = 0;
            bool result = true;
            //获得进程对象,以用来操作
            System.Diagnostics.Process myproc = new System.Diagnostics.Process();
            //得到所有打开的进程
            try
            {
                Process[] pros = Process.GetProcesses();
                foreach (Process thisproc in pros)
                {
                    if (thisproc.ProcessName == str)
                    {
                        i = i + 1;
                        result = false;
                    }
                }
            }
            catch (Exception Exc)
            {
                throw new Exception("", Exc);
            }
            Console.WriteLine(i);
            return result;
        }

 

 

2、调用程序命令

 

private static void StartMicrosoft(string command,string args)
        {
            Process pc = new Process();
            ProcessStartInfo psi = new ProcessStartInfo(command,args);
                 try
            {
                pc.StartInfo = psi;
                pc.StartInfo.UseShellExecute = false;
                pc.Start();
                pc.WaitForExit();
                //int exitCode = pc.ExitCode; //获取返回结果 
            }
            catch
            {

            }
            finally
            {
                pc.Close();
            }

        }

 

 

posted on 2012-05-02 13:48  lei0515  阅读(195)  评论(0)    收藏  举报

导航