Solved

Handle of my appilication?

Posted on 2007-04-02
6
174 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

622 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