Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Handle of my appilication?

Posted on 2007-04-02
6
Medium Priority
?
175 Views
Last Modified: 2010-04-23
Hello

I want to search for mutliple instances of my application.
So I am searching through all processes and if the exename is the same as my app-exename, I add currentinstances +1
if currentinstances > 1 then I want to kill all old instances

so I loop again through all processes and then if the exename is the same as my app exe-name, I want to compare the handles, to check if this instance is the actual running instance.

So I tried:

                        Dim prochandle As String = oprocess.Handle.ToString
                        Dim myhandle As String = Me.Handle.ToString
                        If prochandle <> myhandle Then
                            oprocess.Kill()
                        End If

But this did not work, Me.Handle seems to be different from the Process.Handle of my application...

What is wrong?

Thanks

Sven
0
Comment
Question by:Ruttensoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:MasterThai
ID: 18836552
This should be of some help.
http://www.developerfusion.co.uk/show/134/
0
 
LVL 21

Expert Comment

by:K V
ID: 18836695
this will return you the handle

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
returns long handle >> FindWindow(, "WINDOW TITLE")
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 18836962
"So I am searching through all processes and if the exename is the same as my app-exename"

You are doing more work than you need too...

Use Process.GetProcessesByName():
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassgetprocessesbynametopic1.asp

Something like...

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim appName = System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath)
        Dim ps() As Process = Process.GetProcessesByName(appName)        
        While ps.Length > 1
            ps(0).Kill() ' or ps(0).CloseMainWindow()
            ps = Process.GetProcessesByName(appName)        
        Wend
    End Sub

End Class

You sure you want to kill OLD instances?

What version VB.Net are you working in?

Do you need to pass info to the old and/or new instances?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question