ASP.NET启动Windows服务

wangyanboq 2008-08-30 01:13:33
protected void Button1_Click(object sender, EventArgs e)
{
string service_start_string = "net start wscsvc";

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
p.StandardInput.WriteLine(service_start_string );
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch (Exception e)
{
strOutput = e.Message;
}

}


在本地打开网页的时候,可以启动wscsvc服务(Security Center)。但如果在其他机器上就不能启动,而且也不报错。
是什么原因?
...全文
200 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jrl5365 2008-08-30
  • 打赏
  • 举报
回复
权限问题
Yes1000 2008-08-30
  • 打赏
  • 举报
回复
IIS里开启了WINDOWS身份验证,
而你以系统管理员的身份(或者有权限开启这个服务的系统帐号)登录了系统

这样,你本地访问网站的时候,网站是以系统管理员的身份(或者有权限开启这个服务的系统帐号)来运行的,当然有权限运行了.

非本地机,网站是以IIS中设置的匿名用户身份来运行的,这个账户无权启动服务.

这是很正常的,只要服务器权限设置得当,不用担心存在安全问题

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧