Hello Wilfried and Peter,

Long while ago I have read that the official way was as below:

BOOL ReconfigureService(BOOL fDisable, LPSTR lpDesc, const String 
&serviceName) // from
// 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/opening_an_scmanager_database.asp
// and 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/changing_a_service_configuration.asp
{
    SC_LOCK sclLock;
    LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf;
    SERVICE_DESCRIPTION sdBuf;
    DWORD dwBytesNeeded, dwStartType;
    BOOL bSuccess=TRUE;

    SC_HANDLE schSCManager;
    SC_HANDLE schService;

    // Open a handle to the SC Manager database.

    schSCManager = OpenSCManager(
    NULL,                    // local machine
    NULL,                    // ServicesActive database
    SC_MANAGER_ALL_ACCESS);  // full access rights

    if(NULL == schSCManager)
        return false;

    // Need to acquire database lock before reconfiguring.

    sclLock = LockServiceDatabase(schSCManager);

    // If the database cannot be locked, report the details.

    if (sclLock == NULL)
    {
 // Exit if the database is not locked by another process.

        if (GetLastError() != ERROR_SERVICE_DATABASE_LOCKED)
        {
            // printf("LockServiceDatabase failed (%d)\n", GetLastError());
            return FALSE;
        }

        // Allocate a buffer to get details about the lock.

        lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS) LocalAlloc(
            LPTR, sizeof(QUERY_SERVICE_LOCK_STATUS)+256);
        if (lpqslsBuf == NULL)
        {
            // printf("LocalAlloc failed (%d)\n", GetLastError());
            return FALSE;
        }

        // Get and print the lock status information.

        if (!QueryServiceLockStatus(
            schSCManager,
            lpqslsBuf,
            sizeof(QUERY_SERVICE_LOCK_STATUS)+256,
            &dwBytesNeeded) )
        {
     // printf("QueryServiceLockStatus failed (%d)", GetLastError());
            return FALSE;
        }

        //if (lpqslsBuf->fIsLocked)
     // printf("Locked by: %s, duration: %d seconds\n",
            //    lpqslsBuf->lpLockOwner,
            //    lpqslsBuf->dwLockDuration);
        //else
            // printf("No longer locked\n");

        LocalFree(lpqslsBuf);
    }

    // The database is locked, so it is safe to make changes.

    // Open a handle to the service.

    schService = OpenService(
        schSCManager,           // SCManager database
        serviceName.c_str(),             // name of service
        SERVICE_CHANGE_CONFIG); // need CHANGE access
    if (schService == NULL)
    {
        // printf("OpenService failed (%d)\n", GetLastError());
        return FALSE;
    }

    dwStartType = SERVICE_AUTO_START; //(fDisable) ? SERVICE_DISABLED : 
SERVICE_DEMAND_START;

    // Make the changes.

    if (! ChangeServiceConfig(
        schService,        // handle of service
        SERVICE_NO_CHANGE, // service type: no change
        dwStartType,       // change service start type
 SERVICE_NO_CHANGE, // error control: no change
        NULL,              // binary path: no change
        NULL,              // load order group: no change
        NULL,              // tag ID: no change
        NULL,              // dependencies: no change
        NULL,              // account name: no change
        NULL,              // password: no change
        NULL) )            // display name: no change
    {
        // printf("ChangeServiceConfig failed (%d)\n", GetLastError());
        bSuccess = FALSE;
    }
    else
        // printf("ChangeServiceConfig succeeded.\n");

    sdBuf.lpDescription = lpDesc;

    if( !ChangeServiceConfig2(
        schService,                 // handle to service
        SERVICE_CONFIG_DESCRIPTION, // change: description
        &sdBuf) )                   // value: new description
    {
        // printf("ChangeServiceConfig2 failed\n");
        bSuccess = FALSE;
    }
    else
        // printf("ChangeServiceConfig2 succeeded\n");

    // Release the database lock.

    UnlockServiceDatabase(sclLock);

    // Close the handle to the service.

    CloseServiceHandle(schService);
    return bSuccess;
}
//---------------------------------------------------------------------------

Best Regards,

SZ
www.fastream.com

----- Original Message ----- 
From: "Wilfried Mestdagh" <[EMAIL PROTECTED]>
To: "Delphi-Talk Discussion List" <delphi-talk@elists.org>
Sent: Thursday, September 20, 2007 3:45 PM
Subject: Re: //Service description


> Hello Peter,
>
> In the OnAfterInstall event:
>
> var
>   Reg: TRegistry;
> begin
>   Reg := TRegistry.Create;
>   Reg.RootKey := HKEY_LOCAL_MACHINE;
>   if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\' + Name, False) then 
> begin
>      Reg.WriteString('Description', 'This is my nice service');
>      Reg.CloseKey;
>   end;
>   Reg.Free;
> end;
>
> ---
> Rgds, Wilfried
> http://www.mestdagh.biz
>
> __________________________________________________
> Delphi-Talk mailing list -> Delphi-Talk@elists.org
> http://www.elists.org/mailman/listinfo/delphi-talk 

__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to