我想在winform中实现修改windows服务的配置文件(比如我将时间及数据库链接的配置写在app.config中,在winform中动态加载这个config,然后修改其中的节点),修改完成后再注册这个服务程序,同时提供两个按钮作为启动或停止,以用来启动或停止这个服务,这个应该怎么实现啊,哪位高手能帮帮我啊!提前先谢谢了!

解决方案 »

  1.   

    winform 里面不是有一个专门制作服务的功能嘛
    用那个多好啊 ~!
      

  2.   

    Install
    注册服务和卸载服务可以用Process调用如下命令%windir%\Microsoft.NET\Framework\v2.0.50727\installutil /i YourServiceExe.exe
    net start "You Service Name"UnInstall
    %windir%\Microsoft.NET\Framework\v2.0.50727\installutil /u YourServiceExe.exe
    see also http://msdn.microsoft.com/zh-cn/architecture/50614e95.aspxSystem.ServiceProcess.ServiceController sc = new
    System.ServiceProcess.ServiceController("Your Service Name");
    sc.Start//启动
    sc.Stop()//停止;
    sc.Pause()//暂停
    sc.Continue()//继续see alse http://msdn.microsoft.com/zh-cn/library/system.serviceprocess.servicecontroller_methods.aspx
      

  3.   

    在vs命令行注册我知道,但是不知道在winform怎么注册,比如说放一个按钮,然后在按钮里写一个事件就可以完成注册这样
      

  4.   

    用Process类啊
    设置他的StartInfo.Arguments
      

  5.   

    资料来自网上,希望对你有用static void Main(string[] args)
        {
          if (args.Length == 0)
          {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] { new Service1() };
            ServiceBase.Run(ServicesToRun);
          }     
          else if (args[0].ToLower() == "-i")
          {
            InstallService();
          }      //如参数为"-u",删除服务
          else if (args[0].ToLower() == "-u")
          {
            UnInstallService();
          }
        }//安培服务
    string[] commandLine = { };
            string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
            AssemblyInstaller aAssemblyInstaller = new AssemblyInstaller(serviceFileName, commandLine);
            TransactedInstaller aTransactedInstaller = new TransactedInstaller();
            aTransactedInstaller.Installers.Add(aAssemblyInstaller);
            aTransactedInstaller.Install(new System.Collections.Hashtable());//删除服务
    string[] commandLine = { };
            string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;        
            AssemblyInstaller aAssemblyInstaller = new AssemblyInstaller(serviceFileName, commandLine);
            TransactedInstaller aTransactedInstaller = new TransactedInstaller();
            aTransactedInstaller.Installers.Add(aAssemblyInstaller);
            aTransactedInstaller.Uninstall(null);
      

  6.   

    同时再请教下,怎么样把windows服务和winform一起打包成安装文件