hacking contest

hacking exploits security forum
hacking
compliance articles
upgrade backup exec
information security consultant

UnDeRTaKeR
hi...
iv'e used to work with the old firedamon(80KB one exe) but it won't work on xp.. so i'm trying to manage with the new versions of firedaemon, but they have more then one file and it requires dll's and bla bla.. is there anyway to make the new version of firedaemon to one exe file? and can u please show me how to setup a service with the new firedaemon? by the way... i know srvany/sc/intsrv and others but i don't like them... that's why i'm asking help with firedaemon ONLY
plz help
10x in advance
Serhat
why is it hard with the others?
I am using serviceadd (27.5 KB) works nice here..

CODE
usage: ServiceAdd <IntName> <Label> <Exe>


ServiceAdd MyApp "This App will own you!" c:\MyAPp.exe

is just a little example you can use.. not hard?
Attaching it to this post.. it's easy to use.. why make it hard?

Serhat
UnDeRTaKeR
damn... i didn't say it's hard! i just want to use firedaemon because it start the serviced program every time it crashes.. not as other services managers..
Serhat
Aww oke.. I just wanted to help you out.. sorry for that... wink.gif

Serhat
mrBob
QUOTE (UnDeRTaKeR @ Aug 18 2004, 12:42 AM)
damn... i didn't say it's hard! i just want to use firedaemon because it start the serviced program every time it crashes.. not as other services managers..

you can say that nice too... he's just trying to help
like: thanx for your help but i like firedaemon more because .........
dry.gif


anyway
QUOTE

is there anyway to make the new version of firedaemon to one exe file?


why not put them into an sfx archive ?
or bind the dll's + exe together
there might even be some binders who don't need to unpack the binded files to the hdd before running but they load them straight into the memory (then you got 1 exe smile.gif)
but i never used firedaemon so i'm not sure
UnDeRTaKeR
yes i'm sorry about it... and i ment that i need firedaemon to be one exe as the old version... so all the dll's will be intgerated in it... don't need to extract it... it's hard to expline when u can't understand me :| i'll give u an example of the old firedaemon... and i want one like this...
i've uploaded it...
TRi
MoleBox might be the right thing for ya (www.molebox.com).

QUOTE

MoleBox is a runtime exe packer for Windows applications. MoleBox packs an application and all its data files into a single executable file. MoleBox Pro also allows you to create an executable with a set of data packages as well as to embed DLLs into exe files.

When processing an applications suite, MoleBox compresses and encrypts execytable file, data and media files and DLLs. With MoleBox you can protect your application's data and media files from viewing and modifications, and your DLLs from usage by third party programs.

Moleboxing does not alter the original application's functionality in any way nor requires any additional coding. Unpacking and decryption (if required) are performed automatically and insensibly for application.


smile.gif
UnDeRTaKeR
10x dude i'll give it a try and will notice you
Partizaan
Untertaker ... i yust ran this on an stro wiht firedeamon

____ ____ ___
/ __/_ _____ / _/__ / _/__
_\ \/ // (_-<_ _/ // _ \/ _/ _ \
/___/\_, /___(_)___/_//_/_/ \___/ by riotz
|====/___/====================================================
| OS: Windows NT - Version: 5.1.2600
| OS Language: Polski
| CPU Speed: 2081Mhz
| No. of CPU's: 1
| Computer Name: DOM-JJQR2Z2MAFI
| System uptime: 0:01:00:15
| Current User: SYSTEM
|-------------------------------------------------------------
| Ram: Total: Used: Free:
| -------------------------
| 511 137 (73%) 374
| Drives:
| C:\ 57004 54958 2045 HDD BOOT
| D:\ 53466 23141 30324 HDD BACKUP
| E:\ 3992 2102 1889 HDD RECOVER
|===========================================================

The 80 kb version runs on XP. Proof above ...
otherwise u can use AppToService 2.7 it is the same as firedeamon, iroffer compatible and hexible ... (not that i approov but however ...)
UnDeRTaKeR
I love firedaemon because that even if the program crashes it's start it again..
mmm can u post here your firedaemon? and btw it installs the service but u can see at the screen that an error was made... how ever can u check it? or can u post your firedaemon?
Partizaan
I have the 0.09c 1999-2000



Not edited. dry.gif edit- the same as u have it works fine man

QUOTE
and btw it installs the service but u can see at the screen that an error was made... how ever can u check it?


Please explain more ! blink.gif
pidnull
hey.. the serviceadd.exe dont really work... it adds it... but dosent start it, when i try to start it by net start "name" it goes

The service is not responding to the control function.

More help is available by typing NET HELPMSG 2186.



how do you really use serviceadd?


please reply
UnDeRTaKeR
mmm it starts the service but a winxp error("don't send" blabla) pops up sad.gif
Serhat
QUOTE (pidnull @ Aug 18 2004, 07:50 PM)
The service is not responding to the control function.

More help is available by typing NET HELPMSG 2186.



how do you really use serviceadd?


please reply

Services need to have a control function.. it's called SERVICE ADD.. and services got a control function.. which means you are trying to run stuff which aren't a service..

Serhat
UnDeRTaKeR
hey what about me it's my thread j/k lol biggrin.gif
Serhat
It's your thread but his question =)
also we're here trying to help eachother wink.gif
of course I know you were kidding.. maybe the j/k made me think that.. what do you think? tongue.gif

Serhat
UnDeRTaKeR
lol now i'm confused wacko.gif
Partizaan
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);
}

huh.gif

[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

blink.gif

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.

ph34r.gif 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 !
101
QUOTE (UnDeRTaKeR @ Aug 18 2004, 07:15 PM)
I love firedaemon because that even if the program crashes it's start it again..

You can do it on all service by editing the registry service path dude.
I can't remember what is the command but it should be on the forum,
this is a reg value to add to the service registry path wich restart the exe after 30sec, 15 sec, immediatly etc. after the stop.

so if someone got thos value in logs plz can you copy paste them back ? Im too lazy to search ^^

thx in advance.
UnDeRTaKeR
QUOTE
ntservice.exe - 87 error(s), 26 warning(s)

i suck at compiling... never mind...
i need something easy like firedaemon :|
Serhat
Some more detailed information about app above...

http://www.codeproject.com/system/xyntservice.asp

If you can't get it compiled.. download it here like I did http://www.netcam-watcher.com/runserv.zip
( I got loads of errors while compiling =( )

Don't you just love google? smile.gif

Serhat
UnDeRTaKeR
QUOTE (101 @ Aug 18 2004, 09:35 PM)
You can do it on all service by editing the registry service path dude.
I can't remember what is the command but it should be on the forum,
this is a reg value to add to the service registry path wich restart the exe after 30sec, 15 sec, immediatly etc. after the stop.

so if someone got thos value in logs plz can you copy paste them back ? Im too lazy to search ^^

thx in advance.

YEAP that's what i was looking for.. but did u understand me all the time? lets say the service is running and i'm killing the serviced app so the service will start the app again? smile.gif
101
got them back in old backups, one restart the exe immediatly after the crash , the other restart 30 sec after the crash:

first one:
CODE

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SERVICENAME]
"FailureActions"=hex& #58;80,51,01,00,00,00,00,00,00,00,00,00,03,00,00,00,08,05,15,00,01,00,00,00,60,e
a,00,00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00


another one:
CODE

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SERVICENAME]
"FailureActions"=hex& #58;ff,ff,ff,ff,00,00,00,00,00,00,00,00,01,00,00,00,88,6b,0c,00,01,00,00,00,01,0
0,00,00,


no need of an app to have this option wink.gif

QUOTE (undertaker)

YEAP that's what i was looking for.. but did u understand me all the time? lets say the service is running and i'm killing the serviced app so the service will start the app again?


Yeah of course , after a kill , this is same. Its the method used by some virii, spyware with their boring persistent restart.

bye man.
UnDeRTaKeR
thanks a lot guys that's what i was looking for smile.gif
mrBob
just use start / run --> services.msc
then edit the service options and check the reg dry.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

 
Invision Power Board © 2001-2005 Invision Power Services, Inc.