[C#] 
using System;
using System.Diagnostics;
using System.ComponentModel;namespace MyProcessSample
{
    /// <summary>
    /// Shell for the sample.
    /// </summary>
    public class MyProcess
    {
        
       
        
        public void BindToRunningProcesses()
        {
            // Get the current process.
            Process currentProcess = Process.GetCurrentProcess();            
            // Get all instances of Notepad running on the local
            // computer.
            Process [] localByName = Process.GetProcessesByName("notepad");            
            // Get all instances of Notepad running on the specifiec
            // computer.
            // 1. Using the computer alias (do not precede with "\\").
            Process [] remoteByName = Process.GetProcessesByName("notepad", "myComputer");
            
            // 2. Using an IP address to specify the machineName parameter. 
            Process [] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");
            
            
            // Get all processes running on the local computer.
            Process [] localAll = Process.GetProcesses();            
            // Get all processes running on the remote computer.
            Process [] remoteAll = Process.GetProcesses("myComputer");            
            // Get a process on the local computer, using the process id.
            Process localById = Process.GetProcessById(1234);            
            // Get a process on a remote computer, using the process id.
            Process remoteById = Process.GetProcessById(2345, "myComputer");
            
        }
        
        public static void Main()
        {
                
                   MyProcess myProcess = new MyProcess();
                        myProcess.BindToRunningProcesses();            }    
    }
}

解决方案 »

  1.   

    利用进程计数器 和using System.Diagnostics;
      

  2.   

    To wangsaokui: 谢谢!To kimpankata:如何利用进程计数器?请给一个例子;  谢谢!!!
      

  3.   

    wangsaokui(无间道III(终极无间))的解决办法不错,不过还是有一个小问题不知如何解决:系统在执行此段代码时会读软驱,那吱嘎一声实在太难听了!
      

  4.   

    wangsaokui(无间道III(终极无间))Very Good蛋~~咕咕蛋~
      

  5.   

    [DllImport("user32)] _
        public static extern int FindWindow(string lpClassName, string lpWindowName)    如果返回值不等于0,那么就是有运行了。
      

  6.   

    或者用这个:
    Dim thisproc As System.Diagnostics.Process
                    For Each thisproc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
                        If thisproc.CloseMainWindow() = False Then
                            thisproc.Kill()
                            MsgBox("kill the EXCEL successfully!")
                        Else
                            MsgBox("Close the Excel Process successfully!")
                        End If
                    Next
      

  7.   

    using System.Diagnostics;
    using System.Runtime.InteropServices;[DllImport("user32.dll")] private static extern
    bool SetForegroundWindow(IntPtr hWnd);
    [DllImport("user32.dll")] private static extern
    bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    [DllImport("user32.dll")] private static extern
    bool IsIconic(IntPtr hWnd); private const int SW_HIDE = 0;
    private const int SW_SHOWNORMAL = 1;
    private const int SW_SHOWMINIMIZED = 2;
    private const int SW_SHOWMAXIMIZED = 3;
    private const int SW_SHOWNOACTIVATE = 4;
    private const int SW_RESTORE = 9;
    private const int SW_SHOWDEFAULT = 10;
    static void Main() 
    {

    #region 关闭重复线程

    string proc=Process.GetCurrentProcess().ProcessName;

    Process[] processes=Process.GetProcessesByName(proc);

    if (processes.Length > 1)
    {

    MessageBox.Show ("程序已经启动!!",Constants.MESSAGEBOX_TITLE  );
    Process p=Process.GetCurrentProcess();
    int n=0;     
    if (processes[0].Id==p.Id)
    {

    n=1;
    }

    IntPtr hWnd=processes[n].MainWindowHandle;

    if (IsIconic(hWnd))
    {
    ShowWindowAsync(hWnd, SW_RESTORE);
    }

    SetForegroundWindow(hWnd);

    return;
    }
    #endregion
    }
      

  8.   

    利用互斥:
    using System.Runtime.InteropServices;
    然后在Main()函数里面加如下代码:
    bool requestInitialOwnership = true;
    bool mutexWasCreated; Mutex m = new Mutex(requestInitialOwnership, "jiliang",out mutexWasCreated);
            
    if (!(requestInitialOwnership && mutexWasCreated))
    {
    MessageBox.Show("本程序已经打开。");
    return;
    }
    就可以解决问题了.
      

  9.   

    谢谢诸位高手的指点,Kstar(颽嗣鳓) 兄的方案最完整详细,我已采用;再次感谢!!!结帖
      

  10.   

    谢谢诸位高手! Kstar兄的方案完整详尽,我已采用;再次感谢!!结帖 
      

  11.   

    To Kstar
       忘了结帖,现在给分!