delphi - How to start my Windows Service at RunTime or at OnAfterInstall -
history
i building windows service
part of platform application
handle updates , server functions, can installed in machines different client application
installed. uses udp send , receive broadcast messages, , tcp to handle more sensitive , important messages.
objective
i want application installed end user, copying executable files in computers , when executing them. main application should verify if user administrator, create configuration files, , install windows service , run it, when non administrative users log in, won't receive error application regarding administrative rights. goal make configurations without need present technician, since database remote.
problem
my service being installed command myservice.exe /install
not starting automatically. way start go on control panel > admin tools > services
, manually. tryed call net start myservice
through application receive invalid service name
@ shell. tryied executable name
, display name
, object name
of service, none of them worked. object of tservice:
object servicemaincontroller: tservicemaincontroller oldcreateorder = false oncreate = servicecreate displayname = 'platformupdateservice' interactive = true afterinstall = serviceafterinstall afteruninstall = serviceafteruninstall onshutdown = serviceshutdown onstart = servicestart onstop = servicestop height = 210 width = 320
question
what should start service code , not user hands? best if inside client application, or when after onserviceafterinstall
call.
here's sample startservice
call, in afterinstall
event:
procedure tservicemaincontroller.serviceafterinstall(sender: tservice); var manager, service: sc_handle; begin manager := openscmanager(nil, nil, sc_manager_all_access); win32check(manager <> 0); try service := openservice(manager, pchar(name), service_all_access); win32check(service <> 0); try win32check(startservice(service, 0, pchar(nil^))); closeservicehandle(service); end; closeservicehandle(manager); end; end;
however i'm not sure work you, should have success net start
too.
Comments
Post a Comment