service 'service name' failed to start. - Advanced Installer Community
f.nourazar
Posts: 2
Joined: Mon Jun 30, 2014 8:05 am

service 'service name' failed to start.

I've added a service in my setup file to be installed. when installing my application, it installs the service but when try to start it, the error 'service 'service name' failed to start.Verify that you have sufficient privileges to start system services ' .
If I don't allow to start service during installation and after installation I start it manually every thing OK. What should I do now?? :(
Please help me
Cmajda
Posts: 3
Joined: Tue Jun 24, 2014 2:23 pm

Re: service 'service name' failed to start.

Hi,
I had same problem, and my solutions is.
1. Add Custom action "Run Windows PowerShell Script"
2. Put this powershell code

Code: Select all

param($accountToAdd)

if( [string]::IsNullOrEmpty($accountToAdd) ) {
	Write-Host "no account specified"
	exit
}

$sidstr = $null
try {
	$ntprincipal = new-object System.Security.Principal.NTAccount "$accountToAdd"
	$sid = $ntprincipal.Translate([System.Security.Principal.SecurityIdentifier])
	$sidstr = $sid.Value.ToString()
} catch {
	$sidstr = $null
}

Write-Host "Account: $($accountToAdd)" -ForegroundColor DarkCyan

if( [string]::IsNullOrEmpty($sidstr) ) {
	Write-Host "Account not found!" -ForegroundColor Red
	exit -1
}

Write-Host "Account SID: $($sidstr)" -ForegroundColor DarkCyan

$tmp = [System.IO.Path]::GetTempFileName()

Write-Host "Export current Local Security Policy" -ForegroundColor DarkCyan
secedit.exe /export /cfg "$($tmp)" 

$c = Get-Content -Path $tmp 

$currentSetting = ""

foreach($s in $c) {
	if( $s -like "SeServiceLogonRight*") {
		$x = $s.split("=",[System.StringSplitOptions]::RemoveEmptyEntries)
		$currentSetting = $x[1].Trim()
	}
}

if( $currentSetting -notlike "*$($sidstr)*" ) {
	Write-Host "Modify Setting ""Logon as a Service""" -ForegroundColor DarkCyan
	
	if( [string]::IsNullOrEmpty($currentSetting) ) {
		$currentSetting = "*$($sidstr)"
	} else {
		$currentSetting = "*$($sidstr),$($currentSetting)"
	}
	
	Write-Host "$currentSetting"
	
	$outfile = @"
[Unicode]
Unicode=yes
[Version]
signature="`$CHICAGO`$"
Revision=1
[Privilege Rights]
SeServiceLogonRight = $($currentSetting)
"@

	$tmp2 = [System.IO.Path]::GetTempFileName()
	
	
	Write-Host "Import new settings to Local Security Policy" -ForegroundColor DarkCyan
	$outfile | Set-Content -Path $tmp2 -Encoding Unicode -Force

	#notepad.exe $tmp2
	Push-Location (Split-Path $tmp2)
	
	try {
		secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS 
		#write-host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS "
	} finally {	
		Pop-Location
	}
} else {
	Write-Host "NO ACTIONS REQUIRED! Account already in ""Logon as a Service""" -ForegroundColor DarkCyan
}

Write-Host "Done." -ForegroundColor DarkCyan
4. Set script Parameters "Account for service"
5. Execution Time > Immediately
6. Put this custom action behind "insatallFinalize" in "Install Execution Stage"

All the best
Michal
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: service 'service name' failed to start.

Hello Nourazar and welcome to Advanced Installer forums,

I'm not sure why you encountered this behavior. You can also try, on the machine on which the service is failing, to type eventvwr.msc in Start->Run to open up the Event Viewer and see if there are any related errors there that might help you pinpoint the issue.

By the way, does your service rely on an assembly presence? If it does, please note that services that rely on the presence of an assembly in the Global Assembly Cache (GAC) cannot be installed or started during the execution of StartServices standard action. If you need to start a service that depends on an assembly in the GAC, you must use a custom action scheduled after the InstallFinalize standard action.

You can try to start your service through a custom action, following these steps:
  • Create a .bat file and paste the following code:

    Code: Select all

    net start "Service Name"
    OBS! The "Service Name" must match the declared "Service Name:" field of your service.
  • Add your .bat file to the project as a temporary file.
  • Select your service control operation from the Services Page and uncheck the "Start" checkbox in "Event on Install" field.
  • Go to the Custom Actions Page and add Launch File after "Finish Execution" action group from "Install Execution Stage". Select the [ Edit... ] button and select your bat file.
Please let me know if that helped.

Hi Michal.
Thank you for sharing this with us. I'm sure this will help further users in the same situation.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”