Solved

executing only 1 application at a time

Posted on 2003-11-13
10
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

738 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