Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 12th, 2004, 8:33 AM   #1
lepricaun
Hobbyist Programmer
 
lepricaun's Avatar
 
Join Date: Aug 2004
Location: The Netherlands
Posts: 111
Rep Power: 5 lepricaun is on a distinguished road
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
lepricaun is offline   Reply With Quote
Old Sep 15th, 2004, 11:38 AM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Sep 15th, 2004, 1:51 PM   #3
lepricaun
Hobbyist Programmer
 
lepricaun's Avatar
 
Join Date: Aug 2004
Location: The Netherlands
Posts: 111
Rep Power: 5 lepricaun is on a distinguished road
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
lepricaun is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC