Search
 
 
  Engleski
 
 
 
Open in this window (click to change)
Forum@DeGiorgi: Početna
Forum za podršku nastavi na PMF-MO
Login Registracija FAQ Smajlići Članstvo Pretražnik Forum@DeGiorgi: Početna

NT servis u C++
WWW:

Moja sarma
 
Započnite novu temu   Odgovorite na temu   printer-friendly view    Forum@DeGiorgi: Početna -> Kolegiji diplomskih i starih studija -> Objektno programiranje (C++)
Prethodna tema :: Sljedeća tema  
Autor/ica Poruka
Gost






PostPostano: 16:13 čet, 5. 6. 2008    Naslov: NT servis u C++ Citirajte i odgovorite

kako da napravim program koji radi kao servis (NT servis).
program čita txt datoteku, dje je napisano datum,sat i poruka, i na ovaj sat i datum javi poruko

dio programa:

[code:1]
#include "process.h"
#include "iostream"
#include "time.h"
#include "fstream"
#include "string"
#include "tchar.h"
#include "stdio.h"
#include "windows.h"
#include "winbase.h"
#include "winsvc.h"

// Service.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#define MAX_NUM_OF_PROCESS 4
/** Window Service **/
VOID ServiceMainProc();
VOID Install(char* pPath, char* pName);
VOID UnInstall(char* pName);
VOID WriteLog(char* pFile, char* pMsg);
BOOL KillService(char* pName);
BOOL RunService(char* pName);
VOID ExecuteSubProcess();
VOID ProcMonitorThread(VOID *);

VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv);
VOID WINAPI ServiceHandler(DWORD fdwControl);


/** Window Service **/
const int nBufferSize = 500;
CHAR pServiceName[nBufferSize+1];
CHAR pExeFile[nBufferSize+1];
CHAR lpCmdLineData[nBufferSize+1];
CHAR pLogFile[nBufferSize+1];
BOOL ProcessStarted = TRUE;

CRITICAL_SECTION myCS;
SERVICE_TABLE_ENTRY lpServiceStartTable[] =
{
{pServiceName, ServiceMain},
{NULL, NULL}
};

LPTSTR ProcessNames[MAX_NUM_OF_PROCESS];

SERVICE_STATUS_HANDLE hServiceStatusHandle;
SERVICE_STATUS ServiceStatus;
PROCESS_INFORMATION pProcInfo[MAX_NUM_OF_PROCESS];

int _tmain(int argc, _TCHAR* argv[])
{
if(argc >= 2)
strcpy(lpCmdLineData, argv[1]);
ServiceMainProc();
return 0;
}

VOID ServiceMainProc()
{
::InitializeCriticalSection(&myCS);
// initialize variables for .exe and .log file names
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(pLogFile,"%s.log",pModuleFile);
}
//name of process
strcpy(pServiceName,"SkyDiver");

if(_stricmp("-i",lpCmdLineData) == 0 || _stricmp("-I",lpCmdLineData) == 0)
Install(pExeFile, pServiceName);
else if(_stricmp("-k",lpCmdLineData) == 0 || _stricmp("-K",lpCmdLineData) == 0)
KillService(pServiceName);
else if(_stricmp("-u",lpCmdLineData) == 0 || _stricmp("-U",lpCmdLineData) == 0)
UnInstall(pServiceName);
else if(_stricmp("-s",lpCmdLineData) == 0 || _stricmp("-S",lpCmdLineData) == 0)
RunService(pServiceName);
else
ExecuteSubProcess();
}

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 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);
}
DeleteFile(pLogFile);
}


VOID WriteLog(char* pFile, char* pMsg)
{
// write error or other information into log file
::EnterCriticalSection(&myCS);
try
{
SYSTEMTIME oT;
::GetLocalTime(&oT);
FILE* pLog = fopen(pFile,"a");
fprintf(pLog,"%02d/%02d/%04d, %02d:%02d:%02d\n %s",oT.wMonth,oT.wDay,oT.wYear,oT.wHour,oT.wMinute,oT.wSecond,pMsg);
fclose(pLog);
} catch(...) {}
::LeaveCriticalSection(&myCS);
}

BOOL KillService(char* pName)
{
// kill service with given name
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
{
// open the service
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
{
// call ControlService to kill the given service
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)
{
// run service with given name
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
{
// open the service
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
{
// call StartService to run the service
if(StartService(schService, 0, (const char**)NULL))
{
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;
}


VOID ExecuteSubProcess()
{
if(_beginthread(ProcMonitorThread, 0, NULL) == -1)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "StartService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
if(!StartServiceCtrlDispatcher(lpServiceStartTable))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "StartServiceCtrlDispatcher failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
:eleteCriticalSection(&myCS);
}

VOID WINAPI ServiceMain(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, ServiceHandler);
if (hServiceStatusHandle==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "RegisterServiceCtrlHandler failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
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);
}
}

VOID WINAPI ServiceHandler(DWORD fdwControl)
{
switch(fdwControl)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
ProcessStarted = FALSE;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
break;
case SERVICE_CONTROL_PAUSE:
ServiceStatus.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_INTERROGATE:
break;

};
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "SetServiceStatus failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
}

VOID ProcMonitorThread(VOID *)
{
while(ProcessStarted == TRUE)
{
//WriteLog(pLogFile, "Write service!!!");

char date [9];
char time [9];
char time_dat [9];
char date_dat [9];
//cout << "System date : " << _strdate(date) <
//cout << "System time : " << _strtime(time) <

using namespace std;
string line;
ifstream myfile ("File.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline (myfile,line);
cout << line << endl;
}

/*do
{
if ( !strcmp(time_dat,time) && !strcmp(date_dat,date) )
//put message!
if(MessageBox(NULL, time, "Message", MB_ICONINFORMATION) ==IDOK)
exit(0);
}
while(time_dat != _strdate(time) && date_dat != _strdate(date));*/

myfile.close();
}

}
}[/code:1]
kako da napravim program koji radi kao servis (NT servis).
program čita txt datoteku, dje je napisano datum,sat i poruka, i na ovaj sat i datum javi poruko

dio programa:

Kod:

#include "process.h"
#include "iostream"
#include "time.h"
#include "fstream"
#include "string"
#include "tchar.h"
#include "stdio.h"
#include "windows.h"
#include "winbase.h"
#include "winsvc.h"

// Service.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#define MAX_NUM_OF_PROCESS 4
/** Window Service **/
VOID ServiceMainProc();
VOID Install(char* pPath, char* pName);
VOID UnInstall(char* pName);
VOID WriteLog(char* pFile, char* pMsg);
BOOL KillService(char* pName);
BOOL RunService(char* pName);
VOID ExecuteSubProcess();
VOID ProcMonitorThread(VOID *);

VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv);
VOID WINAPI ServiceHandler(DWORD fdwControl);


/** Window Service **/
const int nBufferSize = 500;
CHAR pServiceName[nBufferSize+1];
CHAR pExeFile[nBufferSize+1];
CHAR lpCmdLineData[nBufferSize+1];
CHAR pLogFile[nBufferSize+1];
BOOL ProcessStarted = TRUE;

CRITICAL_SECTION myCS;
SERVICE_TABLE_ENTRY lpServiceStartTable[] =
{
{pServiceName, ServiceMain},
{NULL, NULL}
};

LPTSTR ProcessNames[MAX_NUM_OF_PROCESS];

SERVICE_STATUS_HANDLE hServiceStatusHandle;
SERVICE_STATUS ServiceStatus;
PROCESS_INFORMATION pProcInfo[MAX_NUM_OF_PROCESS];

int _tmain(int argc, _TCHAR* argv[])
{
if(argc >= 2)
strcpy(lpCmdLineData, argv[1]);
ServiceMainProc();
return 0;
}

VOID ServiceMainProc()
{
::InitializeCriticalSection(&myCS);
// initialize variables for .exe and .log file names
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(pLogFile,"%s.log",pModuleFile);
}
//name of process
strcpy(pServiceName,"SkyDiver");

if(_stricmp("-i",lpCmdLineData) == 0 || _stricmp("-I",lpCmdLineData) == 0)
Install(pExeFile, pServiceName);
else if(_stricmp("-k",lpCmdLineData) == 0 || _stricmp("-K",lpCmdLineData) == 0)
KillService(pServiceName);
else if(_stricmp("-u",lpCmdLineData) == 0 || _stricmp("-U",lpCmdLineData) == 0)
UnInstall(pServiceName);
else if(_stricmp("-s",lpCmdLineData) == 0 || _stricmp("-S",lpCmdLineData) == 0)
RunService(pServiceName);
else
ExecuteSubProcess();
}

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 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);
}
DeleteFile(pLogFile);
}


VOID WriteLog(char* pFile, char* pMsg)
{
// write error or other information into log file
::EnterCriticalSection(&myCS);
try
{
SYSTEMTIME oT;
::GetLocalTime(&oT);
FILE* pLog = fopen(pFile,"a");
fprintf(pLog,"%02d/%02d/%04d, %02d:%02d:%02d\n %s",oT.wMonth,oT.wDay,oT.wYear,oT.wHour,oT.wMinute,oT.wSecond,pMsg);
fclose(pLog);
} catch(...) {}
::LeaveCriticalSection(&myCS);
}

BOOL KillService(char* pName)
{
// kill service with given name
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
{
// open the service
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
{
// call ControlService to kill the given service
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)
{
// run service with given name
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
{
// open the service
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
{
// call StartService to run the service
if(StartService(schService, 0, (const char**)NULL))
{
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;
}


VOID ExecuteSubProcess()
{
if(_beginthread(ProcMonitorThread, 0, NULL) == -1)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "StartService failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
if(!StartServiceCtrlDispatcher(lpServiceStartTable))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "StartServiceCtrlDispatcher failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
:eleteCriticalSection(&myCS);
}

VOID WINAPI ServiceMain(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, ServiceHandler);
if (hServiceStatusHandle==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "RegisterServiceCtrlHandler failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
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);
}
}

VOID WINAPI ServiceHandler(DWORD fdwControl)
{
switch(fdwControl)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
ProcessStarted = FALSE;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
break;
case SERVICE_CONTROL_PAUSE:
ServiceStatus.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_INTERROGATE:
break;

};
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus))
{
long nError = GetLastError();
char pTemp[121];
sprintf(pTemp, "SetServiceStatus failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
}

VOID ProcMonitorThread(VOID *)
{
while(ProcessStarted == TRUE)
{
//WriteLog(pLogFile, "Write service!!!");

char date [9];
char time [9];
char time_dat [9];
char date_dat [9];
//cout << "System date : " << _strdate(date) <
//cout << "System time : " << _strtime(time) <

using namespace std;
string line;
ifstream myfile ("File.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline (myfile,line);
cout << line << endl;
}

/*do
{
if ( !strcmp(time_dat,time) && !strcmp(date_dat,date) )
//put message!
if(MessageBox(NULL, time, "Message", MB_ICONINFORMATION) ==IDOK)
exit(0);
}
while(time_dat != _strdate(time) && date_dat != _strdate(date));*/

myfile.close();
}

}
}


[Vrh]
Markec
Forumaš(ica)
Forumaš(ica)


Pridružen/a: 20. 02. 2003. (14:49:45)
Postovi: (134)16
Spol: muško
Sarma = la pohva - posuda
-3 = 37 - 40

PostPostano: 18:33 čet, 5. 6. 2008    Naslov: Citirajte i odgovorite

mozda da pitas ponovo covjeka koji ti je taj kod napisao evo [url=http://www.elitesecurity.org/t324483-0]ovdje[/url]
mozda da pitas ponovo covjeka koji ti je taj kod napisao evo ovdje


[Vrh]
Korisnički profil Pošaljite privatnu poruku
vinko
Forumaš(ica)
Forumaš(ica)


Pridružen/a: 26. 08. 2006. (23:08:00)
Postovi: (1A8)16
Spol: muško
Sarma = la pohva - posuda
69 = 87 - 18
Lokacija: PMF-MO 214

PostPostano: 19:12 čet, 5. 6. 2008    Naslov: Re: NT servis u C++ Citirajte i odgovorite

[quote="Anonymous"]kako da napravim program koji radi kao servis (NT servis).
[/quote]Nemam baš volje proučavati ovaj kôd. Lakše je objasniti kako napraviti NT servis, i to bi mi lakše bilo usmeno na primjeru nego ovako.

Pa bivolio da zainteresirani Gost dođe na konzultacije.

A i sam servis zbog servisa i nema baš nekog smisla.
Anonymous (napisa):
kako da napravim program koji radi kao servis (NT servis).
Nemam baš volje proučavati ovaj kôd. Lakše je objasniti kako napraviti NT servis, i to bi mi lakše bilo usmeno na primjeru nego ovako.

Pa bivolio da zainteresirani Gost dođe na konzultacije.

A i sam servis zbog servisa i nema baš nekog smisla.


[Vrh]
Korisnički profil Pošaljite privatnu poruku Posjetite Web stranice
Prethodni postovi:   
Započnite novu temu   Odgovorite na temu   printer-friendly view    Forum@DeGiorgi: Početna -> Kolegiji diplomskih i starih studija -> Objektno programiranje (C++) Vremenska zona: GMT + 01:00.
Stranica 1 / 1.

 
Forum(o)Bir:  
Možete otvarati nove teme.
Možete odgovarati na postove.
Ne možete uređivati Vaše postove.
Ne možete izbrisati Vaše postove.
Ne možete glasovati u anketama.
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2002 phpBB Group
Theme created by Vjacheslav Trushkin
HR (Cro) by Ančica Sečan