安装服务出错 用VS建了一个服务,一运行安装服务的EXE,就报错,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe 不是有效的WIN32应用程序,网上也没找到答案,这是怎么回事啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 运行VS2005的CMD命令第一:将目录转至到Windows服务的执行目录下第二:installutil yourproject.exe //安装服务 InstallUtil.exe这个程序挂了吧, 重下一个, 要不你重装一下,.NET Freamwork 可以不用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); } } 果然是InstallUtil.exe 挂了,下了个InstallUtil.exe ,现在能安装了,可是在服务里却看不到,是怎么回事啊? C# 监控服务状态 这里有没有手机开发的高手? 我在vs 2008里面编辑代码的时候,Ctrl+E D然后代码的横向宽度锁定了,如何复原呢? 看看怎么这SQL语句怎么回事 我想用框架2.0的类,安装好2。0后还要如何设置啊? 关于VS2005 输入法 和 全角的问题 请问哪有公开提供的可供调用的Web Service? 关于listView控件的问题 一个窗口淡出的问题,望解答! C#中预处理防注入式攻击的方法: C#中richTextBox的问题,来寻求大家的帮助 关于Socket的Raw的事件加载问题!!
第一:将目录转至到Windows服务的执行目录下
第二:installutil yourproject.exe //安装服务
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);
}
}