1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
void __fastcall TForm10::ProcessServices(char* szDisplayServiceName)
{
SERVICE_STATUS OpenServStatus;
SC_HANDLE schandle=NULL, Fservice=NULL;
bool resu=false;
const MaxLen=255;
char szDisplayName[MaxLen];
char szServiceName[MaxLen];
strcpy(szDisplayName,szDisplayServiceName);
DWORD cchBuffer=MaxLen;
// Arrête le service "Mises à jour automatiques"
schandle=OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(schandle)
{
resu=GetServiceKeyName(schandle,
szDisplayName,
szServiceName,
&cchBuffer);
if(resu)
{
Fservice=OpenService(schandle,
szServiceName,
SERVICE_QUERY_STATUS|SERVICE_START|SERVICE_STOP);
if (Fservice)
{
ControlService(Fservice, SERVICE_CONTROL_STOP, &OpenServStatus);
// Exécute le MSI
// ShellExecute(Application->Handle, "open", "msiexec.exe", parametres, NULL, SW_SHOWDEFAULT);
// Démarre le service "Mises à jour automatiques"
if(!StartService(Fservice,NULL,NULL))
{
CloseServiceHandle(Fservice);
CloseServiceHandle(schandle);
RaiseLastOSError();
}
else
CloseServiceHandle(Fservice);
}
else
{
CloseServiceHandle(schandle);
RaiseLastOSError();
}
}
CloseServiceHandle(schandle);
}
} |
Partager