By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Check if VB Application is running on network

P: 66
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
May 29 '08 #1
Share this Question
Share on Google+
7 Replies


Expert 100+
P: 487
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!
May 29 '08 #2

P: 66
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
May 29 '08 #3

debasisdas
Expert 5K+
P: 8,127
better to restrict the number of con-current login to the server.
May 29 '08 #4

Expert 100+
P: 487
...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).
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?
May 29 '08 #5

Expert 100+
P: 487
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!
May 29 '08 #6

100+
P: 283
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
May 29 '08 #7

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

Declarations:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  2. Public Declare Function CreateFileA Lib "kernel32" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  3. Public Declare Function DeleteFileA Lib "kernel32" (ByVal lpFileName As String) As Long
  4.  
  5. Public Const FILE_ATTRIBUTE_NORMAL As Long = 128
  6. Public Const FILE_FLAG_DELETE_ON_CLOSE = &H4000000
  7. Public Const GENERIC_READ As Long = &H80000000
  8. Public Const CREATE_NEW As Long = 1
  9.  
  10. Public hFile As Long, I As Long
  11.  
General Code: (Module)
Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.  
  3.     hFile = CreateFileA(App.Path & "\" & "MYINST.INI", GENERIC_READ, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_DELETE_ON_CLOSE, 0)
  4.     If hFile <> -1 Then
  5.         Form1.Show
  6.     Else
  7.         End
  8.     End If
  9.  
  10. End Sub
  11.  
General Code: (Form)
Expand|Select|Wrap|Line Numbers
  1. Sub Form_Unload()
  2.  
  3.     CloseHandle hFile
  4.  
  5. End Sub
  6.  
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_DELETE_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.
May 30 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.