服务也要有Main函数入口
你的Main函数有吗? using System;
 using System.ServiceProcess;
namespace Service_Windows
{
       internal static class Program
    {
        private static void Main()
        {
            ServiceBase.Run(new ServiceBase[] { new Service_Windows () });
        }
    }
}

解决方案 »

  1.   

     RegistryKey bKey = Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true);
                    
    你修改注册表是修改的当前用户的注册表值,而服务程序的启动帐户一般是system。也就是说做成服务后修改的是system帐户的壁纸,而不是你登录帐户的壁纸。
    要想解决的话可以把服务的登录帐户设置为你自己的帐户。
    以上是我分析。没有验证过,不知道对不对。
      

  2.   

    楼上说的有道理  窗口程序和服务程序不一样的噢 窗口程序不需要main函数
      

  3.   


    窗口程序也需要Main()方法
      

  4.   

    我又试了一下,问题就出在using System.Runtime.InteropServices;
    和[DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);if (SystemParametersInfo(20, 1, picturePath, 1) == 0)
                        {
                            throw new Exception("更换壁纸失败");
                        }这几句上,我把hbz.huan(@"H:\3号机备分\bak\照片", 5, 0);方法注释掉,马上就能正常启动,所以,和程序入口没关系
      

  5.   


    窗口程序也需要Main()方法
    这是什么问题阿