如何使用c#通过asp.net调用Windows Service Exe? [英] How to invoke a Windows Service Exe via asp.net with c#?

查看:91
本文介绍了如何使用c#通过asp.net调用Windows Service Exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#通过asp.net调用Windows Service Exe?



代码如下:



How to invoke a Windows Service Exe via asp.net with c#?

Code as follows:

private void StartService(string serviceName, int timeoutMilliseconds)
{
  Configuration objConfigFile;
  //getting an instance of the configuration file
  objConfigFile = WebConfigurationManager.OpenWebConfiguration(
  HttpContext.Current.Request.ApplicationPath);
 
  //getting an instance of the "identity" section of the cofiguration file
  IdentitySection objIdentitySection =(IdentitySection)objConfigFile.GetSection("system.web/identity");
  //Checking the domain,username and password credentails by Alex on Jan 8,2014
  if (objIdentitySection != null)
  {
    string username = objIdentitySection.UserName;
    string password = objIdentitySection.Password;
    bool impersonate = objIdentitySection.Impersonate;

    if (impersonate == true)
    {
      ServiceController service = new ServiceController(@"D:\C3sps Project\COMMON\Source\Untested\C3psps\C3PSPS_SOD\bin\Debug\C3PSPS_SOD.exe");

      try
      {
        TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

        service.Start();
        service.WaitForStatus(ServiceControllerStatus.Running, timeout);
        return;
      }
    }
  }
}

推荐答案

请停止重新发布问题;您之前已经发布了两次,并在您的sockpuppet帐户下发布了两次如何用c#在asp.net代码中运行windows服务exe路径? [ ^ ]。
Please stop reposting questions; you already posted this twice before, and twice under your sockpuppet account at How to run a windows service exe path in asp.net code behind with c#?[^].


这篇关于如何使用c#通过asp.net调用Windows Service Exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆