Bonjour,
j'aimerai savoir comment lancer, mais surtout arreter (oui, parce que pour lancer, il suffit de faire un ShellExecute) une application service.
Ce serai pour gerer mes serveurs Apache, MySQL et SMTP
Bonjour,
j'aimerai savoir comment lancer, mais surtout arreter (oui, parce que pour lancer, il suffit de faire un ShellExecute) une application service.
Ce serai pour gerer mes serveurs Apache, MySQL et SMTP
Salut,
Je ne sais pas si �a r�pond � la question, mais tu peux aller voir ici :
http://www.developpez.net/forums/vie...hlight=#229238
Selon ce que tu veux faire, le Timer peut �tre utile ou non ...
En esp�rant avoir pu t'aider![]()
Bonne Continuation
Mathieu
peut etre que je me trompe, mais aucune fenetre n'est ouverte pour une application service, donc je ne pourrait pas trouver le Handle de la fenetre avec :
comme dans ton code :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2 HWND HandleF = FindWindow("About", "#32770");
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5 HWND HandleF = FindWindow("About", "#32770"); if (HandleF) { PostMessage(HandleF, WM_CLOSE, NULL, NULL); Timer1->Enabled = false; }
Salut,
C'est peut-�tre moi qui me trompe sur la d�finition d'Application Service ...![]()
Si aucune fen�tre n'est r�ellement cr��e, je ne sais pas si FindWindow permet aussi d'acc�der aux processus en cours ...
Essaye quand m�me;
Si cela ne marche pas, je te poste ce soir une proc�dure de CALLBACK qui pemet d'�num�rer toutes les fen�tres actives, ainsi que les processus.
Bonne Chance
Mathieu
Finalement, j'ai retrouv� �a![]()
Unit1.h
Unit1.cpp
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11 bool CALLBACK EnumWindowsProc(HWND hWnd, TListView *ListView); class TForm1 : public TForm { __published: TListView *ListView1; TButton *Button1; void __fastcall Button1Click(TObject *Sender); private: public: __fastcall TForm1(TComponent* Owner); };
Ensuite, tu reconnais ton processus ... et le tour est jou�
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 void __fastcall TForm1::Button1Click(TObject *Sender) { ListView1->Items->Clear(); EnumChildWindows(GetDesktopWindow(),(WNDENUMPROC)EnumWindowsProc,(LPARAM)ListView1); EnumWindows((WNDENUMPROC)EnumWindowsProc,(LPARAM)ListView1); EnumDesktopWindows(NULL,(WNDENUMPROC)EnumWindowsProc,(LPARAM)ListView1); } bool CALLBACK EnumWindowsProc(HWND hWnd, TListView *ListView) { char WindowName[80], ClassName[80]; GetWindowText(hWnd, WindowName, 80); GetClassName(hWnd, ClassName, 80); ListView->Items->Add(); int i=ListView->Items->Count-1; ListView->Items->Item[i]->Caption=AnsiString(WindowName); ListView->Items->Item[i]->SubItems->Add(AnsiString(ClassName)); ListView->Items->Item[i]->Update(); return true; }![]()
Je pense que �a devrait convenir![]()
Bonne Continuation
Mathieu
Moi j'ai trouv� �a, je pense que ca correspond mieux, mais j'arrive pas � me servir de la structure SERVICE_STATUS du ServiceControl. J'ai trouv� ces infos dans l'aide du Windows SDK, � Service Functions :
voila ce que j'ai fais :Button1 pour D�marrer, et ca marche !
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 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "monitor.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; SC_HANDLE schandle, startApache, stopApache; SERVICE_STATUS *service_status; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { schandle=OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { startApache=OpenService(schandle, "Apache", SERVICE_START ); StartService(startApache, NULL, NULL); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { stopApache=OpenService(schandle, "Apache", SERVICE_STOP); ControlService(stopApache, SERVICE_CONTROL_STOP, service_status); }
Button2 pour arreter, mais ca marche pas!
tu a oubli� un l�ger d�tail,
tu dois ouvrir le service avec la possibilit� de D�marrer,Arr�ter, interroger l'�tat du Service
utilise le code suivant
Avec mes Salutations
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 SERVICE_STATUS OpenServStatus; SC_HANDLE schandle; Fservice; schandle=OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); Fservice=OpenService(schandle, "Apache", SERVICE_QUERY_STATUS|SERVICE_START|SERVICE_STOP); // maintenant pour démarre le Service StartService(Fservice,NULL,NULL); // pour le Stopper ControlService(FWatchService, SERVICE_CONTROL_STOP, &OpenServStatus);
![]()
![]()
vous trouverez mes tutoriels � l'adresse suivante: http://djmsoftware.developpez.com/
je vous en souhaite une excellente lecture ...
A lire : Les r�gles du forum
Partager