protected override void OnStart(string[] args)
{
   string appdataPath = System.Environment.GetEnvironmentVariable("appdata");
   string xapPath = appdataPath + "\\kuwo\\KuWo.exe";
   Process.Start(xapPath);
}
上面的代码在我开启服务的时候并没有启动kuwo.exe
当我改成 xapPath = "C:\\Users\\shengjun\\AppData\\Roaming\\kuwo\\KuWo.exe" 
开启服务就能执行了,但是我不能把我本地的路径写上去。。
求大神解救serviceC#

解决方案 »

  1.   

    加点日志,先确认路径对不对。
    再一个,对路径操作别自己拼字符串,请使用Path类
      

  2.   

    确认下appdataPath是否等于C:\\Users\\shengjun\\AppData\\Roaming
      

  3.   


    System.Environment.GetEnvironmentVariable()这个方法在VS里面能正常获取路径,但是服务启动后直接又停止了,这个方法根本没办法执行。。
      

  4.   


    换个说法就是在onstart方法里想执行其他exe文件,路径到底该怎么写?
    GetEnvironmentVariable等这些方法在服务开启时都不能获取值,但是又不能直接写绝对路径,因为这个服务要装到别人电脑上的。。谢谢
      

  5.   


    谢谢,那么我的这个执行路径C:\\Users\\shengjun\\AppData\\Roaming\\kuwo\\KuWo.exe
    该怎么写?