Autor Beitrag
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Sa 06.11.04 14:09 
Hallo,
wie kann ich mit Delphi den Dienst "Konfigurationsfreie drahtlose Verbindung" neustarten. Das fertige Programm wird Adminrechte haben.

Danke,
maxk

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
greg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119

Windows2000, WindowsXP
D5 Prof
BeitragVerfasst: Sa 06.11.04 14:23 
Hallo Maxk,

per Kommandozeile bzw. in der Eingabeaufforderung startest Du einen Dienst mit Net Start Dienstname und stoppst ihn mit Net Stop Dienstname, wobei Dienstname der Name der ausführbaren Datei ist.
Was ich jetzt wiederum nicht weiss, ist wie man eine solche Eingabe von einem Delphi Programm aus an Windows übergibt, aber ich würde in der Hilfe von der ShellApi suchen.
Wenn Du eine Lösung hast, poste die doch bitte mal. Das Thema interessiert mich auch.

Gruß
Gregor
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 06.11.04 14:47 
So geht es: Erst mal unter Suche im MSDN OPENSERVICE kucken und dor findet man auch ein Beispiel: msdn.microsoft.com/l...arting_a_service.asp und wie man da vorgeht.
maxk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Sa 20.11.04 19:39 
So, nach viel Arbeit habe ich endlich wieder Zeit gefunden. Hier meine Lösung:
ausblenden volle Höhe Delphi-Quelltext
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:
uses JwaWinSvc;

function ControlService(const ServiceName:PChar;const Start:boolean):boolean;
var schService,schSCManager:SC_Handle;
    sspStatus:_SERVICE_STATUS_PROCESS;
    ssStatus:_SERVICE_STATUS;
    dwOldCheckPoint,dwStartTickCount,dwWaitTime,dwBytesNeeded:DWord;
begin
 Result:=False;
 schSCManager:=OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);
 if schSCManager<>0 then try
  schService:=OpenService(schSCManager,ServiceName,SERVICE_ALL_ACCESS);
  if schService=0 then Exit;

  case Start of
   True:  if not StartService(schService,0,nil) then Exit;
   False: if not jWaWinSvc.ControlService(schService,SERVICE_CONTROL_STOP,
           ssStatus) then Exit;
  end;

  if not QueryServiceStatusEx(schService,SC_STATUS_PROCESS_INFO,@sspStatus,
   SizeOf(sspStatus),dwBytesNeeded ) then Exit;

  dwStartTickCount:=GetTickCount;
  dwOldCheckPoint:=sspStatus.dwCheckPoint;
  while (sspStatus.dwCurrentState=SERVICE_START_PENDING)
     or (sspStatus.dwCurrentState=SERVICE_STOP_PENDING) do begin
   dwWaitTime:=sspStatus.dwWaitHint div 10;
   if dwWaitTime<1000 then dwWaitTime:=1000
    else if dwWaitTime>10000 then dwWaitTime:=10000;

   Sleep (dwWaitTime);
   if not QueryServiceStatusEx(schService,SC_STATUS_PROCESS_INFO,@sspStatus,
    SizeOf(sspStatus),dwBytesNeeded) then Exit;

   if sspStatus.dwCheckPoint>dwOldCheckPoint then begin
    dwStartTickCount:=GetTickCount;
    dwOldCheckPoint:=sspStatus.dwCheckPoint;
   end else begin
    if GetTickCount-dwStartTickCount > sspStatus.dwWaitHint then Break;
   end;
  end;

  CloseServiceHandle(schService);
  if sspStatus.dwCurrentState = SERVICE_RUNNING then Result:=True;

 finally
  CloseServiceHandle(schSCManager);
 end;
end;

function RestartService(const ServiceName:PChar):boolean;
begin
 Result:=ControlService(ServiceName,False) and ControlService(ServiceName,True);
end;

Das Neustarten des oben genannten Service könnte dann durch RestartService('WZCSVC'); erfolgen. XP Anwender können auch mal als ServiceName Themes verwenden ;)

Danke!

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.