Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
GDI+: converting text strings to images and saving in a graphics file
How to retrieve list of system DSNs (Data Source Name) with parameters
Pocket PC: enumerating mounted database volumes and databases in the Object Store
Using LoadLibrary
Pocket PC: creating backup for the System Registry
Retrieving the System Time adjustment
Saying "Hello World!" with VFP and WinAPI
Dynamic strings implemented through VFP Custom class
Power capabilities of the system: battery, UPS, sleep and hibernation modes, processor throttling
Retrieving geometrical parameters of the system desktop window
Finding the application, icon and friendly names associated with a file name
List of ODBC drivers installed (read from the [ODBC Drivers] section)
Setting the Window Region for a form
Terminating VFP application using the FatalAppExit
How to retrieve information about a cache entry (Internet Explorer)
Managing Cookies
Displaying all TCP connections for the local system
How to create a service object
Obtaining window class name for the main VFP window
Open and close a Simple MAPI Session
Retrieving a handle to DLL and address of an exported function in it
Creating two-byte hashes for a list of URLs
GetFileOwner - Get the owner of an NTFS file
Retrieving list of supported paper names (for example, Letter or Legal) for a given printer
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 (54.242.233.11)
    2.12 hrs.Example: 'Basic Volume information'
     Example: 'Extensible Storage Engine class library'
    2.46 hrs.Example: 'Storing screen shot of a form to bitmap file'
    4.73 hrs.Function: 'PathCombine'
    5.41 hrs.Example: 'How to create MD-5 and SHA-1 hash values from a string'
    Language: 'Visual FoxPro'
     Function: 'waveInStart'
    Function group: 'Windows Multimedia'
    6.07 hrs.Function: 'CertCloseStore'
     Function: 'CeGetTempPath'
    7.73 hrs.Function: 'HeapReAlloc'
    Function group: 'Memory Management'
     Function: 'CopyIcon'
    Function group: 'Icon'
    Google
    Advertise here!