日期:2014-05-18  浏览次数:20674 次

有关WindowService安装出现的问题
1:新建一个Windows服务应用程序
2:已经把 CanPauseAndContinue 和 CanShutDown 设置为 true。
3:设置了Windows服务的安装程序。设置serviceInstaller1的StartType属性Automatic,serviceProcessInstaller1的Account属性为LocalService
4:增加一个Timer控件
代码:
 protected override void OnStart(string[] args)
  {
  System.Timers.Timer t = new Timer(1000);
  t.Elapsed += new ElapsedEventHandler(timer1_Tick);
  t.AutoReset = true;
  t.Enabled = true;
  }

  protected override void OnStop()
  {
  }

  private void timer1_Tick(object sender, EventArgs e)
  {
  Process[] localByName = Process.GetProcessesByName("360tray.exe");
  if (localByName.Length == 0)
  {
  Process.Start("D:\\360安全卫士\\360safe\\safemon\\360tray.exe");
  }
  else
  { }
  }[code=C#][/code]
这样,当服务运行后,每1秒都将执行 Timer_Click 函数
6:单击 生成---在\bin\Debug生成.exe文件
7:安装服务--出现问题
单击开始——》运行——》输入"cmd”单击确定 输入cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 回车 进入这个文件夹 这一步正常
当我 输入InstallUtil D:\My Documents\Visual Studio 2008\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe 回车。
问题是 在初始化安装时发出异常:
System.IO.FileNotFoundException:未能加载文件或程序集 "file:///My"或它的某一个依赖性。系统找不到制定文件。。

大侠们指点迷津啊


------解决方案--------------------
InstallUtil "D:\My Documents\Visual Studio 2008\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe"

注意到那对引号了吗?