Error 5:Access Denied When Starting Windows Service

System error 5 Access is denied when starting a .NET service

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.

Access Denied when running Windows Service

I found the solution and believe me I feel really stupid!!!

When I installed it as a service I only put the path in "binPath".

sc create WindowsService1 binPath="C:\temp".

Once I actually added the executable to the binPath parameter everything worked.

Changed it to sc create WindowsService1 binPath="C:\temp\WindowsService.exe" and it worked.

I know it is an Id10t error but Microsoft should really provide better messaging for the "sc" command. A message like "Cannot find file specified in the binPath parameter" would have been really helpful. Would have saved me about 6 hours of work.

Thanks everyone for reviewing and replying to this question.

Windows service fails to start up with "Error 5: Access is denied"

Ok, so I've managed to resolve my problem by using a different installation routine for the service. It appears it was a problem of installation rather than user rights related problem. Below is the example of a working script in case anyone is interested:

# ALISE MONITORING SERVICE INSTALLATION #

$service_fullname = "Alise.MonitoringService"
$username = ".\AliseMonitoring"
$password = "mypassword"
$pause = 0
$exeName = "MonitoringService.exe"

$ErrorActionPreference = "Stop"
$nl = [Environment]::NewLine

$dir = Split-Path $MyInvocation.MyCommand.Path
$service_path = join-path $dir "$exeName"
$service_path = resolve-path $service_path


Write-Host $nl
Write-Host "Service name: $service_fullname" -foregroundcolor green
Write-Host "Service logon identity: $username" -foregroundcolor green
Write-Host "Service installation path: $service_path" -foregroundcolor green
Write-Host $nl

Write-Host "Creating user if necessary..." -foregroundcolor green
start-process create_user.bat -Wait
Write-Host "Granting user log on as service rights..." -foregroundcolor green
$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$Identity = "AliseMonitoring"
$privilege = "SeServiceLogonRight" 
$CarbonDllPath = $PSScriptRoot + "\Carbon.dll"
[Reflection.Assembly]::LoadFile($CarbonDllPath)
[Carbon.Lsa]::GrantPrivileges( $Identity, $privilege )
Write-Host $nl

$service = Get-WmiObject -Class Win32_Service -Filter "Name = '$service_fullname'"
if ($service -ne $null)
{
Write-Host "Service already exists, attempting stop and delete:" -foregroundcolor green
Write-Host "Stop service $service_fullname..."
$service | stop-service
Write-Host "Delete service $service_fullname..."
$service.Delete()
Write-Host "Service $service_fullname deleted."
Write-Host $nl
}

Write-Host $nl

Write-Host "Registering service $service_fullname for $service_path ..." -foregroundcolor green
New-Service -Name $service_fullname -BinaryPathName $service_path -DisplayName $service_fullname -Description "Alise monitoring serviss." -StartupType Automatic
$service = Get-WmiObject -Class Win32_Service -Filter "Name = '$service_fullname'"
Write-Host "Service registred."

$res = sc.exe config $service_fullname obj= $username password= $password

if ($LASTEXITCODE -ne 0)
{
Write-Host "username: $username password: $password" -foregroundcolor green
throw $res
}

#Event log and source registration
Write-Host $nl
Write-Host "Registering event source Alise.MonitoringService" -foregroundcolor green
if ([system.diagnostics.eventlog]::SourceExists("Alise.MonitoringService") -eq $false)
{
[system.diagnostics.eventlog]::CreateEventSource("Alise.MonitoringService", "Alise")
Write-Host "Created event source: Alise.MonitoringService"
}
else
{
Write-Host "Event source Alise.MonitoringService allready exists."
}

Write-Host $nl
Write-Host "Starting service..." -foregroundcolor green
Start-Service $service_fullname
Write-Host "Service started!" -foregroundcolor green

if ($pause -eq 1)
{
read-host -prompt "Press enter to exit"
}

Starting Windows service as anything but Administrator gives 'Access denied'

The problem was actually that the service executable was encrypted with EFS; the error code (access denied) threw me off.

The service was being output to a folder that was inadvertently encrypted, so when I copied the service out to the install location, it remained encrypted. Once I unchecked the 'Encrypt contents to secure data' check box in the file's properties, the service correctly started for all users.

This explains why the service would only start as the current user, and not any of the system users, including the privileged 'Local System' account.



Related Topics



Leave a reply



Submit