Bonjour,

J'ai un petit programme en delphi qui stoppe et relance un service pour faire un traitement. Sous 32 bits pas de problèmes mais par contre impossible de la faire fonctionner sous 64 bits Des idées ?

J'avais trouvé ça sur le net :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function ServiceStart(sMachine, sService: String) : Boolean;
  var
    schm,
    schs: SC_Handle;
    ss: TServiceStatus;
    psTemp: PChar;
    dwChkP: DWord;
  begin
    ss.dwCurrentState := 1; // originally -1, corrected by Henk Mulder
    schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
    if (schm>0) then
    begin
      schs := OpenService(schm, PChar(sService), SERVICE_START or
        SERVICE_QUERY_STATUS);
      if (schs>0) then
      begin
        psTemp := nil;
        if (StartService(schs, 0, psTemp)) then
          if (QueryServiceStatus(schs, ss)) then
            while (SERVICE_RUNNING<>ss.dwCurrentState) do
            begin
              dwChkP := ss.dwCheckPoint;
              Sleep(ss.dwWaitHint);
              if (not QueryServiceStatus(schs, ss)) then
                Break;
              if (ss.dwCheckPoint < dwChkP) then
                Break;
            end;
        CloseServiceHandle(schs);
      end;
      CloseServiceHandle(schm);
    end;
    Result := SERVICE_RUNNING=ss.dwCurrentState;
  end;
 
  function ServiceStop(sMachine, sService: String) : Boolean;
 
  var
    schm,
    schs: SC_Handle;
    ss: TServiceStatus;
    dwChkP: DWord;
  begin
 
    // connection au service
    schm := OpenSCManager(PChar(sMachine), SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
    if (schm>0) then
    begin
      schs := OpenService(schm, PChar(sService), SERVICE_STOP or
        SERVICE_QUERY_STATUS);
      if (schs>0) then
      begin
        if (ControlService(schs, SERVICE_CONTROL_STOP, ss)) then
          if (QueryServiceStatus(schs, ss)) then
            while (SERVICE_STOPPED<>ss.dwCurrentState) do
            begin
              dwChkP := ss.dwCheckPoint;
              Sleep(ss.dwWaitHint);
 
              if (not QueryServiceStatus(schs, ss)) then
                Break;
              if (ss.dwCheckPoint < dwChkP) then
                Break;
            end;
        CloseServiceHandle(schs);
      end;
      CloseServiceHandle(schm);
    end;
    Result := SERVICE_STOPPED=ss.dwCurrentState;
  end;
Merci d'avance !