日期:2014-05-20 浏览次数:21043 次
ServiceController sc = new ServiceController(); sc.ServiceName = "服务名";
private void btnStart_Click(object sender, EventArgs e)
{
sc.Start();//启动
}
private void btnStop_Click(object sender, EventArgs e)
{
sc.Stop();//停止
}
private void btnStart_Click(object sender, EventArgs e)
{
sc.Start();//启动
sc.WaitForStatus(ServiceControllerStatus.Running);//等待服务达到指定状态
}
private void btnStart_Click(object sender, EventArgs e)
{
if(sc.Status==ServiceControllerStatus.Stopped)
sc.Start();//启动
sc.WaitForStatus(ServiceControllerStatus.Running);//等待服务达到指定状态
}
private void btnStart_Click(object sender, EventArgs e)
{
sc.Refresh();//刷新属性值
if(sc.Status==ServiceControllerStatus.Stopped)
sc.Start();//启动
sc.WaitForStatus(ServiceControllerStatus.Running);//等待服务达到指定状态
}
using System.Configuration;
string _value = ConfigurationSettings.AppSettings["Key值"];
using System.Xml;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(configPath);//configPath是config文件的路径,对于这个路径的获取,将会在后面说明
XmlNodeList nodes = xmlDoc.GetElementsByTagName("add");
Hashtable hash = new Hashtable();
foreach (XmlNode node in nodes)
{
hash.Add(node.Attributes["key"].Value.ToString(), node.Attributes["value"].Value.ToString());
}
//通过hash["Key值"].ToString()就能获取到某一个key所对应的value了
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(configPath);//configPath为config文件的路径
XmlNode xmlNode=xmlDoc.SelectSingleNode("configuration/appSettings/add[@key='"+_key+"']");//_key为需要修改其value的key值
xmlNode.Attributes["value"].InnerText=_value;//_value为新值
xmlDoc.Save(configPath);