Alex Rivera | Logout

Cannot open <MyService> service on computer '.'

Asked 2011-06-23T11:42:31.557
15

I have a website created by C# which is to start a services in a server.

I created a services called MyService using this :

instsrv MyService %systemroot%\system32\srvany.exe

then I uses the following code to call it :

ServiceController service = new ServiceController("MyService");
try
{
    service.Start();
}
catch (Exception ex)
{
    Response.Write(ex.Message);
}

but when I access the website and trigger this event, it prompt me

Cannot open <MyService> service on computer '.'

Is it because of the security or permission problem?? Any guide with clear steps is highly appreciated.

Edit
Report

1 Answer

3

I have actually solve the problem of on top scenario.

  • The service in this case is "MyService" need to set the log on to Local System Account and check Allow service to interact with desktop
  • In the IIS Manager, create a Application Pool for the particular website. And load the website in to it.
  • The particular Application Pool Identitys need to predefined to Local Syatem

This is what is needed in the IIS and services.msc

On the other hand, there will still be errors about the MAC address.
So, we need a which can be generate by machineKey Generator.
The machineKey generated is needed to paste at the tag below.

Then copy the whole block of the quote below and paste it to the Web.config

<pages buffer="false"
enableViewState="false"
enableSessionState="false"
enableViewStateMac="false"
validateRequest="false"
enableEventValidation="false"
viewStateEncryptionMode ="Never"/>

<machineKey 
validationKey="8FCCB821044C5174C551129400F278B5629C64EAC195046DA5FE608EF418913C1139636E13FE  9F8C35AD3C10C394CAC1D9CEBB8B6BDA018165E91136B1AADBE1"
decryptionKey="3F260119F4CC0A0DD8C6B4979C70644A0ED2DD19B3ADB00F85FB7C83634FC544"
validation="SHA1"
decryption="AES"
/>

And the problem will then be solved, maybe the situation you guys faced may be different but I hope it may help someone as I struggle in this quite a long time.

In addition, I uses this code so there will no conflict when start and stop the services created.

if (service.Status == ServiceControllerStatus.Stopped)
{
    try
    {
        service.Start();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}
else
{
    try
    {
        servic
answered 2011-06-24T11:19:42.437

Your Answer