Solved

executing only 1 application at a time

Posted on 2003-11-13
10
215 Views
Last Modified: 2010-05-01
Hi,
I'm working with VB6, access97,ado
I  installed the application I wrote,
How can I make sure that a user will not be able to execute more then one
application (same application!) at a time?

Thanx

 
0
Comment
Question by:zolpo
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 24

Assisted Solution

by:R_Rajesh
R_Rajesh earned 150 total points
ID: 9740307
Hi zolpo,

put this at the beginning of your code If App.PrevInstance Then End
Cheers!

Raj
0
 
LVL 1

Author Comment

by:zolpo
ID: 9740372
Hi,
thanx,
How can I check if a different (VB6) application (I wrote)  is running?
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9740438
Private Sub Form_Load()
    MsgBox FindProcess("lsass.exe") ' Your exefile here
End Sub

Function FindProcess(Process) As Boolean
    Set objWMIService = GetObject("winmgmts:")
    Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objProcess In colProcesses
        If LCase(Process) = LCase(objProcess.Caption) Then FindProcess = True
    Next
End Function
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9740452
you should use the  FindWindow api and try and retrive the handle to that window, but this really should be posted as a new question :)
0
 
LVL 1

Author Comment

by:zolpo
ID: 9740810
R_Rajesh You'r right!

I am adding more 150 points (in this question) for that sub question.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:aelatik
ID: 9741130
The function i posted will check if your exe is already running, or another exe. Just try it....
0
 
LVL 14

Accepted Solution

by:
aelatik earned 150 total points
ID: 9741228
Here's the FindWindow method. Replace "Untitled - Notepad" with the title of the app you wan't to search for.
If the messagebox returns 0 it means the window cannot be found. Other than 0 is OK.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Form_Load()
    MsgBox FindWindow(vbNullString, "Untitled - Notepad")
End Sub
0
 
LVL 27

Expert Comment

by:planocz
ID: 9741703
Hi zolpo,
 You can place this code in the load of your program to check for a duplicate instance....

  Dim sTitle                 As String
 
  If App.PrevInstance Then
    sTitle = App.Title
    App.Title = "... duplicate instance."
    Me.Caption = "... duplicate instance."
    AppActivate sTitle
    SendKeys "% R", True
    End
  End If

0
 
LVL 1

Expert Comment

by:RocketMan801
ID: 9752104
hey dude it is much easier than this..  just ah planocz said, u only have to check the app.previnstance value on the load sub of the main form
0
 
LVL 1

Author Comment

by:zolpo
ID: 9758227
Hi,
Thank you all!!!
aelatik,
Thanks a lot, I tried the first function u suggested, but it gave a runtime error, I tried using the FindWindow API and it works !
Thanx again!

R_Rajesh,
Thanx  a lot, for the quick answer to my first problem!

thanx again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

943 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now