Hi,
I used this to bring another application to the Front:
Hope this helps,
Pieter
Public Sub BringExtraToFro nt()
Dim prc As Process
Dim clsProc As New clsProcesses
prc = clsProc.Process Extra 'gets me the
process based on the name
Dim handle As IntPtr = prc.MainWindowH andle
Dim Win32Help As New Win32Helper
If Not IntPtr.Zero.Equ als(handle) Then
Win32Helper.Sho wWindow(handle, 1)
Win32Helper.Set ForegroundWindo w(handle)
End If
End Sub
Option Explicit On
Public Class clsProcesses
Public Shared Function PrevInstance() As Process
Dim c As Process = Process.GetCurr entProcess()
' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProc essesByName(c.P rocessName)
' Aktuellen Prozess nicht beachten.
If p.Id <> c.Id Then
' Es kann mehrere Prozesse gleichen Namens geben, die von
' unterschiedlich en Programmen stammen.
If p.MainModule.Fi leName = c.MainModule.Fi leName Then
' Prozess der ersten gefundenen anderen Instanz
' zurückgeben.
Return p
End If
End If
Next p
' Keine andere Instanz gefunden.
Return Nothing
End Function
Public Shared Function ExtraOpen() As Boolean
' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 4) = SessionName Then
Return True
Exit Function
End If
Next p
Return False
End Function
Public Shared Function ProcessExtra() As Process
' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 4) = SessionName Then
Return p
Exit Function
End If
Next p
Return Nothing
End Function
Public Sub New()
'error-handler die alle errors voor zn rekening neemt
AddHandler System.Windows. Forms.Applicati on.ThreadExcept ion,
AddressOf GlobalErrorHand ler
End Sub
End Class
Public NotInheritable Class Win32Helper
<System.Runtime .InteropService s.DllImport("us er32.dll", _
EntryPoint:="Se tForegroundWind ow", _
CallingConventi on:=Runtime.Int eropServices.Ca llingConvention .StdCall, _
CharSet:=Runtim e.InteropServic es.CharSet.Unic ode, SetLastError:=T rue)> _
Public Shared Function _
SetForegroundWi ndow(ByVal handle As IntPtr) As Boolean
' Leave function empty
End Function
<System.Runtime .InteropService s.DllImport("us er32.dll", _
EntryPoint:="Sh owWindow", _
CallingConventi on:=Runtime.Int eropServices.Ca llingConvention .StdCall, _
CharSet:=Runtim e.InteropServic es.CharSet.Unic ode, SetLastError:=T rue)> _
Public Shared Function ShowWindow(ByVa l handle As IntPtr, _
ByVal nCmd As Int32) As Boolean
' Leave function empty
End Function
End Class ' End Win32Helper
"Ken Wagnitz" <kw******@bigfo ot.com> wrote in message
news:21******** *************** **@posting.goog le.com...
I tried Bob's C# code in his "Only one instance of an application"
article.
It didn't work for me in Windows 2000.
I then tried to email you about it Bob, but you are running FrontPage
extensions on your site, which didn't work for me. Presumably my
company firewall doesn't like them. Why you need FrontPage extensions
to handle a simple form is beyond me.
I am still looking for a solution to this problem. All I have found
on the net so far are solutions which don't work reliably, or guesses
from people (even Microsofties) who haven't tried what they are
suggesting.
Don't know if the barrier is .net, or Win2K/XP. I suspect the latter.
Ken.