FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index Utilities / Utilidades Run As Service
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Run As Service
Posted: Wed Jan 28, 2015 09:10 PM
Here is a nice little command line tool to run your exe as a service:

http://runasservice.com/

RunAsService is a command line tool that allows you to setup a regular
console application to run as a service. Below you will find descriptions
and examples of how to do this.
This tool requires that .NET Framework 2.0 be already installed on your computer. If you do not have .NET Framework 2.0 this tool will display a message and not run. You probably already have the .NET Framework 2.0 but if you don't you can download it here: Microsoft Download Center
IMPORTANT: Any services you install using this tool will
require that this tool remain on that computer in the same
location in order for those services to continue functioning. Therefore
before installing any services you should make sure this tool is
somewhere where it can remain permanently. If you do end up moving
this tool use the 'fixservices' action to fix the existing services.
(details on how to use 'fixservices' can be found below)

RunAsService
Typing just the name of the tool without specifying any parameters.
Or specifying incorrect paramters will bring you to the help screen.

RunAsService install [Name] [Display Name] PathToExecutable
Name
The name of the service, if none is specified the name
will default to the name of the executable.

You might choose to give it a different name than
the executable to keep some kind of existing convention,
make it friendlier or make it easier to use commands like
'net start' and 'net stop'

Display Name
This is how the service name will be displayed in the windows
services list. If no display name is specified it will default
to Name, if Name is not specified, it will default to the name
of the executable.

Generally the display name is longer and more descriptive
than the name and gives the user a better idea of what
the service is and/or does.

PathToExecutable
The location of the application you want to run as a service.

Note, the tool will check if this executable exists, if it
doesn't find it will not install it.

RunAsService uninstall Name
Name
The name of the service you would like to uninstall.

RunAsService fixservices
Use this action when you've moved the RunAsService executable.
Services installed using RunAsService require that RunAsService
remain on the computer and at the same location if
you move it the services will stop working, use this
action to fix that.

EXAMPLES

RunAsService install "c:\my apps\Myapp.exe"
Installs Myapp as a service called "Myapp"

RunAsService install "My Service" "c:\my apps\Myapp.exe"
Installs Myapp as a service called "My Service"

RunAsService install "My Service" "My Super Cool Service" "c:\my apps\Myapp.exe"
Installs Myapp as a service internally called "My Service"
when using commands like 'net start' and 'net stop' and shows
up as "My Super Cool Service" in Window's services list.

RunAsService uninstall "My Service"
Uninstalls the service.

RunAsService fixservices
Use this action if you move this tool. This is because services
installed using this tool rely on this tool remaining on that
computer and at the same location. If you do not call 'fixservices'
after moving this tool the existing services installed using this
tool will stop functioning.

NOTES

You can use Windows built in commands to start and stop your
services. For example you can use:
net start "My Service"
and
net stop "My Service"

Where "My Service" would be replaced with the name of your service.

CREDITS

This tool was created by Luis Perez on April 2011. For more
information or to contact me visit RunAsService.com.
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Run As Service
Posted: Thu Jan 29, 2015 10:07 AM

Thanks!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Run As Service
Posted: Thu Jan 29, 2015 10:25 AM
http://objectmix.com/xharbour/779023-wi ... rvice.html
http://www.pctoledo.com.br/forum/viewto ... 437#p77865


Adem谩s por ah铆 ten铆a esta documentaci贸n. Cr茅ditos a su autor.
EJECUCI脫N DE UN PROGRAMA EN EL ARRANQUE DE WINDOWS

Aqu铆 est谩n todas las formas de ejecutar un programa al inicio de Windows....

Se pueden agregar accesos, o sea especificar ruta y ejecutable directamente dentro de las siguientes ubicaciones dentro del registro de Windows:

Por ejemplo:

HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Run

Ejecuta los items almacenados en esta ubicaci贸n de tu registro autom谩ticamente comenzado cuando el usuario actual s贸lo es logeado. En los usuarios con m煤ltiples usuarios o cuentas, esta informaci贸n puede cambiar dependiendo de quien fue el que se logueo, por ejemplo cuando se ingresa a un sistema conectado a una red y quiere tener acceso bajo Windows NT.

HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\RunOnce

Ejecuta los items almacenado en la ubicaci贸n denominado exactamente de la misma manera que la anterior, pero s贸lo una vez y son autom谩ticamente removidos.


HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\Run

Se ejecutan los items almacenados en esta ubicaci贸n del registro autom谩ticamente en cada nueva sesi贸n, sin importar quien se logue.


HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\RunOnce

Se ejecutan los items almacenados en esta ubicaci贸n igualmente que el punto anterior, pero s贸lo una vez.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\RunOnceEx

Se ejecutan los items almacenados en esta ubicaci贸n del registro, sin importar quien se ha logueado.


HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\RunServices

Los Items almacenados en esta ubicaci贸n del registro ser谩n ejecutados autom谩ticamente como "servicios" (m谩s aplicable bajo Windows NT), dichos programas ser谩n ejecutados antes de que cualquier otro programa sea cargado y se continua su ejecuci贸n inclusive despu茅s de que el sistema sea bloqueado, y no aparecer谩n al pulsar las teclas CTRL+ATL+DEL.

Aqu铆 les traduce un art铆culo publicado en la p谩gina de Patrick Mast, gracias a 茅l....

Esto est谩 muy bueno para cargar aplicaciones ocultas, pero realmente como hago para que funcione ?

Al instalar la aplicaci贸n como proceso de servicio, la aplicaci贸n correr谩 de fondo en forma invisible, siendo invisible en la carpeta de aplicaciones del administrador de tareas. Las aplicaciones que corren como un proceso de servicios no se detendr谩n por m谩s que el usuario se desloguee, seguir谩 ejecut谩ndose. Como muestra de una aplicaci贸n que se ejecuta como proceso de servicio se encuentra Symatec WinFax. El programa este recibe siempre los faxes entrantes, por m谩s que el usuario se encuentre deslogueado.
Hay dos ventajas principales de correr una aplicaci贸n con proceso de servicio: Ser invisible en la pantalla de el administrador de tareas, y seguir ejecut谩ndose por m谩s que el usuario se desloguee.

Ahora, como se puede hacer que una aplicaci贸n FiveWin sea un proceso de Servicio? Bueno, la funci贸n del Api de Windows "RegisterServiceProcess" es la soluci贸n. Esta funci贸n registra y desregistra una aplicaci贸n como un proceso de servicio. La funci贸n del Api de Windows "RegisterServiceProcess" acepta dos par谩metros. El primer par谩metro es la identificaci贸n del proceso de la aplicaci贸n (ID). Para obtener el ID del proceso, usaremos otra funci贸n del Api de Windows llamada "GetCurrentProcessId". Esta llamada a la funci贸n del Api de Windows no necesita par谩metros. El segundo par谩metro de "RegisterServiceProcess" especifica si el servicio es registrado o desregistrado. Un valor de 1 registra la aplicaci贸n, y 0 la desregistra.

Ejemplo un programa:

Function Main()
ServiceProcess(1)
/*
Aqu铆 tu c贸digo...
*/
Return NIL

Function ServiceProcess( mode )

Local nProcessId := 0
Default mode := 0
nProcessId := GCP( )
If Abs( nProcessId ) > 0
RSProcess( nProcessId, mode )
Endif
RETURN

DLL32 FUNCTION RSProcess(npID AS LONG , nMode AS LONG ) ;
AS LONG FROM "RegisterServiceProcess" LIB "kernel32.DLL"

DLL32 FUNCTION GCP() AS LONG FROM "GetCurrentProcessId" LIB "kernel32.dll"


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\RunServicesOnce

Los items almacenados en esta ubicaci贸n del registro ser谩n autom谩ticamente ejecutados como "servicios", pero s贸lo una vez, esto es m谩s utilizado bajo Windows NT, el resto es igual que el punto anterior.



Ahora se pueden agregar accesos igual que en los puntos anteriores dentro del archivo "Win.ini". El archivo Win.ini es un archivo de inicializaci贸n que almacena los datos de configuraci贸n de su sistema y es procesado en el comienzo de cada sesi贸n de Windows. Dentro de este archivo hay dos secciones donde las aplicaciones pueden ser agregadas con s贸lo colocar Load o Run, pero esto es m谩s usado por compatibilidad con Windows 3.11 y aconsejo que se usen los puntos anteriores, ya que es m谩s dif铆cil de modificar.


Para modificar los puntos anteriores recomiendo usar la clase TREG32.

Continue the discussion