求解,怎么样在winform中注册、启动、停止用c#写的windows服务 我想在winform中实现修改windows服务的配置文件(比如我将时间及数据库链接的配置写在app.config中,在winform中动态加载这个config,然后修改其中的节点),修改完成后再注册这个服务程序,同时提供两个按钮作为启动或停止,以用来启动或停止这个服务,这个应该怎么实现啊,哪位高手能帮帮我啊!提前先谢谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 winform 里面不是有一个专门制作服务的功能嘛用那个多好啊 ~! Install注册服务和卸载服务可以用Process调用如下命令%windir%\Microsoft.NET\Framework\v2.0.50727\installutil /i YourServiceExe.exenet start "You Service Name"UnInstall%windir%\Microsoft.NET\Framework\v2.0.50727\installutil /u YourServiceExe.exesee also http://msdn.microsoft.com/zh-cn/architecture/50614e95.aspxSystem.ServiceProcess.ServiceController sc = newSystem.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 在vs命令行注册我知道,但是不知道在winform怎么注册,比如说放一个按钮,然后在按钮里写一个事件就可以完成注册这样 用Process类啊设置他的StartInfo.Arguments 资料来自网上,希望对你有用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); 同时再请教下,怎么样把windows服务和winform一起打包成安装文件 文本字符太多|上下文不存在cname 下面这段错误捕捉的代码有用吗?看到一个项目里经常有这样的语句.我不太明白它的作用. 自定义纸张大小(发票) 请教一下关于筛选List<T>的问题 问个简单的用户空件的问题 怎样指定Winform的特定列的背景颜色? 无法正常使用字符串,字符串有内容,显示不出来,长度也有.怪? 线性表的另一种实现 求FTP客户端 遍历文件夹问题 短信 8口猫池 区分各modem的问题,望弄过的哥们进来看一眼 数据库插入的问题
用那个多好啊 ~!
注册服务和卸载服务可以用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
设置他的StartInfo.Arguments
{
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);