Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to display Windows On-Screen Keyboard
How to print a bitmap file
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Winsock: sending email messages (SMTP, port 25)
System Image List Viewer
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Custom HttpRequest class (WinHTTP)
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Printing Image File, programmatically set print page orientation to landscape
How to convert a bitmap file to monochrome format (1 bpp)
The window and its ancestors
Mapping and disconnecting network drives
How to download a file from the FTP server using FtpGetFile
Using EnumPrinters function to enumerate locally installed printers
Custom FTP Class for Visual FoxPro application
Displaying the associated icons and descriptions for files and folders
Displaying icons in the system tray (VFP9)
How to activate Windows Calculator
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Drawing Windows predefined bitmaps using the LoadBitmap functions
Sending email messages with Simple MAPI
How to create a service object

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
This code sample shows how to create a record in the Service Control Manager database and link it to the specified executable file.

Properties dialog for the newly created service object opened from Miscrosoft Common Console window:



See also:
  • How to delete a service object
  • Encapsulating access to the Windows Services in a class

  •  
    #DEFINE SC_MANAGER_CREATE_SERVICE 2
    #DEFINE SERVICE_WIN32_OWN_PROCESS 0x00000010
    #DEFINE SERVICE_ALL_ACCESS 0xF01FF
    #DEFINE SERVICE_DEMAND_START 0x00000003
    #DEFINE SERVICE_ERROR_NORMAL 0x00000001
     
    DO declare
     
    LOCAL hManager, hService
     
    hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE)
    IF hManager = 0
        ? "OpenSCManager failed with error", GetLastError()
        RETURN
    ENDIF
     
    LOCAL cServiceName, cDisplayName, nDesiredAccess, nServiceType,;
        nStartType, nErrorControl, cPathToExe
     
    cServiceName="FriendlyService"
    cDisplayName="Friendly Service"
    nDesiredAccess=SERVICE_ALL_ACCESS
    nServiceType=SERVICE_WIN32_OWN_PROCESS
    nStartType=SERVICE_DEMAND_START
    nErrorControl=SERVICE_ERROR_NORMAL
    cPathToExe="C:\friendlyservice\bin\fs.exe"
     
    * note that a new service will be created
    * uncomment the following lines before testing
     
    *!*    hService = CreateService(m.hManager, m.cServiceName, m.cDisplayName,;
    *!*        m.nDesiredAccess, m.nServiceType, m.nStartType, m.nErrorControl,;
    *!*        m.cPathToExe, NULL, 0, NULL, NULL, NULL)
     
    IF hService = 0
    * 1073=ERROR_SERVICE_EXISTS
        ? "CreateService failed with error", GetLastError()
    ELSE
        ? "hService:", hService
        = CloseServiceHandle(m.hService)
    ENDIF
     
    = CloseServiceHandle(m.hManager)
    * end of main
     
    PROCEDURE declare
        DECLARE INTEGER GetLastError IN kernel32
        DECLARE INTEGER CloseServiceHandle IN advapi32 INTEGER hSCObject
     
        DECLARE INTEGER CreateService IN advapi32;
            INTEGER hSCManager, STRING lpServiceName, STRING lpDisplayName,;
            LONG dwDesiredAccess, LONG dwServiceType, LONG dwStartType,;
            LONG dwErrorControl, STRING lpBinaryPathName,;
            STRING lpLoadOrderGroup, LONG lpdwTagId, STRING lpDependencies,;
            STRING lpServiceStartName, STRING lpPassword
     
        DECLARE INTEGER OpenSCManager IN advapi32;
            STRING lpMachineName, STRING lpDatabaseName,;
            LONG dwDesiredAccess
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    1872 bytes  
    Created: 2006-09-21 22:04:27  
    Modified: 2010-10-18 14:40:54  
    Visits in 7 days: 34  
    Listed functions:
    CloseServiceHandle
    CreateService
    GetLastError
    OpenSCManager
    Printer friendly API declarations
    My comment:
    Windows Registry entry for the newly created service:

    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    Matt W | 2006-10-17 11:02:03
    Although this does create an entry in the services database, it should be noted that you cannot run a standard VFP exe as a service. It will attempt to launch for 30 seconds and return a 1053 error - "the service did not respond to the start in a timely fashion."

    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (107.20.7.65)
    4 sec.Example: 'How to display Windows On-Screen Keyboard'
    1.53 min.Function: 'JetBeginSession'
    Function group: 'Extensible Storage Engine (ESE, Jet Blue)'
    6.85 min.Example: 'Finding out if the current user is the Guest account'
    1.41 hrs.Example: 'Exporting DLL icon resources as .ICO files'
     Function: 'GdipResetWorldTransform'
    Function group: 'GDI+ Graphics'
    2.35 hrs.Function: 'mixerGetLineControls'
    Function group: 'Windows Multimedia'
    3.35 hrs.Function: 'SizeofResource'
     Function: 'GlobalFree'
    Function group: 'Memory Management'
    4.93 hrs.Example: 'Listing INF files in a specified directory'
     Function: 'CreatePopupMenu'
    Function group: 'Menu'
    Google
    Advertise here!