Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

executing only 1 application at a time

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
zolpo
Asked:
zolpo
  • 3
  • 3
  • 2
  • +2
2 Solutions
 
R_RajeshCommented:
Hi zolpo,

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

Raj
0
 
zolpoAuthor Commented:
Hi,
thanx,
How can I check if a different (VB6) application (I wrote)  is running?
0
 
aelatikCommented:
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
Independent Software Vendors: 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!

 
R_RajeshCommented:
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
 
zolpoAuthor Commented:
R_Rajesh You'r right!

I am adding more 150 points (in this question) for that sub question.
0
 
aelatikCommented:
The function i posted will check if your exe is already running, or another exe. Just try it....
0
 
aelatikCommented:
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
 
planoczCommented:
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
 
RocketMan801Commented:
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
 
zolpoAuthor Commented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now