社区
C#
帖子详情
求解,怎么样在winform中注册、启动、停止用c#写的windows服务
jimmy-yu
2008-07-05 11:05:00
我想在winform中实现修改windows服务的配置文件(比如我将时间及数据库链接的配置写在app.config中,在winform中动态加载这个config,然后修改其中的节点),修改完成后再注册这个服务程序,同时提供两个按钮作为启动或停止,以用来启动或停止这个服务,这个应该怎么实现啊,哪位高手能帮帮我啊!提前先谢谢了!
...全文
259
8
打赏
收藏
求解,怎么样在winform中注册、启动、停止用c#写的windows服务
我想在winform中实现修改windows服务的配置文件(比如我将时间及数据库链接的配置写在app.config中,在winform中动态加载这个config,然后修改其中的节点),修改完成后再注册这个服务程序,同时提供两个按钮作为启动或停止,以用来启动或停止这个服务,这个应该怎么实现啊,哪位高手能帮帮我啊!提前先谢谢了!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
活靶子哥哥
2008-07-05
打赏
举报
回复
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.aspx
System.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
tianhuo_soft
2008-07-05
打赏
举报
回复
winform 里面不是有一个专门制作服务的功能嘛
用那个多好啊 ~!
wwshiwojiaguaiguai
2008-07-05
打赏
举报
回复
[Quote=引用 4 楼 zzyhuian06142 的回复:]
用Process类啊
设置他的StartInfo.Arguments
[/Quote]
jimmy-yu
2008-07-05
打赏
举报
回复
同时再请教下,怎么样把windows服务和winform一起打包成安装文件
xminsong
2008-07-05
打赏
举报
回复
资料来自网上,希望对你有用
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);
jimmy-yu
2008-07-05
打赏
举报
回复
能给个具体的例子吗
或者稍微详细点的代码
谢谢
zzyhuian06142
2008-07-05
打赏
举报
回复
用Process类啊
设置他的StartInfo.Arguments
jimmy-yu
2008-07-05
打赏
举报
回复
在vs命令行注册我知道,但是不知道在winform怎么注册,比如说放一个按钮,然后在按钮里写一个事件就可以完成注册这样
c#
winform
根据三点选圆心
c#
winform
根据三点选圆心
C#
平滑数据处理
winform
案例
C#
平滑数据处理
winform
案例,基于最小二乘法。以五点三次平滑为例。取相邻的5个数据点,可以拟合出一条3次曲线来 包含五点线性平滑和七点线性平滑。
C#
winform
四轴机械手正运动.zip
C#
winform
四轴机械手正运动.zip
C#
写
的等值线填充算法
一个用
C#
些的等值线填充算法,我是从网上下载的,如果有用,可以借鉴一下,谢谢原作者!
基于
winform
的个人计算器
基于vs2010开发的个人计算器,支持多项式运算、小数运算。
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章