Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to invoke a Windows Service Exe via asp.net with c#?

Code as follows:

C#
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;
      }
    }
  }
}
Posted
Updated 9-Jan-14 1:29am
v3

1 solution

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#?[^].
 
Share this answer
 
v2
Comments
Rahul 105 9-Jan-14 7:42am    
Is there a solution for the above?
Rahul 105 9-Jan-14 7:43am    
I tried

System.Diagnostics.Process.Start(@"D:\C3sps Project\COMMON\Source\Untested\C3psps\C3PSPS_SOD\bin\Debug\C3PSPS_SOD.exe");
Its in asp.net web interface where on a button click that windows service exe should run.

But the exe isn't running.
Richard MacCutchan 9-Jan-14 7:46am    
I have no idea. I am just trying to get you to stop reposting the same question over and over. Please follow the proper procedures here or your account is likely to be reported for abuse.
Rahul 105 9-Jan-14 23:37pm    
In task manager process is running but various methods in service isn't working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900