Check if VB Application is running on network

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuragshrivastava64
    New Member
    • Jan 2007
    • 66

    Check if VB Application is running on network

    Hi All,

    I am making a project using VB 6.0.
    How can i stop multiple instances of my program being run in different systems.

    I used App.PrevInst but it works only on the same system.
    On any other system it is not of use
  • CyberSoftHari
    Recognized Expert Contributor
    • Sep 2007
    • 488

    #2
    This will work only in local system. Can you explain why you need to check for multiple systems?
    Note: multiple instances need to check only local system and there is no use of network systems multiple instances. I assume you are looking for forum authentication in network!

    Comment

    • anuragshrivastava64
      New Member
      • Jan 2007
      • 66

      #3
      No actually we are makin an application in two modes Advanced and Standard.
      In advanced version it can be used across network i.e Multi User.

      But in standard version it has to be single user only.

      The exe will be on server only. Other users will log on to server and use that exe

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        better to restrict the number of con-current login to the server.

        Comment

        • CyberSoftHari
          Recognized Expert Contributor
          • Sep 2007
          • 488

          #5
          Originally posted by anuragshrivasta va64
          ...In advanced version it can be used across network i.e Multi User....
          The word itself mean multi user (i.e) alow multiple instances for all user (in other mechines).
          Originally posted by anuragshrivasta va64
          The exe will be on server only. Other users will log on to server and use that exe
          I doubt, is there any other installation on other machines?

          Comment

          • CyberSoftHari
            Recognized Expert Contributor
            • Sep 2007
            • 488

            #6
            Originally posted by debasisdas
            better to restrict the number of con-current login to the server.
            That is good, But outside that application one user can access that server machine!

            Comment

            • jg007
              Contributor
              • Mar 2008
              • 283

              #7
              what about opening a file on a shared network when it is opened and then having you app check to see if that file is locked ( sorry not sure of code for that ) and not allowing another instance if it is

              Comment

              • tristanlbailey
                New Member
                • Apr 2007
                • 30

                #8
                That's a good idea. I've actually been working on the code for that:

                Declarations:
                [CODE="VB"]
                Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
                Public Declare Function CreateFileA Lib "kernel32" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttri butes As Long, ByVal dwCreationDispo sition As Long, ByVal dwFlagsAndAttri butes As Long, ByVal hTemplateFile As Long) As Long
                Public Declare Function DeleteFileA Lib "kernel32" (ByVal lpFileName As String) As Long

                Public Const FILE_ATTRIBUTE_ NORMAL As Long = 128
                Public Const FILE_FLAG_DELET E_ON_CLOSE = &H4000000
                Public Const GENERIC_READ As Long = &H80000000
                Public Const CREATE_NEW As Long = 1

                Public hFile As Long, I As Long
                [/CODE]
                General Code: (Module)
                [CODE="VB"]
                Sub Main()

                hFile = CreateFileA(App .Path & "\" & "MYINST.INI ", GENERIC_READ, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_ NORMAL Or FILE_FLAG_DELET E_ON_CLOSE, 0)
                If hFile <> -1 Then
                Form1.Show
                Else
                End
                End If

                End Sub
                [/CODE]
                General Code: (Form)
                [CODE="VB"]
                Sub Form_Unload()

                CloseHandle hFile

                End Sub
                [/CODE]
                When the program runs the first time, it will create a configuration file in the same directory. The file is created with the FILE_FLAG_DELET E_ON_CLOSE value, which causes the file to be deleted when it is closed.

                If another instance of the same program is created, it will see if that configuration file exists; if it does, it immediately closes. If not, it will re-create the file, and continue to run.

                Comment

                Working...