Solved

executing only 1 application at a time

Posted on 2003-11-13
10
217 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
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!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

685 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