用VS建了一个服务,一运行安装服务的EXE,就报错,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe 不是有效的WIN32应用程序,网上也没找到答案,这是怎么回事啊。

解决方案 »

  1.   

    运行VS2005的CMD命令
    第一:将目录转至到Windows服务的执行目录下
    第二:installutil yourproject.exe //安装服务
      

  2.   

    InstallUtil.exe这个程序挂了吧, 重下一个,
      

  3.   

    要不你重装一下,.NET Freamwork
      

  4.   

    可以不用installutil注册啊using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Configuration.Install;
    using System.Collections;
    using System.ServiceProcess;
    static void Main(string[] args)
            {
            InstallService(new System.Collections.Hashtable(), “服务程序路径...", "服务名...", 
    "描述...");       
    }
             /// <summary>   
            /// 安装服务   
            /// </summary>   
            /// <param name="stateSaver"> 服务名</param>   
            /// <param name="filepath">安装服务路径</param>   
            /// <param name="svcName">服务名称</param>   
            public static void InstallService(IDictionary stateSaver, string filepath, string svcName, string displayname)
            {
                try
                {
                    System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(svcName);                if (!ServiceIsExisted(svcName))
                    {
                        service.DisplayName = displayname;
                        //Install Service   
                        AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
                        myAssemblyInstaller.UseNewContext = true;
                        myAssemblyInstaller.Path = filepath;
                        myAssemblyInstaller.Install(stateSaver);
                        myAssemblyInstaller.Commit(stateSaver);
                        myAssemblyInstaller.Dispose();
                        //--Start Service   
                        service.Start();
                    }
                    else
                    {
                        if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running && service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)
                        {
                            service.Start();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("installServiceError\n" + ex.Message);
                }
            }
      

  5.   

    果然是InstallUtil.exe 挂了,下了个InstallUtil.exe ,现在能安装了,可是在服务里却看不到,是怎么回事啊?