Autor Beitrag
CarpeDiem
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 128

WIN XP
Borland C++ 2002, CodeGear C++ 2007, C# (VS 2008)
BeitragVerfasst: Mi 27.02.08 08:20 
Hallo,

befasse mich hauptsächlich mit Codegear C++ 2007. Ich würde gerne mein kleines Programm nur einmal starten können und beim zweiten Versuch möchte ich nur eine MessageBox ausgeben, daß das Programm schon gestartet ist.

Kann mir jemand sagen, wie ich das Problem lösen kann? Vielleicht durch Abfrage der Prozesse im Task-Manager. Möchte nur nicht eine Datei ablegen, die nach dem Beenden Programmes wieder gelöscht werden muss. Denke mal, daß diese Möglichkeit bei einem Rechner-Absturz mit Problemen behaftet ist.


Vielen Dank gleich mal.


Stefan
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mi 27.02.08 08:53 
(a) die Suche hier benutzen
(b) das Thema gibt es nicht zum erstenmal
(c) Tipp: CreateMutex suchen
(d) siehe hier

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Mi 27.02.08 08:58 
Willkommen hier im Forum! :wink2:

In der Delphi-Library gibt es einen Beitrag der dir helfen könnten:

...verhindern dass die Anwendung mehrmals gestartet wird?

Lg Martin

_________________
Ein Nutzer der Ecke ;-)
CarpeDiem Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 128

WIN XP
Borland C++ 2002, CodeGear C++ 2007, C# (VS 2008)
BeitragVerfasst: Mi 27.02.08 14:03 
Vielen Dank erstmal für die schnelle Hilfe,
habe es jetzt so gelöst (allerding in C++):

Ich habe vor der Programm-Initialisierung ein Handle mit
CreateMutex() erstellt und überprüfe, ob das Programm
schon gestartet ist.
ausblenden volle Höhe 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:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Mutex_Startseite.cpp", Form3);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
 try
  {
.
.
.
  HANDLE mHandle;
  mHandle=CreateMutex(NULL,true,"Mutex");
  if (mHandle!=NULL)
    {
    if (GetLastError()==ERROR_ALREADY_EXISTS)
      {
      ShowMessage("Programm ist bereits geöffnet");
CloseHandle(mHandle); 
      return 0;
      }
    }
    Application->Initialize();
    SetApplicationMainFormOnTaskBar(Application, true);
    Application->CreateForm(__classid(TForm3), &Form3);
    Application->Run();
  }
.
.
.

}
//---------------------------------------------------------------------------

Dabei das
CloseHandle(mHandle);
am Programmende nicht vergessen.

Moderiert von user profile iconTino: Code-Tags hinzugefügt.
Silas
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mi 27.02.08 15:46 
Ich würde als Mutex-Name unbedingt den Programmnamen, eine GUID oder irgendetwas anderes eindeutiges verwenden. Sonst kann es sein, dass ein anderes Programm einen Mutex mit dem selben Namen erstellt und sich dann dein Programm nicht mehr starten lässt.

_________________
Religionskriege sind nur Streitigkeiten darüber, wer den cooleren imaginären Freund hat ;-)
CarpeDiem Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 128

WIN XP
Borland C++ 2002, CodeGear C++ 2007, C# (VS 2008)
BeitragVerfasst: Mi 27.02.08 15:55 
Danke, gute Idee.
Will mein Programm sowieso noch über die GUID und einige anderen Daten
verschlüsseln. Könnte man damit vielleicht gleich verbinden.