无法打开 <MyService>计算机“."上的服务 [英] Cannot open <MyService> service on computer '.'

查看:35
本文介绍了无法打开 <MyService>计算机“."上的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 C# 创建的网站,用于在服务器中启动服务.

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

我使用这个创建了一个名为 MyService 的服务:

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

无法打开计算机."上的服务

是因为安全还是权限问题??任何具有明确步骤的指南都受到高度赞赏.

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

推荐答案

我其实已经解决了 on top 场景的问题.

I have actually solve the problem of on top scenario.

  • 本例中的服务是MyService",需要设置登录到本地系统帐户并勾选允许服务与桌面交互
  • 在 IIS 管理器中,为特定网站创建一个应用程序池.并将网站加载到其中.
  • 特定的应用程序池身份需要预定义为本地系统
  • 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

这是 IIS 和 services.msc 中需要的

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

另一方面,MAC地址仍然会出现错误.
所以,我们需要一个可以由 machineKey Generator 生成的.
需要将生成的 machineKey 粘贴到下面的标签处.

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.

然后复制下面引用的整个块并将其粘贴到Web.config

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
    {
        service.Stop();
        service.Start();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}

祝你好运,感谢你们的帮助.

Good Luck and thank you guys for helping.

参考:http://www.csharp-examples.net/restart-windows-service/
http://forums.asp.net/t/906759.aspx/3/10

这篇关于无法打开 &lt;MyService&gt;计算机“."上的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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