可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When I try to start a service I created in Visual Studio I receive the following error:
System error 5 has occurred.
Access is denied.
I am running the command line with elevated privileges, so it's not that problem. Is there any place I can look to see what error is occuring.
回答1:
To get it to work I needed to add permissions to the output bin\debug folder for my service project.
The Local Service account didn't have permissions to the output .exe file, and this was why the error was occuring.
回答2:
Had the same issue.
Fixed by running the service under "Local System Account"
回答3:
In my case the solution was even that simple: Run Command Prompt as administrator.
回答4:
I see you've fixed the problem; but in reality, you shouldn't normally be running the service from a project's bin folder anyway - the files should be put somewhere project and profile independent (for example, under program files). For debugging purposes (when it will be in the bin folder), you can detect whether it is a service in Main()
, and if it is being run interactively just run the service code directly, rather than the usual service-start setup.
You can detect either by adding a command line argument, or you can try checking Environment.UserInteractive
.
回答5:
The Local Services account doesn't seem to be privileged to control a service. So, in the service's LogOn Property, change the account type to Local System and allow service to interact with desktop.
Also, make sure that, you install the service using instalutil, as an administrator.
Lastly, when you want to run a service from the command prompt using the "net start [service name]" command, you have to run the command prompt as an administrator.
回答6:
I had the same problem because my project and its source code was in a folder that had NTFS's Encrypting File System (EFS) enabled. This caused by compiled assemblies being encrypted aswell and the user running my service didn't have permissions to decrypt them. Removing EFS was the easy solution for this. It can be done by command line using CIPHER.EXE, which is a Windows tool.
回答7:
I had the same problem when I migrated a service from vs05 to vs2010, from framework 2.0 till framework 4.0 at the same time. I got Access denied. As soon as a change back to framework 2.0 it worked again. The ?%¤#%&%& problem was that the initializing string for the service was incorrect (?!). The string expected quotes at the beginning and at the end!
Before....path + service name" "/parameter=1 ' this had worked with framework 2.0
After...."path + service name" "/parameter=1"
Access Denied has nothing to do with the problem. Why not "Path not found " or "missing parameter"
回答8:
A user account with administrator rights will prompt “are you sure?” in situations where the administrator account is not prompted. I had this problem with net stop netprofm.
To remove the prompt do this.
Control Panel, User Accounts, Change User Account Control settings, never notify
This seems to provide the user account with admin rights the same behavior as a the administrator account.
回答9:
Run it from Task Scheduler with highest privileges and it will work.
回答10:
Just ran into this issue after I had run an 'sc config' to change binPath of the service.
The only fix that worked for me was to 'sc delete' the service and install again.
Things worked perfectly after that.