Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 1 Jahr, 1 Monat
Letzter Beitrag:
vor 1 Jahr, 1 Monat
Beteiligte Autoren:
Curtis, Fabrice Harari, Peter Holemans

[WD20] Error Installing Service (Access is denied)

Startbeitrag von Curtis am 27.03.2017 16:13

I am unable to install a service I created with WinDev. I'm trying to install the service from the project init code of another app. I am on an admin account and I'm running the app in test mode. I receive a system error code of '5' and a system error of 'Access is denied'.

IF NOT ServiceExist("AbcUpdate") THEN
sServicePath is string = "C:\PathIsCorrect\AbcUpdate.exe"
Service.Description = "Update service for Abc products."
Service.Startup = serviceStartupAutomatic
Service.DelayedStartup = True
Service.StartupError = serviceErrorSerious
Service.CommandLine = sServicePath
Service.User = AccountLocalSystem
Service.Type = serviceTypeSimple

IF ServiceInstall("AbcUpdate") THEN
IF NOT ServiceStart("AbcUpdate") THEN
// Log Error
Error("ServiceInstall('AbcUpdate'). '" + ErrorInfo(errFullDetails) + "'")
// Log Error
Error("ServiceInstall('AbcUpdate'). '" + ErrorInfo(errFullDetails) + "'")


Hi Curtis,

In the past I encountered too many constraints using the built-in service variable and functions of WLanguage. Guess it's half baked as well...
I replaced all this by using the SC commands instead (in admin mode) which works like a charm...
E.g. To install a service:

sc create "Update service for abc products" binpath= "C:\PathIsCorrect\AbcUpdate.exe"

E.g. To config the service on e.g. impersonation (run as):

sc config "Update service for abc products" obj= "username" password= "password"

E.g. To delete the service from the system:

sc delete "Update service for abc products"

To safely start a service (even on a remote server/machine) you can use this command script (e.g; SafeServiceStart.cmd) :
Sample call:
CALL "C:\scriptpath\SafeServiceStart.cmd" Servername "Update service for abc products"
Content of SafeServiceSart.cmd:

@echo off
:: This script originally authored by Eric Falsken, edited and bug fixed by Peter Holemans

if [%1]==[] GOTO GetHostName
IF [%1]==[] GOTO usage
IF [%2]==[] GOTO usage

REM ping -n 1 %1 | FIND "TTL=" >NUL
REM IF errorlevel 1 GOTO SystemOffline
SC \\%1 query %2 | FIND "STATE" >NUL
IF errorlevel 1 GOTO SystemOffline

SC \\%1 query %2 | FIND "STATE" | FIND "STOPPED" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO StartService
SC \\%1 query %2 | FIND "STATE" | FIND "RUNNING" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO StartedService
SC \\%1 query %2 | FIND "STATE" | FIND "PAUSED" >NULL
IF errorlevel 0 IF NOT errorlevel 1 GOTO SystemOffline
echo Service State is changing, waiting for service to resolve its state before making changes
sc \\%1 query %2 | Find "STATE"
timeout /t 2 /nobreak >NUL
GOTO ResolveInitialState

echo Starting %2 on \\%1
sc \\%1 start %2 >NUL
IF errorlevel 1 GOTO CommandFailed

GOTO StartingService

echo Waiting for %2 to start
timeout /t 2 /nobreak >NUL

SC \\%1 query %2 | FIND "STATE" | FIND "RUNNING" >NUL
IF errorlevel 1 GOTO StartingServiceDelay

echo %2 on \\%1 is started

echo Server \\%1 is not accessible or is offline

echo SC Command failed for \\%1 service %2


echo This function Will start a remote service
echo This script will wait for the service to enter the started state if necessary
echo SafeServiceSTART [system name] [service name]
echo Example: SafeServiceSTART server1 MyService

I also have scripts for safe restarting and safe stopping if anyone is interested.

All the best,

Peter Holemans

von Peter Holemans - am 28.03.2017 07:59

in order to install a service, you should be in admin mode.
To be in admin mode, EVEN in an admin account, you need to right click on the application and do a "run as administrator"

So I'm not surprised that in test mode in a windev editor NOT started in admin mode, you would have this kind of problem.

Best regards

von Fabrice Harari - am 28.03.2017 21:50
Thanks y'all! Is there anyway within WinDev to elevate to admin before running my service install code?

For the time being, I've created a timed procedure in my app that prompts to update the app if there is an update available. This runs once an hour. It's working well. At this point I'm not sure if it's even worth creating the service.

von Curtis - am 29.03.2017 16:32
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.