Run As Service

Run As Service

Postby Jeff Barnes » Wed Jan 28, 2015 9: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 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Jeff Barnes
 
Posts: 920
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Run As Service

Postby Antonio Linares » Thu Jan 29, 2015 10:07 am

Thanks!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41205
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Run As Service

Postby hmpaquito » 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.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm


Return to Utilities / Utilidades

Who is online

Users browsing this forum: No registered users and 5 guests