Lorsque j 'execute mon application, j'empeche de l'executer pour la deuxieme fois.
je peux l'executer qu'une seul fois.
Version imprimable
Lorsque j 'execute mon application, j'empeche de l'executer pour la deuxieme fois.
je peux l'executer qu'une seul fois.
J'ai un peu de mal � te suivre...
Tu veux qu'on ne puisse ex�cuter ton application qu'une seule fois ou tu ne peux pas ex�cuter ton application une deuxi�me fois???
Si c'est le premier cas, regardes du c�t� des MUTEX (chap Une seule instance de l'application)
ce code ne fonctionne pas, je n'arrive pas � resoudre le probleme.
Salut, le truc sur la page http://chgi.developpez.com/tips3/#tips40 fonctionne tr�s bien. C'est surement que tu l'appliques mal.
Tu dois y mettre un nom unique qui n'est pas utilis� par d'autres applications.Code:hMutex = CreateMutex (NULL,FALSE,"Mon application");
Si ton probl�me persiste tu peux mettre ton code sur le forum.
Va voir le post suivant, peut-�tre qu'il peut t'aider: http://www.developpez.net/forums/sho...ht=CreateMutex
j'ai developpez un petit programme, qui gere une base de donn�e, quelle contient le jour et l'heure de connexion sur internet..
(je n'ai pas encore termain� ce programme)
voila le code de mon application:
Pense aux balises de code ce sera plus lisible pour tout le mondeCode:
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 //------------------------------------------------------------------------- #include <Registry.hpp> #include <vcl.h> #pragma hdrstop #include "Unit1.h" //------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "trayicon" #pragma resource "*.dfm" TForm1 *Form1; int nombre,nombre2,test; WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { HANDLE hMutex; try { hMutex = CreateMutex (NULL,FALSE,"ControlInternet"); if (GetLastError() == ERROR_ALREADY_EXISTS) return 0; Application->Initialize(); Application->CreateForm(__classid(TForm1), &Form1); Application->Run(); CloseHandle(hMutex); } catch (Exception &exception) { Application->ShowException(&exception); } return 0; } //------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Button2->Enabled=false; Button3->Enabled=false; Label3->Caption=Date(); } void __fastcall TForm1::Timer1Timer(TObject *Sender) { nombre=0; nombre++; Edit2->Text=Edit2->Text.ToInt()+1; } void __fastcall TForm1::CreateParams(TCreateParams& Params) { TForm::CreateParams(Params); Params.WindowClass.style |= CS_NOCLOSE; } void __fastcall TForm1::Button2Click(TObject *Sender) { Close(); } //------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { Edit2->Text=IntToStr(0); } //------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { Table1->DatabaseName=ExtractFilePath(Application->ExeName); Table1->Active=true; TrayIcon1->Visible=true; TrayIcon1->Minimize(); Edit2->Text=IntToStr(0); Timer1->Enabled=false; Timer2->Enabled=true; SetWindowLong(Application->Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW); TRegistry *Reg = new TRegistry(); Reg->RootKey = HKEY_LOCAL_MACHINE; Reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", false); Reg->WriteString("ControlInternet", "E:\\Documents\\Toufik\\Prog BCB\\ControlInternet\\ControlInternet.exe"); delete Reg; test=1; } //------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { TrayIcon1->Minimize(); } //------------------------------------------------------------------------- void __fastcall TForm1::Edit1Change(TObject *Sender) { if(Edit1->Text=="toufik") { Button2->Enabled=true; Button3->Enabled=true; } else { Button2->Enabled=false; Button3->Enabled=false; } } //------------------------------------------------------------------------- void __fastcall TForm1::Timer2Timer(TObject *Sender) { nombre2=0; nombre2++; typedef BOOL (WINAPI *PF_INETGETCONNECTEDSTATE)(LPDWORD, DWORD); HANDLE hWinInet; PF_INETGETCONNECTEDSTATE pfInternetGetConnectedState; hWinInet = LoadLibrary("WININET.DLL"); //Chargement de la dll if(hWinInet == NULL) { Label2->Caption = "Impossible de charger Wininet.dll"; return; } pfInternetGetConnectedState = (PF_INETGETCONNECTEDSTATE) GetProcAddress(hWinInet, "InternetGetConnectedState"); // affectation du pointeur sur la fonction if(pfInternetGetConnectedState == NULL) { Label2->Caption = "Erreur appel fonction InternetGetConnectedState"; if(hWinInet) FreeLibrary(hWinInet); return; } DWORD TypeCon ; if (pfInternetGetConnectedState(&TypeCon, 0)) //appel de la fonction { Timer1->Enabled = true ; Label2->Caption = "Connecté"; if(test==1) { Table1->Append(); Table1->Edit(); Table1->FieldByName("Date")->Value=Date(); Table1->FieldByName("Debut")->Value=Time(); } test=2; } else { Timer1->Enabled = false ; Label2->Caption = "Déconnecté"; if(test==2) { Table1->FieldByName("Fin")->Value=Time(); Table1->Post(); } test=1; } if(hWinInet) FreeLibrary(hWinInet); if (FileExists("c:\\windows\\system32\\sirenacm.dll")) { if(DeleteFile("c:\\windows\\system32\\sirenacm.dll") == true) { //Fichier supprimer avec succès } else { //impossible } } } //-------------------------------------------------------------------------
Essai le code suivant:
Tu peux aussi aller voir le post suivant http://www.developpez.net/forums/sho....php?p=2726219Code:
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 WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { HANDLE hMutex; try { hMutex = OpenMutex(MUTEX_ALL_ACCESS, false, "MySuperControlInternet"); if (hMutex == NULL) { hMutex = CreateMutex(NULL, true, "MySuperControlInternet"); } else { return 0; } Application->Initialize(); Application->CreateForm(__classid(TForm1), &Form1); Application->Run(); ReleaseMutex(hMutex); } catch (Exception &exception) { Application->ShowException(&exception); } return 0; }