DLLs, Processes, and Threads Changing a Service Configuration In the following example, a service configuration program uses the ChangeServiceConfig and ChangeServiceConfig2 functions to change the configuration parameters of an installed service. The program opens a handle to the service object, modifies its configuration, and then closes the service object handle.#include <windows.h> #include <stdio.h>BOOL ReconfigureSampleService(BOOL fDisable, LPSTR lpDesc) { SERVICE_DESCRIPTION sdBuf; DWORD dwBytesNeeded, dwStartType; BOOL bSuccess=TRUE;
// Open a handle to the service.
schService = OpenService( schSCManager, // SCManager database "Sample_Srv", // name of service SERVICE_CHANGE_CONFIG); // need CHANGE access if (schService == NULL) { printf("OpenService failed (%d)\n", GetLastError()); return FALSE; } dwStartType = (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"); // Close the handle to the service.
DLLs, Processes, and Threads
Changing a Service Configuration
In the following example, a service configuration program uses the ChangeServiceConfig and ChangeServiceConfig2 functions to change the configuration parameters of an installed service. The program opens a handle to the service object, modifies its configuration, and then closes the service object handle.#include <windows.h>
#include <stdio.h>BOOL ReconfigureSampleService(BOOL fDisable, LPSTR lpDesc)
{
SERVICE_DESCRIPTION sdBuf;
DWORD dwBytesNeeded, dwStartType;
BOOL bSuccess=TRUE;
// Open a handle to the service.
schService = OpenService(
schSCManager, // SCManager database
"Sample_Srv", // name of service
SERVICE_CHANGE_CONFIG); // need CHANGE access
if (schService == NULL)
{
printf("OpenService failed (%d)\n", GetLastError());
return FALSE;
} dwStartType = (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"); // Close the handle to the service.
CloseServiceHandle(schService);
return bSuccess;
}
See Also
Service Configuration
© 2005 Microsoft Corporation. All rights reserved.
See Also
Service Configuration
我不需要更改服务配置的方法,不过还是谢谢你