![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Aug 2004
Location: The Netherlands
Posts: 111
Rep Power: 5
![]() |
hi,
i was searching through the net on how-to create a service in windows. well i have found several links, on of them is from msdn here and although i find it very usefull, i can't get it to work ..here's what i have so far: #include <windows.h>
#include <stdio.h>
#include <Winsvc.h>
SC_HANDLE schSCManager,schService;
int main(void)
{
BOOL CreateSampleService()
{
TCHAR szPath[MAX_PATH];
if( !GetModuleFileName( NULL, szPath, MAX_PATH ) )
{
printf("GetModuleFileName failed (%d)\n", GetLastError());
return FALSE;
}
schSCManager = OpenSCManager(
NULL, // local machine
NULL, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights
if (NULL == schSCManager)
{
printf("OpenSCManager failed (%d)\n", GetLastError());
return 1;
}
schService = CreateService(
schSCManager, // SCManager database
TEXT("Sample_Srv"), // name of service
"lpszDisplayName", // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type
"c:\\test.exe", // path to service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
NULL, // LocalSystem account
NULL); // no password
if (schService == NULL)
{
printf("CreateService failed (%d)\n", GetLastError());
return FALSE;
}
else
{
printf("service created...");
CloseServiceHandle(schService);
return TRUE;
}
}
}i kinda copied and paste from the msdn site, and altered it a little to get it to run, but somehow the above code still won't create a service ... can someone please tell me what i have done wrong, cause this is really bothering me ![]()
__________________
http://www.white-scorpion.nl |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Check the windows event/error log (in your administrative tools) this will likely detail exactly why the error is occuring.
Aside from that though everything does seem to look fine. Perhasps tomorrow when I get back home I will pull out my services code and post it here for you.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Aug 2004
Location: The Netherlands
Posts: 111
Rep Power: 5
![]() |
well, i can't find anything useful in the logs
, it would be great if you would post your code though ![]()
__________________
http://www.white-scorpion.nl |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|