오류 5 : Windows 서비스를 시작할 때 액세스가 거부되었습니다.
C #에서 만든 Windows 서비스를 시작하려고하면이 오류가 발생합니다.
지금까지 내 코드 :
private ServiceHost host = null;
public RightAccessHost()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
host = new ServiceHost(typeof(RightAccessWcf));
host.Open();
}
protected override void OnStop()
{
if (host != null)
host.Close();
host = null;
}
업데이트 # 1
NETWORK SERVICE 계정에 권한을 부여하여 위의 문제를 해결 했지만 이제 다른 문제가 있습니다.
업데이트 # 2
서비스를 시작할 수 없습니다. System.InvalidOperationException : 서비스 'RightAccessManagementWcf.RightAccessWcf'에 애플리케이션 (비 인프라) 엔드 포인트가 없습니다. 이는 애플리케이션에 대한 구성 파일이 없거나 구성 파일에서 서비스 이름과 일치하는 서비스 요소를 찾을 수 없거나 서비스 요소에 정의 된 엔드 포인트가 없기 때문일 수 있습니다. System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints (ServiceDescription description) at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost (ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.ServiceHostBase.InitializeRuntime () at System.ServiceModel.ServiceHostBase.OnOpen ( System.ServiceModel.Channels.CommunicationObject에서 TimeSpan 시간 초과).
이 게시물이 오래되었다는 것을 알고 있지만 표시된 해결책이 없으며이 문제를 어떻게 해결했는지 설명하고 싶었습니다.
첫 번째 Error 5: Access Denied
오류는 출력 디렉터리에 대한 권한을 NETWORK SERVICE
계정에 부여하여 해결되었습니다 .
두 번째 Started and then stopped
오류는 서비스에 장애가 발생했을 때 일반적인 메시지로 보입니다. 이벤트 뷰어 (특히 'Windows 로그> 애플리케이션')에서 실제 오류 메시지를 확인하십시오.
제 경우에는 app.config의 잘못된 서비스 구성 설정이었습니다.
컴퓨터-> 관리-> 서비스-> [내 서비스] 속성. 그런 다음 계정 정보가있는 탭입니다. 관리자 계정으로 서비스를 실행하는 것과 같은 설정을 사용하십시오.
그것은 나를 위해 해냈다.
편집 : 또한 문제가 될 수있는 것은 대부분의 서비스가 LOCAL SERVICE
또는 LOCAL SYSTEM
계정 으로 실행된다는 것 입니다. 이제 C:/my-admin-dir/service.exe
해당 계정으로 실행 하지만 해당 디렉토리에서 아무것도 실행할 수없는 경우 error 5
. 따라서 서비스 실행 파일을 찾고 디렉터리를 RMB-> 속성-> 보안하고 서비스가 실행되는 계정이 디렉터리를 완전히 제어 할 수있는 사용자 목록에 있는지 확인합니다.
이것은 나를 위해 일했습니다.
- 서비스 실행 파일이 포함 된 최상위 폴더를 마우스 오른쪽 버튼으로 클릭합니다. 속성으로 이동
- "보안"탭으로 이동
- "편집"을 클릭하십시오
- "추가"를 클릭하십시오.
- "SYSTEM"이름을 입력하고 확인을 클릭합니다.
- 시스템 사용자를 강조 표시하고 "모든 권한"옆에있는 허용 확인란을 클릭합니다.
- 확인을 두 번 클릭하십시오.
또한 동일한 오류가 발생했습니다. 서비스> 속성> 로그온> 다음으로 로그온 : 로컬 시스템 계정을 마우스 오른쪽 버튼으로 클릭하여 해결했습니다.
Path to executable
실제 실행 파일을 가리키는 지 확인하십시오 (서비스-> 속성-> 일반 탭을 마우스 오른쪽 버튼으로 클릭). powershell (및 sc.exe)을 통해 실행 파일을 가리 키지 않고 서비스를 설치할 수 있습니다 ... ahem.
나는 해결책을 얻었다.
1. Go to local service window(where all services found)
2. Just right click on your service name:
3. click on "properties"
4. go to "log on" tab
5. select "local system account"
6. click "ok"
이제 서비스를 시작할 수 있습니다.
내 경우에는 다음이 확인되지 않았습니다.
이 오류는 OnStart
메서드에 오류가있을 때 발생합니다 . 호스트 OnStart
는 호출 될 때 실제로 열리지 않고 대신 제어를 기다릴 것이기 때문에 메소드 에서 직접 호스트를 열 수 없습니다 . 따라서 스레드를 사용해야합니다. 이것이 제 예입니다.
public partial class Service1 : ServiceBase
{
ServiceHost host;
Thread hostThread;
public Service1()
{
InitializeComponent();
hostThread= new Thread(new ThreadStart(StartHosting));
}
protected override void OnStart(string[] args)
{
hostThread.Start();
}
protected void StartHosting()
{
host = new ServiceHost(typeof(WCFAuth.Service.AuthService));
host.Open();
}
protected override void OnStop()
{
if (host != null)
host.Close();
}
}
if you are a having an access denied error code 5. then probably in your code your service is trying to interact with some files in the system like writing to a log file
open the services properties select log on
tab and check option to allow service to interact with the desktop,
For me - the folder from which the service was to run, and the files in it, were encrypted using the Windows "Encrypt" option. Removing that and - voila!
I had windows service hosted using OWIN and TopShelf. I was not able to start it. Same error - "Access denied 5"
I ended up giving all the perms to my bin/Debug.
The issue was still not resolved.
So I had a look in the event logs and it turned out that the Microsoft.Owin.Host.HttpListener
was not included in the class library containing the OWIN start up class.
So, please make sure you check the event log to identify the root cause before beginning to get into perms, etc.
Your code may be running in the security context of a user that is not allowed to start a service.
Since you are using WCF, I am guessing that you are in the context of NETWORK SERVICE.
see: http://support.microsoft.com/kb/256299
Use LocalSystem Account instead of LocalService Account in Service Installer.
You can do this either from doing below change in design view of your service installer:
Properties of Service Process Installer -> Set Account to LocalSystem.
or by doing below change in in designer.cs file of your service installer:
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
Right click on the service
in service.msc and select property
.
You will see a folder path under Path to executable
like C:\Users\Me\Desktop\project\Tor\Tor\tor.exe
Navigate to C:\Users\Me\Desktop\project\Tor and right click on Tor.
Select property
, security
, edit
and then add
. In the text field enter LOCAL SERVICE
, click ok and then check the box FULL CONTROL
Click on add
again then enter NETWORK SERVICE
, click ok
, check the box FULL CONTROL
Then click ok (at the bottom)
In my case, I had to add 'Authenticated Users' in the list of 'Group or User Names' in the folder where the executable was installed.
I was getting this error because I misread the accepted answer from here: Create Windows service from executable.
sc.exe create <new_service_name> binPath= "<path_to_the_service_executable>"
For <path_to_service_executable>
, I was using the path of the executable's folder, e.g. C:\Folder
.
It needs to be the path of the executable, e.g. C:\Folder\Executable.exe
.
Hopefully this helps someone who made the same silly mistake as I did.
One of the causes for this error is insufficient permissions (Authenticated Users) in your local folder. To give permission for 'Authenticated Users' Open the security tab in properties of your folder, Edit and Add 'Authenticated Users' group and Apply changes.
Once this was done I was able to run services even through network service account (before this I was only able to run with Local system account).
Have a look at Process Utilities > Process monitor
from http://www.sysinternals.com.
This is tool that allows you monitor what a process does. If you monitor this service process, you should see an access denied somewhere, and on what resource the access denied is given.
For the error 5, i did the opposite to the solution above. "The first Error 5: Access Denied error was resolved by giving permissions to the output directory to the NETWORK SERVICE account."
I changed mine to local account, instead of network service account, and because i was logged in as administrator it worked
If you are getting this error on a server machine try give access to the folder you got the real windows service exe. You should go to the security tab and select the Local Service as user and should give full access. You should do the same for the exe too.
I have monitored sppsvc.exe using process monitor and found out that it was trying to write to the HKEY_LOCAL_MACHINE\SYSTEM\WPA key. After giving permissions to NETWORK SERVICE on this key, I was able to start the service and Windows suddenly recognized that it was activated again.
I accidentally set my service to run as Local service
solution was to switch to Local System
After banging my had against my desk for a few hours trying to figure this out, somehow my "Main" method got emptied of it's code!
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new DMTestService()
};
ServiceBase.Run(ServicesToRun);
Other solutions I found:
- Updating the .NET framework to 4.0
Making sure the service name inside the InitializeComponent() matches the installer service name property
private void InitializeComponent() ... this.ServiceName = "DMTestService";
And a nice server restart doesn't hurt
Szhlopp
In may case system run out of free space on local disk.
I had this issue today on a service that I was developing, and none of the other suggestions on this question worked. In my case, I had a missing .dll dependency in the folder where the service ran from.
When I added the dependencies, the issue went away.
In my case I kept the project on desktop and to access the desktop we need to add permission to the folder so I simply moved my project folder to C:\ directory now its working like a charm.
I don't know if my answer would make sense to many, but I too faced the same issue and the solution was outrageously simple. All I had to do was to open the program which I used to run the code as an administrator. (right-click --> Run as Administrator).
That was all.
I had this issue on a service that I was deploying, and none of the other suggestions on this question worked. In my case, it was because my .config (xml) wasn't valid. I made a copy and paste error when copying from qualif to prod.
As the error popup suggests this is related to permission. So run the service as "LocalSystem" account.
To do the same, Right Click on serviceProcessInstaller -> Properties -> Account
and set it to "LocalSystem"
instead of the default "User"
. Install the service and voila.
Click the Start
menu and choose Run
or use the keyboard shortcut of Win+R.
In the dialog box, type lusrmgr.msc
. When this application opens, click Users in the left-hand panel and then right click Administrator
in the right-hand panel. Click Properties
in the menu.
에서 Administrator Properties
대화 상자에서 선택 Member Of
탭을 누른 다음 오른쪽 하단에서 추가 ... 버튼을 클릭합니다. 다음 대화 상자에서Advanced...
다른 대화 상자가 나타납니다. 거기 Find Now
에서 오른쪽을 클릭하십시오 . 대화 상자 하단에 검색 결과 목록이 나타납니다. Network Services
이 목록에서 선택 OK
하고 열려있는 각 대화 상자를 클릭 합니다.
참고 URL : https://stackoverflow.com/questions/4267051/error-5-access-denied-when-starting-windows-service
'program tip' 카테고리의 다른 글
Javascript 객체 값을 동적으로 설정하는 방법은 무엇입니까? (0) | 2020.09.03 |
---|---|
React의 다른 return 문에서 JSX 여러 줄을 반환하는 방법은 무엇입니까? (0) | 2020.09.03 |
Razor를 사용한 Html.RenderPartial () 구문 (0) | 2020.09.03 |
Underscore.js와 jQuery는 서로를 보완합니까? (0) | 2020.09.03 |
iOS-Swift 용 단위 테스트를 실행할 때 'MyProject-Swift.h'파일을 찾을 수 없음 (0) | 2020.09.03 |