Solved

executing only 1 application at a time

Posted on 2003-11-13
10
216 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…

829 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