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.
Start a service from Server Explorer Expand the Services node, and then locate the service you want to start. Right-click the name of the service, and then select Start.
Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to enable a service and press Enter: sc config "SERVICE-NAME" start=auto In the command, replace "SERVICE-NAME" for the name of the service that you want to enable.
with iis (version 6 and higher), web apps are run using an application pool. EAch application pool can run with a specific user (the identity), which is, by default, NETWORK SERVICE. It's a very bad idea to add this user to local administrators.
Possible ways :
I have actually solve the problem of on top scenario.
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
{
service.Stop();
service.Start();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Good Luck and thank you guys for helping.
ref:
http://www.csharp-examples.net/restart-windows-service/
http://forums.asp.net/t/906759.aspx/3/10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With