日期:2014-05-17  浏览次数:21036 次

利用WindowsService服务如何实现启用一个自动更新的程序
自动更新程序已经写好(Update.exe),当程序运行的时候自动更新,现在手动更新(双击Update.exe)可以实现更新,但是上级要求必须在凌晨1点钟的时候启用一次更新,所以写了一个WindowsService服务,在监听函数里面写入:

if (DateTime.Now.Hour.ToString() =="0")
            {
                FunctionLibrary = new AssistantFunctionLibrary();
                FunctionLibrary.RegisterActionInf("采集更新开始!");                      Process.Start(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Update.exe");
            }


服务的:"允许服务与桌面交互"已开启,但是未能实现预期的目的,请问是什么原因造成的?
进程 WindowsService服务 更新

------解决方案--------------------
Win service 启动程序是没问题的,但程序的UI是不会显示在当前login用户的桌面的,
因为不是一个session。

所以要保证你的程序能自己运行就好,没有UI可以写LOG文件看过程。

------解决方案--------------------
http://blog.csdn.net/lanruoshui/article/details/4968901
------解决方案--------------------
引用:
Quote: 引用:

http://blog.csdn.net/lanruoshui/article/details/4968901


交互已经完成了,但是实现不了程序(Update.exe)的功能~求指教



直接启动 Update.exe 不就行了?

   ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName =path+@"\Update.exe";
                    startInfo.WindowStyle = ProcessWindowStyle.Normal;
                    Process.Start(startInfo);
                    Process.GetCurrentProcess().Kill();

------解决方案--------------------
Application.StartupPath
------解决方案--------------------
到最后只是工作路径的问题啊

ProcessStart() 用ProcessStartInfo做参数,
可以设定工作路径:

ps.WorkingDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
------解决方案--------------------
养成好习惯,关键步骤写log文件来检查后台程序是否工作正常。
------解决方案--------------------
服务程序运行的用户是不是有权限写文件到某个目录呢?