Results 1 to 2 of 2

Thread: Preventing multiple copies of software with VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    1

    Preventing multiple copies of software with VB.NET

    I have an application that is being used on PPC based hand held scanners but the software they use to lock the scanners allows them to move focus from the scanner software to the lockdown program. Because the lockdown software doesn't allow access to menus they return to the scanner software by running the application again.

    Because the original copy has control of the scanner hardware the second copy now doesn't operate correctly.

    I believe that I should be able to use the FindWindow routine in the initial startup code to check whether the software is already running and if it is I should be able to use the SetForegroundWindow routine to surface the original copy then exit the second copy.

    Is this a senisble way of handling this sequence of events? If so how do I do this (code would be good).

    Steve Sharkey

  2. #2
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Preventing multiple copies of software with VB.NET

    Ya it is the right way to do it. When you try to launch the second instance of the applicaiton it will check for a previous existance and if one exists it will bring it to the foreground


    here is the code:
    VB Code:
    1. Declare Function FindWindow Lib "coredll.dll" (ByVal className As Char(), ByVal WindowsName As Char()) As Integer
    2.     Declare Function SetForegroundWindow Lib "coredll.dll" (ByVal hwnd As Integer) As Boolean
    3.  
    4.     Public Shared Sub Main()
    5.         Dim hWnd As Integer
    6.         hWnd = FindWindow(Nothing, "Form1 Caption".ToCharArray)
    7.  
    8.         If hWnd <> 0 Then
    9.             SetForegroundWindow(hWnd)
    10.         Else
    11.             Application.Run(New Form1)
    12.         End If
    13.     End Sub

    Form1 Caption is the text on the top of the form in the title bar



    Rgds
    Barry
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width