Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can you teach me how to create an NT service?
Message
From
15/11/2001 13:21:23
 
 
To
15/11/2001 12:47:15
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00582226
Message ID:
00582253
Views:
35
This message has been marked as a message which has helped to the initial question of the thread.
Luis,

>Sorry for disturbing you but, can you be so kind as to teach how to create an NT service?
>
>TIA
>
>Luis

No problem! I am sorry for not getting back to you sooner. I have been very busy.

Essentially you need to create a normal FoxPro program that has the following behaviors:

1) It must not attempt to write anything to the screen.
2) It must either use a Timer event or the Windows Sleep function in a loop. I have chosen the second method.
3) Give yourself an easy way of stopping the service manually - My code shows a crude but effective method for this. Remember that you can manage Services through the Service panel.
4) Read up on SRVANY.EXE - Here's a link to one of Microaoft's support articles: http://support.microsoft.com/support/kb/articles/q137/8/90.asp

Here is the main program I am currently working on. The comments should help explain what I am doing. My service is VERY simple. Every few seconds look on our Transaction Server for some files. If they exist get them using Web Connection's (www.west-wind.com) pre-built functions. (They have saved me a LOT of work!)

If I've missed anything someone will jump in and help - or if you have any more questions, please ask!

Also, I have not included any support functions that you will see referenced. You'll have to write your own.
*
** MtgSvrMain
*
** Main or 'start' program for Mortgage Server Service
*
SET TALK OFF
SET NOTIFY OFF
SET EXCLUSIVE OFF

SET PROCEDURE TO wwapi.prg, wwutils.prg ADDITIVE

LOCAL lnMilliseconds, lnSleepSeconds, lnNtService, loIP

IF FILE("seconds.txt")
   lnSleepSeconds = FILETOSTR("seconds.txt")
ENDIF

IF ISDIGIT(lnSleepSeconds)
   lnSleepSeconds = INT(VAL(lnSleepSeconds))
ELSE
   STORE 15 TO lnSleepSeconds
ENDIF

STORE lnSleepSeconds * 1000 TO lnMilliseconds

*
** Service Support
*
STORE 0 TO lnNtService		&& 1 = Disables Service Mode, 0 enables it
=SYS(2340,lnNtService)		&& VFP 7.0 function - You will need VFP 7.0 for this!

SET CLASSLIB TO wwipstuff	&& Web Connection Internet Library.
*
** Create wwIpStuff Object
*
loIP = CREATEOBJECT("wwIpStuff")

=WriteLog(PROGRAM(),"Starting Up")

IF VARTYPE(loIP) == "O"
   *
   ** Set up Sleep Mode
   *
   DECLARE Sleep IN WIN32API INTEGER lnMilliseconds	&& Make Windows API Sleep function available.

   CLEAR TYPEAHEAD
   IF LocalFileCheck()					&& Checks for and creates any necessary tables.
      IF TokenPass()						&& Process to actually exchange data with Transaction Server.
                                    && Validates if TS is 'live'.
         DO WHILE .T.
            ServerReceive(loIP)		&& Receive loacally any Transaction Server-based data.
            ServerSend(loIP)			&& Send any local data to Transaction Server.

            =Sleep(lnMilliseconds)	&& Pause for 'n' seconds.

            IF FILE("stop.txt") OR CHRSAW()	&& Back door way to stop service.
               EXIT
            ENDIF
         ENDDO
      ELSE
         =WriteLog(PROGRAM(),"Token Pass Failed")
      ENDIF
   ENDIF
ENDIF

=WriteLog(PROGRAM(),"Shutting Down")
Best,


DD

A man is no fool who gives up that which he cannot keep for that which he cannot lose.
Everything I don't understand must be easy!
The difficulty of any task is measured by the capacity of the agent performing the work.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform