各位大侠,我建了一个windows服务项目,想通过服务自动开启每次开机后自动启动exe的程序。我用web项目测试可以做到。但是用windows服务测试,老是有exe进程,而exe程序没有运行。比例abc.exe这个程序,我在进程里看到有这个程序的进程,但是程序却没有运行?请问到底该怎么做呢?         public void StartSystem(string mySys)
        {
            int i = 1;
            Process[] myProcesses = Process.GetProcesses();
            foreach (Process myPrpcess in myProcesses)
            {
                if (myPrpcess.ProcessName.ToUpper() == mySys)//mySys EXE程序进程名
                {
                    i = i + 1;
                }
                else
                {
                    i = 1;
                }
            }
            if (i == 1)
            {
                Process p = new Process();
                p.StartInfo.FileName = myFile; //myFile EXE程序路径
                p.Start();
            }
            else
            {
                StopSystem(mySys);
            }
            return;
        }

解决方案 »

  1.   

    你与其在这里等回复,为什么不baidu || google一下:
    http://hi.baidu.com/d369608w/blog/item/6358c752ed90600b0df3e303.html
      

  2.   

    是WINDOWS服务默认不支持与UI交互的问题。
    今天问这个的怎么这么多 
    http://blog.csdn.net/zgke/archive/2009/01/11/3751917.aspx可能对你有帮助
      

  3.   


    string Apppath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"abc.exe")
    RegistryKey MyReg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
    if (MyReg.GetValue("abc.exe") != null)
                    {
                        string path = MyReg.GetValue("abc.exe").ToString();
                        if (path != Apppath)
                        {
                            MyReg.SetValue("abc.exe", Apppath);
                        }
                    } 
                    else
                    {
                        MyReg.SetValue("abc.exe", Apppath);
                    }