Visual Basic Online Course - Prevent VB6 Application from run twice

Visual Basic Online Course

Limit your application to one single instance

Limit Your Application
Visual Basic Online Course - Limit Your Application
- Some applications are free trials and they're controlled using code. If you want to limit your application abilities on the client machine, then you will find those ideas great, regardless the Visual Basic Version I'm using VB6, you can still use them in .Net too.

1) Limit your VB6 Application to a certain number of times to run on the client's machine, seems sometimes to do the trick but it also can be modified easily, means your limitations can be broken easily if your client have some knowledge about programming or asked for help from a programmer. But as long as the idea is kept hidden and unknown inside the Source Code, then it would be hard to be discovered anyway. You can also limit your VB6 application setting a start Date and End Date instead of the values given in the source code below.
'Visual Basic Online Course
'Prevent application from Running twice at the same time
'http://vb6access2003.blogspot.com
Option Explicit
Dim Retvalue, GD As String
Dim Reset As Integer
Private Sub Command1_Click()
DeleteSetting "A", "0", "RunCount"
GD = 0
End Sub
Private Sub Form_Load()
Retvalue = GetSetting("A", "0", "Runcount")
GD = Val(Retvalue) + 1
SaveSetting "A", "0", "RunCount", GD
If GD > 3 Then 'You exceeded the 3 times trials
Reset = _
MsgBox("This application needs to be activated, contact your vendor", _
vbYesNoCancel, _
"Limited")
If Reset = vbYes Then
End
ElseIf Reset = vbNo Then
Call Command1_Click
Else
Unload Me
End If
End If
Label1.Caption = ("You have " & 3 - GD & " Trials left.")
End Sub
view raw gistfile1.vb hosted with ❤ by GitHub

2) Limit your VB6 application running once only. Some application can not run more than one interface specially those which connects to a Database because you don't want to duplicate connection to an already opened Database or Tables. You will need to limit your application to only run single instance or prevent your VB6 Application from running more than once.
You will need to do those steps though,
- Add Module Module1.bas, copy the following code into it.
- Then, from Menu Project, Project Properties, Start Up Object, choose Sub Main
'Visual Basic Online Course
'Prevent your application from running twice VB6
'http://vb6accesss2003.blogspot.com
'Add Module
'then, from Project => Properties =>
'Start up Object: => Sub Main
Private Sub main()
'Check for previous instance and exit if found.
Dim rc As Long
If App.PrevInstance Then
rc = MsgBox("Application is already running", _
vbCritical, _
App.Title)
Exit Sub
Else
Form1.Show
End If
End Sub
view raw gistfile1.vb hosted with ❤ by GitHub

You can also use the 1st example to prevent your application from running twice at the same time, but the second example is much more secure then the 1st one.

VB6 Popular Posts

Visual Basic Online Course - Function Keys (F1 to F12)

VB 0.6 Copy, Paste, Cut and Create Folders

Visual Basic Online Course - Run-time error '3021' : Either BOF or EOF is True, or the current record has been deleted.