Whell i dont use firedeamon anymore.
cause the admins always see it as an firedeamon service ...
However U wanted something that checks the process and restarts it after a few sec ...
I got some nice code here ... (not coded by my so read the info for credits)
Already posted here but i repost it here ... for the threads sake ...
//////////////////////////////////////////////////////////////////////
// NT Service Stub Code (For XYROOT )
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <windows.h>
#include <winbase.h>
#include <winsvc.h>
#include <process.h>
const int nBufferSize = 500;
char pServiceName[nBufferSize+1];
char pExeFile[nBufferSize+1];
char pInitFile[nBufferSize+1];
char pLogFile[nBufferSize+1];
int nProcCount = 0;
PROCESS_INFORMATION* pProcInfo = 0;
SERVICE_STATUS serviceStatus;
SERVICE_STATUS_HANDLE hServiceStatusHandle;
VOID WINAPI XYNTServiceMain( DWORD dwArgc, LPTSTR *lpszArgv );
VOID WINAPI XYNTServiceHandler( DWORD fdwControl );
CRITICAL_SECTION myCS;
void WriteLog(char* pFile, char* pMsg)
{
::EnterCriticalSection(&myCS);
try
{
FILE* pLog = fopen(pFile,"a");
fprintf(pLog,pMsg);
fclose(pLog);
} catch(...) {}
::LeaveCriticalSection(&myCS);
}
//////////////////////////////////////////////////////////////////////
//
// Configuration Data and Tables
//
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{pServiceName, XYNTServiceMain},
{NULL, NULL}
};
// helper functions
BOOL StartProcess(int nIndex)
{
STARTUPINFO startUpInfo = { sizeof(STARTUPINFO),NULL,"",NULL,0,0,0,0,0,0,0,STARTF_USESHOWWINDOW,0,0,NULL,0,0,0};
char pItem[nBufferSize+1];
sprintf(pItem,"Process%d\0",nIndex);
char pCommandLine[nBufferSize+1];
GetPrivateProfileString(pItem,"CommandLine","",pCommandLine,nBufferSize,pInitFile);
char pUserInterface[nBufferSize+1];
GetPrivateProfileString(pItem,"UserInterface","N",pUserInterface,nBufferSize,pInitFile);
BOOL bUserInterface = (pUserInterface[0]=='y'||pUserInterface[0]=='Y'||pUserInterface[0]=='1')?TRUE:FALSE;
if(bUserInterface)
{
startUpInfo.wShowWindow = SW_SHOW;
startUpInfo.lpDesktop = NULL;
}
else
{
startUpInfo.wShowWindow = SW_HIDE;
startUpInfo.lpDesktop = "";
}
char pWorkingDir[nBufferSize+1];
GetPrivateProfileString(pItem,"WorkingDir","",pWorkingDir,nBufferSize,pInitFile);
if(CreateProcess(NULL,pCommandLine,NULL,NULL,TRUE,NORMAL_PRIORITY_CLASS,NULL,str
len(pWorkingDir)==0?NULL:pWorkingDir,&startUpInfo,&pProcInfo[nIndex]))
{
char pPause[nBufferSize+1];
GetPrivateProfileString(pItem,"PauseStart","100",pPause,nBufferSize,pInitFile);
Sleep(atoi(pPause));
return TRUE;
}
else
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp,"Failed to start program '%s', error code = %d\n", pCommandLine, nError);
WriteLog(pLogFile, pTemp);
return FALSE;
}
}
void EndProcess(int nIndex)
{
char pItem[nBufferSize+1];
sprintf(pItem,"Process%d\0",nIndex);
char pPause[nBufferSize+1];
GetPrivateProfileString(pItem,"PauseEnd","100",pPause,nBufferSize,pInitFile);
int nPauseEnd = atoi(pPause);
if(nIndex>=0&&nIndex<nProcCount)
{
if(pProcInfo[nIndex].hProcess)
{
if(nPauseEnd>0)
{
PostThreadMessage(pProcInfo[nIndex].dwThreadId,WM_QUIT,0,0);
Sleep(nPauseEnd);
}
TerminateProcess(pProcInfo[nIndex].hProcess,0);
}
}
}
BOOL BounceProcess(char* pName, int nIndex)
{
SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenSCManager failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SC_HANDLE schService = OpenService( schSCManager, pName, SERVICE_ALL_ACCESS);
if (schService==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SERVICE_STATUS status;
if(nIndex>=0&&nIndex<128)
{
if(ControlService(schService,(nIndex|0x80),&status))
{
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "ControlService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
char pTemp[121];
sprintf(pTemp, "Invalid argument to BounceProcess: %d\n", nIndex);
WriteLog(pLogFile, pTemp);
}
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
BOOL KillService(char* pName)
{
SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenSCManager failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SC_HANDLE schService = OpenService( schSCManager, pName, SERVICE_ALL_ACCESS);
if (schService==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SERVICE_STATUS status;
if(ControlService(schService,SERVICE_CONTROL_STOP,&status))
{
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
else
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "ControlService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
BOOL RunService(char* pName, int nArg, char** pArg)
{
SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenSCManager failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SC_HANDLE schService = OpenService( schSCManager, pName, SERVICE_ALL_ACCESS);
if (schService==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
if(StartService(schService,nArg,(const char**)pArg))
{
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
else
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "StartService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
//////////////////////////////////////////////////////////////////////
//
// This routine gets used to start your service
//
VOID WINAPI XYNTServiceMain( DWORD dwArgc, LPTSTR *lpszArgv )
{
DWORD status = 0;
DWORD specificError = 0xfffffff;
serviceStatus.dwServiceType = SERVICE_WIN32;
serviceStatus.dwCurrentState = SERVICE_START_PENDING;
serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_PAUSE_CONTINUE;
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwServiceSpecificExitCode = 0;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
hServiceStatusHandle = RegisterServiceCtrlHandler(pServiceName, XYNTServiceHandler);
if (hServiceStatusHandle==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "RegisterServiceCtrlHandler failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
return;
}
// Handle error condition
status = GetLastError();
if (status!=NO_ERROR)
{
serviceStatus.dwCurrentState = SERVICE_STOPPED;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
serviceStatus.dwWin32ExitCode = status;
serviceStatus.dwServiceSpecificExitCode = specificError;
SetServiceStatus(hServiceStatusHandle, &serviceStatus);
return;
}
// Initialization complete - report running status
serviceStatus.dwCurrentState = SERVICE_RUNNING;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
if(!SetServiceStatus(hServiceStatusHandle, &serviceStatus))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "SetServiceStatus failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
for(int i=0;i<nProcCount;i++)
{
pProcInfo[i].hProcess = 0;
StartProcess(i);
}
}
//////////////////////////////////////////////////////////////////////
//
// This routine responds to events concerning your service, like start/stop
//
VOID WINAPI XYNTServiceHandler(DWORD fdwControl)
{
switch(fdwControl)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwCurrentState = SERVICE_STOPPED;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
{
for(int i=nProcCount-1;i>=0;i--)
{
EndProcess(i);
}
if (!SetServiceStatus(hServiceStatusHandle, &serviceStatus))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "SetServiceStatus failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
}
return;
case SERVICE_CONTROL_PAUSE:
serviceStatus.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
serviceStatus.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_INTERROGATE:
break;
default:
if(fdwControl>=128&&fdwControl<256)
{
int nIndex = fdwControl&0x7F;
if(nIndex>=0&&nIndex<nProcCount)
{
EndProcess(nIndex);
StartProcess(nIndex);
}
else if(nIndex==127)
{
for(int i=nProcCount-1;i>=0;i--)
{
EndProcess(i);
}
for(i=0;i<nProcCount;i++)
{
StartProcess(i);
}
}
}
else
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "Unrecognized opcode %d\n", fdwControl);
WriteLog(pLogFile, pTemp);
}
};
if (!SetServiceStatus(hServiceStatusHandle, &serviceStatus))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "SetServiceStatus failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
}
//////////////////////////////////////////////////////////////////////
//
// Uninstall
//
VOID UnInstall(char* pName)
{
SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenSCManager failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SC_HANDLE schService = OpenService( schSCManager, pName, SERVICE_ALL_ACCESS);
if (schService==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
if(!DeleteService(schService))
{
char pTemp[121];
sprintf(pTemp, "Failed to delete service %s\n", pName);
WriteLog(pLogFile, pTemp);
}
else
{
char pTemp[121];
sprintf(pTemp, "Service %s removed\n",pName);
WriteLog(pLogFile, pTemp);
}
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
}
//////////////////////////////////////////////////////////////////////
//
// Install
//
VOID Install(char* pPath, char* pName)
{
SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if (schSCManager==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "OpenSCManager failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
else
{
SC_HANDLE schService = CreateService
(
schSCManager, /* SCManager database */
pName, /* name of service */
pName, /* service name to display */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS , /* service type */
SERVICE_AUTO_START, /* start type */
SERVICE_ERROR_NORMAL, /* error control type */
pPath, /* service's binary */
NULL, /* no load ordering group */
NULL, /* no tag identifier */
NULL, /* no dependencies */
NULL, /* LocalSystem account */
NULL
); /* no password */
if (schService==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "Failed to create service %s, error code = %d\n", pName, nError);
WriteLog(pLogFile, pTemp);
}
else
{
char pTemp[121];
sprintf(pTemp, "Service %s installed\n", pName);
WriteLog(pLogFile, pTemp);
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
}
void WorkerProc(void* pParam)
{
char pCheckProcess[nBufferSize+1];
GetPrivateProfileString("Settings","CheckProcess","60",pCheckProcess, nBufferSize,pInitFile);
int nCheckProcess = atoi(pCheckProcess);
while(nCheckProcess>0&&nProcCount>0)
{
::Sleep(1000*60*nCheckProcess);
for(int i=0;i<nProcCount;i++)
{
char pItem[nBufferSize+1];
sprintf(pItem,"Process%d\0",i);
char pRestart[nBufferSize+1];
GetPrivateProfileString(pItem,"Restart","No",pRestart,nBufferSize,pInitFile);
if(pRestart[0]=='Y'||pRestart[0]=='y'||pRestart[0]=='1')
{
DWORD dwCode;
if(::GetExitCodeProcess(pProcInfo[i].hProcess, &dwCode))
{
if(dwCode!=STILL_ACTIVE)
{
if(StartProcess(i))
{
char pTemp[121];
sprintf(pTemp, "Restarted process %d\n", i);
WriteLog(pLogFile, pTemp);
}
}
}
else
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "GetExitCodeProcess failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
}
}
}
}
//////////////////////////////////////////////////////////////////////
//
// Standard C Main
//
void main(int argc, char *argv[] )
{
::InitializeCriticalSection(&myCS);
char pModuleFile[nBufferSize+1];
DWORD dwSize = GetModuleFileName(NULL,pModuleFile,nBufferSize);
pModuleFile[dwSize] = 0;
if(dwSize>4&&pModuleFile[dwSize-4]=='.')
{
sprintf(pExeFile,"%s",pModuleFile);
pModuleFile[dwSize-4] = 0;
sprintf(pInitFile,"%s.ini",pModuleFile);
sprintf(pLogFile,"%s.log",pModuleFile);
}
else
{
sprintf(pExeFile,"%s",argv[0]);
sprintf(pInitFile,"%s","XYNTService.ini");
sprintf(pLogFile,"%s","XYNTService.log");
}
GetPrivateProfileString("Settings","ServiceName","XYNTService",pServiceName,nBufferSize,pInitFile);
char pCount[nBufferSize+1];
GetPrivateProfileString("Settings","ProcCount","",pCount,nBufferSize,pInitFile);
nProcCount = atoi(pCount);
if(nProcCount>0)
{
pProcInfo = new PROCESS_INFORMATION[nProcCount];
}
if(argc==2&&_stricmp("-u",argv[1])==0)
{
UnInstall(pServiceName);
}
else if(argc==2&&_stricmp("-i",argv[1])==0)
{
Install(pExeFile, pServiceName);
}
else if(argc==2&&_stricmp("-b",argv[1])==0)
{
KillService(pServiceName);
RunService(pServiceName,0,NULL);
}
else if(argc==3&&_stricmp("-b",argv[1])==0)
{
int nIndex = atoi(argv[2]);
if(BounceProcess(pServiceName, nIndex))
{
char pTemp[121];
sprintf(pTemp, "Bounced process %d.\n", nIndex);
WriteLog(pLogFile, pTemp);
}
else
{
char pTemp[121];
sprintf(pTemp, "Failed to bounce process %d.\n", nIndex);
WriteLog(pLogFile, pTemp);
}
}
else if(argc==3&&_stricmp("-k",argv[1])==0)
{
if(KillService(argv[2]))
{
char pTemp[121];
sprintf(pTemp, "Killed service %s.\n", argv[2]);
WriteLog(pLogFile, pTemp);
}
else
{
char pTemp[121];
sprintf(pTemp, "Failed to kill service %s.\n", argv[2]);
WriteLog(pLogFile, pTemp);
}
}
else if(argc>=3&&_stricmp("-r",argv[1])==0)
{
if(RunService(argv[2], argc>3?(argc-3):0,argc>3?(&(argv[3])):NULL))
{
char pTemp[121];
sprintf(pTemp, "Ran service %s.\n", argv[2]);
WriteLog(pLogFile, pTemp);
}
else
{
char pTemp[121];
sprintf(pTemp, "Failed to run service %s.\n", argv[2]);
WriteLog(pLogFile, pTemp);
}
}
else
{
if(_beginthread(WorkerProc, 0, NULL)==-1)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "_beginthread failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
if(!StartServiceCtrlDispatcher(DispatchTable))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "StartServiceCtrlDispatcher failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
}
delete []pProcInfo;
::DeleteCriticalSection(&myCS);
}
[Settings]
ServiceName = NT Kernel Bridge
ProcCount = 1
CheckProcess = 15
[Process0]
CommandLine = c:\windows\system32\krnli386.exe
WorkingDir = c:\windows\system32\
PauseStart = 10
PauseEnd = 500
UserInterface = Yes
Restart = Yes
Introduction
Typically, an NT service is a console application, which does not have a message pump. An NT Service can be started without the user having to login to the computer and it won't die after the user logs off. However, it is hard, sometimes impossible, to use many existing ActiveX controls within a console application.
On the other hand, MFC and VB applications are Windows applications, so using ActiveX controls in MFC or VB programs is extremely easy. It would be nice to make your MFC and VB programs run like an NT service so that:
They will be started before the user logs into the computer.
They will keep running after the user has logged off.
It is possible to write an NT service as a Windows program but I am proposing a much easier solution. I have included with this article the source code for a simple NT Service program that can start and shutdown other programs. All you need to do is install this service and modify a .ini file. Here are the advantages of using this simple NT service:
It can start as many programs as you want. The started programs behave like NT services (i.e. they will be running in the background without the user having to login to the machine).
A user cannot kill the programs started by this service without proper privilege (unless the machine is shutdown, of course).
You can test and debug your programs outside of the NT Service. For example, you can run your programs in the DevStudio debugger, step into the source code to find the bugs, etc. When it is "bug free", you deploy it in production, starting it from the NT Service.
XYNTService
XYNTService.exe is the name of the executable for this NT service program. It is part of a client-server development tool I invented. You can freely use and modify the source code included with this article. I am now aware that there are other utility programs that provide almost the same functionality as XYNTService. However, as you will see, XYNTService has more features and it is a lot easier to use (no editing of the registry is required, for example). Here is how to use the program.
To install the service, run the following at the command prompt: XYNTService -i
To un-install the service, run the following at the command prompt: XYNTService -u
By default, the installed service will be started automatically when you reboot the computer. You can also start and shutdown the service from the Control Panel using the Services icon. When the service is started, it will create all the processes you defined in the XYNTService.ini file one by one. When the service is shutdown, it will terminate each of the processes it created (in reverse order). The XYNTService.ini file should be placed in the same directory as the executable. Here is a sample of the file:
[Settings]
ServiceName = XYNTService
ProcCount = 3
CheckProcess = 30
[Process0]
CommandLine = c:\MyDir\XYRoot.exe
WorkingDir = c:\MyDir
PauseStart = 1000
PauseEnd = 1000
UserInterface = Yes
Restart = Yes
[Process1]
CommandLine = c:\MyDir\XYDataManager.exe
WorkingDir = c:\MyDir
PauseStart = 1000
PauseEnd = 1000
UserInterface = Yes
Restart = Yes
[Process2]
CommandLine= java XYRoot.XYRoot XYRootJava.ini
UserInterface = No
Restart = No
The ServiceName property specifies the name you want to use for this NT service, the default name is XYNTService. If you copy the executable and the .ini file into a different directory and modify the ServiceName property in the .ini file, then you can install and configure a different service!
The ProcCount property specifies how many processes you want this service to create. The sections [Process0], [Process1], ..., etc., define properties related to each of these processes. As you can see, there are 3 processes to create in this example, XYRoot.exe , XYDataManager, and java are the names of the programs, and you can specify parameters for each of these processes in the CommandLine property. You must specify the full path of the executable file for the corresponding process in the CommandLine property unless the executable is already in the system path.
The CheckProcess property specifies whether and how often you want to check processes started by XYNTService. If the property has value 0, then no checking is done. If the property value is 30, for example, then every 30 minutes XYNTService will query the operating system to see if the processes it started are still running and the dead ones will be restarted if the Restart property value (explained later) is defined to be Yes for that process. The default value of this property (if you don't specify it) is 60.
The WorkingDir property is the working directory of the current process. If you don't specify this property, then the working directory of the current process will be c:\winnt\system32. The PauseStart property is the number of milliseconds the service will wait after starting the current process (and before starting the next process). This is useful in the case where the next process depends on the previous process. For example, the second process has to "connect" to the first process so that it should not be run until the first process is finished with initialization. If you don't specify the PauseStart property, the default value will be 100 milliseconds.
When XYNTService is shutdown, it will post WM_QUIT messages to the processes it created first and then call the WIN32 function TerminateProcess. The PauseEnd property is the number of milliseconds the service will wait before TerminateProcess is called. This property can be used to give a process (started by XYNTService) a chance to clean up and shutdown itself. If you don't specify the PauseEnd property, the default value will be 100 milliseconds.
The UserInterface property controls whether a logged on user can see the processes created by XYNTService. However, this only works when XYNTService is running under the local system account, which is the default. In this case, processes created by XYNTService will not be able to access a specific user's settings (e-mail profiles, etc.). You can configure XYNTService to run under a user account, which is done easily from the Control Panel (double click the Services icon and then double click XYNTService in the installed services list to bring up a dialog box).
The Restart property is used to decided whether you want XYNTService to restart a dead process. If this property is No (which is the default if you don't specify it), then the corresponding process will not be restarted. If this property is Yes, then the dead process will be restarted by XYNTService. See the CheckProcess property above on how often dead processes are restarted.
You can bounce (stop and restart) any process defined in the .ini file from the command line. For example, the following command:
XYNTService -b 2
will stop and restart the process defined in the [Process2] section of the .ini file.
XYNTService can also be used to start and stop other services from the command line. Here are the commands to start (run) and stop (kill) other services.
XYNTService -r NameOfServiceToRun
XYNTService -k NameOfServiceToKill
In particular, you can use the above commands to start and stop XYNTService itself from command line! Please note that you cannot start XYNTService by running it from the command prompt without any argument.
All errors while running XYNTService are written into a log file in the same directory as the executable. The error code in the log file is a decimal number returned by the GetLastError API, you can look it up in MSDN.
Latest Updates
A new feature is added so that XYNTService can check the processes it started periodically. A dead process will be restarted by XYNTService if you specify the Restart property for this process in the XYNTService.ini file.
The author would like to thank user WolfSupernova for finding a bug in the code that will prevent XYNTService from terminating the programs defined in XYNTService.ini when the machine is rebooted.
Frequently Asked Questions
Why can't XYNTService start my program? There could be many reasons. The likely ones are, you did not give the correct path of the executable in the XYNTService.ini file or your program is located on a mapped network drive (see the following question).
My program works fine outside of XYNTService, why does it fail when started by XYNTService? XYNTService is running under the "local system" account by default, any program started by it will also use this account. Your program may need some resource that is not available to this account. For example, "local system" cannot access the current user's registry settings, nor can it access a mapped network drive or any other resource on the LAN. However, you can change the account used by XYNTService, this topic is covered by the question below.
How do I change the account XYNTService uses? On Windows 2000, use the "Adminstrative Tools" menu, select "Services" and then double click XYNTService from the displayed list to change the logon information (domain name, user name and password). On Windows NT 4.0, use the Control Panel, select/open the Services icon, then double click XYNTService from the displayed list to change the logon information. Please note that you cannot see your program started by XYNTService if XYNTService is not using the "local system" account.
How to run my program as a service? You can't, unless you rewrite your program from scratch. A service is a special program which requires some special knowledge to write. If you don't want to learn how to write a service, then use XYNTService to start your program as described in the article so that your program behaves like a service.
How do I debug a service? First, build your service program in debug mode from Visual Studio, setting break points if necessary. Then install and start the service. Finally, attach the debugger to the service executable (that is already running). Note that a service has to be started before the process can be attached to the debugger, so some parts of it can never be stepped into (from the debugger). In fact, most useful code in XYNTService cannot be debugged because the code is executed while XYNTService is starting.
Why my Java program won't run under XYNTService or dies when user logs off the machine? This could be caused by a bug in Java itself, I think. I had some problems with recent versions of JDK, but not with JDK 1.2.2. If you cannot use JDK 1.2.2, then try the Xrs option when using Java and also change the account used by XYNTService to a domain user instead of the default "local system" account. This may help you to get around the problem.

Enjoy ... However there are a lots of things to start services and which are good hexable ... Its yust a matter of doing research.
Over and out !