?
Solved

How to run PB application as a service?

Posted on 2003-02-19
6
Medium Priority
?
404 Views
Last Modified: 2013-12-26
I want to run my PB application as a service (W2K). I am able to register it as a service. When Service Manager starts it, its window appears and the application works for several seconds. But SM issues an error 1053 past timeout, the service didn't respond. I know, the service have to change its status in SM database. Could You help me, what is the shorter way to do it?
0
Comment
Question by:hink
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 2

Expert Comment

by:AFI
ID: 7983487
Hello.  May be is better to ask this question in C++ site...

Do you do this:

//////////////////////////////////////////////////////////////////////
//
// This routine gets used to start your service
//
VOID WINAPI MyServiceMain( 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_PAUSE_CONTINUE;
    serviceStatus.dwWin32ExitCode      = 0;
    serviceStatus.dwServiceSpecificExitCode = 0;
    serviceStatus.dwCheckPoint         = 0;
    serviceStatus.dwWaitHint           = 0;
 
    hServiceStatusHandle = RegisterServiceCtrlHandler(pServiceName, MyServiceHandler);
    if (hServiceStatusHandle==0)
    {
          long nError = GetLastError();
          FILE* pLog = fopen(pLogFile,"a");
        fprintf(pLog, "RegisterServiceCtrlHandler failed, error code = %d\n", nError);
          fclose(pLog);
        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))
    {
.......
...

¿You are using system account?
0
 
LVL 2

Expert Comment

by:AFI
ID: 7983498
See the SERVICE_RUNNING status...
0
 
LVL 3

Author Comment

by:hink
ID: 7985951
To AFI: I have read this text in the MS SDK Help before, but I don't know, how to set MyServiceHandler (pointer to function) in PB. The 200 points are intended for who will be able to advise in PB. I have solved the problem using SRVANY.EXE, it works fine and fills my momentary demand, but I'd like to get it under my own control.

Anyhow Thank You.
0
 
LVL 2

Accepted Solution

by:
AFI earned 800 total points
ID: 7989168
In which I know of PB he does not allow you to use a AddressOf like VB or the example in C. So possibly you cannot have the control in your program at least that you create your own DLL and you send by argument the path of your program, the name of the service, etc ... to be used in the CreateService function...  Sorry but in PB you can't have a function as an argumento of another function
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question