Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to run PB application as a service?

Posted on 2003-02-19
6
Medium Priority
?
412 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
  • 3
4 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

564 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