|
| Autor |
Nachricht |
GGX_ Newbie

Anmeldedatum: 12.06.2007 Beiträge: 10
|
Durch die neue Instance, die Alte beenden.
Verfasst am: 22.02.2008, 13:00 |
|
|
Hi Leute,
Ich überprüfe mit "App.PrevInstance" in VB6 das gestartet Programm nicht doppelt geöffnet ist. Nun möchte ich aber die laufene Version beenden und die neu gestartete Version weiterlaufen lassen. Könnt ihr mit dabei bitte weiterhelfen?
Besten Dank im Vorraus
MfG GGX |
|
| |
|
 |
Hamtaro_ « Moderator »

Anmeldedatum: 06.05.2007 Beiträge: 217 Wohnort: NRW
|
Verfasst am: 22.02.2008, 14:12 |
|
|
Hmm, falls Previnstance keine PID oder sowas zurückgibt musst du das wohl manuell machen.
Liste aller Prozesse machen mit CreateToolHelp32Snapshot: http://www.activevb.de/tipps/vb6tipps/tipp0273.html
Dann die PID aller gleichnamigen Prozesse mit der deiner vergleichen.
Und alle gleichnamigen Prozesse die nicht gleich GetCurrentProcessId() sind halt killen: Mit OpenProcess() rechte Holen und dann mit TerminateProcess killen. http://www.vbarchiv.net/faq/allg_exitprocess.php
Wie findet ihr meine Sig? |
|
| |
|
 |
GGX_ Newbie

Anmeldedatum: 12.06.2007 Beiträge: 10
|
Verfasst am: 22.02.2008, 20:48 |
|
|
ich hab es jetzt einfach schnell so gemacht:
| Code: | Private Declare Function GetForegroundWindow Lib "user32" () As Integer
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) _
As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd _
As Long, ByVal wCmd As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const WM_CLOSE = &H10
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Dim hwnd2&, result&, title$, var1&
hwnd2 = GetForegroundWindow
var1 = 0
Do
result = GetWindowTextLength(hwnd2) + 1
title = Space$(result)
result = GetWindowText(hwnd2, title, result)
title = Left$(title, Len(title) - 1)
If title = "update2" And var1 = 0 Then
If Not hwnd2 = Me.hwnd Then
'MsgBox title & " # " & hwnd2 & " # " & Me.hwnd
SendMessage hwnd2, WM_CLOSE, ByVal 0&, ByVal 0&
var1 = 1
End If
End If
DoEvents
hwnd2 = GetWindow(hwnd2, GW_HWNDNEXT)
If var1 = 1 Then
hwnd2 = GetForegroundWindow
End If
Loop Until hwnd2 = 0
Text1.Text = GetForegroundWindow
Text2.Text = Me.hwnd
Text3.Text = App.PrevInstance
End Sub |
könnte das bitte jemand prüfen ob es nicht schneller geht? Please
MfG GGX |
|
| |
|
 |
|
|