ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous WINDEV functions
  • Example for the InServiceMode function
InServiceMode (Example)
Example for the InServiceMode function
// Startup off service?
IF InServiceMode() = False _AND_ InTestMode()=False THEN
// Startup off service: this project being intended to be a service,
// propose to install the service
// Service installed?
IF ServiceExist(gsServiceName) = False THEN
// No
IF YesNo("The service is not installed." + ...
"Do you want to install it now?") = True THEN
// Parameters of the service
// Startup
Service.Startup = serviceStartupManual
Service.DelayedStartup = False
// "Normal" service
Service.Type = serviceTypeSimple
// Description
Service.Description = "WINDEV WDService"
Service.LongDescription = ...
"WINDEV service with restarting in case of failure"
// If an error occurs during the startup, information in the log of events
Service.StartupError = serviceErrorLog
// It is the current executable
Service.CommandLine = ExeInfo(exeName)
// Rights
Service.User = AccountLocalSystem
 
 
// In case of failure...
// Wait during 3 seconds
// (in order for the different service resources
// to be freed
Service.TimeoutBeforeActionOnFailure=(3*1000)
// The number of failures is reinitialized
// after 30 seconds without a failure
Service.ReinitFailureCounter = 30
// Number of authorized failures: 3
Service.NbActionOnFailure=3
 
// First failure: The service restarts
Service.ActionOnFailure[1] = serviceFailureRestartService
// and for the following failures (4 in this example)
// same action
FOR nFailureNum = 2 _TO_ 3
Service.ActionOnFailure[nFailureNum] = ...
serviceFailureRestartService
END
// Installs the service
IF ServiceInstall(gsServiceName) = False THEN
Error("Unable to install the service: '" + ErrorInfo())
ELSE
// Starts the service
IF ServiceStart(gsServiceName) = True THEN
Info("The service was installed and started")
ELSE
Error("The service was installed." ...
" but it cannot be started", ErrorInfo())
END
END
END
ELSE
// Yes
// Service status
nServiceStatus is int
nServiceStatus = ServiceStatus(gsServiceName)
SWITCH nServiceStatus
CASE -1 // Error
Error("Unable to get the service status: ", ...
ErrorInfo())
 
CASE serviceStatusStopped //Service stopped, restart it
//1: Start it
//2: Uninstall it
//3: No action
SWITCH Dialog("The service is currently stopped." + ...
"What do you want to do?")
// Start it
CASE 1
// Starts the service
IF ServiceStart(gsServiceName) = True THEN
Info("The service was installed and started")
ELSE
Error("The service was installed" + ...
" but it cannot be started",ErrorInfo())
END
 
// Uninstall it
CASE 2
IF ServiceUninstall(gsServiceName) = True THEN
Info("The service was uninstalled")
ELSE
Error(...
"The service was not uninstalled", ...
ErrorInfo())
END
// No action
CASE 3
 
END
CASE serviceStatusStarted // Service already started, specify it
IF YesNo("The service is already started." + ...
"Do you want to stop it?") THEN
IF ServiceStop(gsServiceName) = True THEN
Info("The service was successfully stopped")
ELSE
Error("The service cannot be stopped", ...
ErrorInfo())
END
END
 
OTHER CASE // Other status (waiting to be started, to be stopped...)
SWITCH nServiceStatus
CASE serviceStatusStopping
Info("The service is being stopped " + ...
"(a stop command was received" + ...
" but it is not stopped yet)")
CASE serviceStatusStarting
Info("The service is being started " + ...
"(a start request was received " + ...
"but it is not started yet)")
CASE serviceStatusPausing
Info("The service is being paused " + ...
"(a pause request was received " + ...
"but it is not paused yet)")
CASE serviceStatusRestarting
Info("The service is being restarted " + ...
("it recieved a restart command " + ...
"but is is not restarted yet)")
CASE serviceStatusPaused
IF YesNo("The service is currently paused." + ...
"Do you want to re-enable it?") THEN
IF ServiceContinue(gsServiceName) = False THEN
Error("The service is paused" + ...
"it cannot be restarted: ", ...
ErrorInfo())
ELSE
Info("The service was re-enabled")
END
END
OTHER CASE
Error("The service is in an unexpected status: " + ...
nServiceStatus)
END
END
END
EndProgram()
END
Minimum version required
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help