8 Replies - 808 Views - Last Post: 19 May 2009 - 11:06 PM Rate Topic: -----

#1 masipro  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 08-July 08

EXE

Post icon  Posted 18 May 2009 - 09:14 PM

Hai,
I have created an exe. I want the exe to be run (on any system) only once i.e. if already the exe is currently running on the system then the same exe file (clicked once again) should not be run; if anybody using the same exe more than once it should pass a message already running.

Please help me, i would greately appreciate if any overcome this solution.

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: EXE

#2 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 49
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Re: EXE

Posted 18 May 2009 - 09:21 PM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: EXE

Posted 18 May 2009 - 09:48 PM


'if startup object is form
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
  Unload Me
End If

'if start up object is sub main
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
Else
  Form1.Show 'or the name of your form
End If



Good Luck
Was This Post Helpful? 0
  • +
  • -

#4 masipro  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 08-July 08

Re: EXE

Posted 18 May 2009 - 09:54 PM

View Postvb5prgrmr, on 18 May, 2009 - 08:48 PM, said:


'if startup object is form
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
  Unload Me
End If

'if start up object is sub main
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
Else
  Form1.Show 'or the name of your form
End If



Good Luck

Thanks a lot; this is what i what i want. Thank you once again
Was This Post Helpful? 0
  • +
  • -

#5 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 773
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: EXE

Posted 18 May 2009 - 10:28 PM

You can also take a look at this Microsoft KB article for a solution:

How to prevent multiple instances of a 32-bit VB application
http://support.microsoft.com/kb/185730
Was This Post Helpful? 0
  • +
  • -

#6 masipro  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 08-July 08

Re: EXE

Posted 18 May 2009 - 10:29 PM

I ran my exe once and still running in background. After adding the code
'if startup object is form
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
  Unload Me
End If


it successfully working but before informing "Program already running" it shows an error:
==========
Run-time error '3709':
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
==========
What kind of error this is. I made the exe for Reminder using VB+MSAccess.
Any other my program information need to help me?
Was This Post Helpful? 0
  • +
  • -

#7 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 773
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: EXE

Posted 18 May 2009 - 10:47 PM

Seems like there is additional code you are using before actually veryfiying for the second instance. And when the database is already open by another application, it generates this error. Try placing the instance verification code before any other code in the startup event.
Was This Post Helpful? 0
  • +
  • -

#8 masipro  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 08-July 08

Re: EXE

Posted 19 May 2009 - 04:18 AM

View Postvb5prgrmr, on 18 May, 2009 - 08:48 PM, said:


'if startup object is form
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
  Unload Me
End If

'if start up object is sub main
If App.PrevInstance = True Then
  MsgBox "Program already running!", vbOKOnly + vbInformation, "Program running"
Else
  Form1.Show 'or the name of your form
End If



Good Luck

After setting the reminder time in my exe, i used to make the application run in background which actually runs but not visible. After checking PrevInstance I want the application to be restored .
Was This Post Helpful? 0
  • +
  • -

#9 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: EXE

Posted 19 May 2009 - 11:06 PM

Then you will need to use the API to do this...

FindWindow API then...

SetForeGroundWindow or SetWindowPos or SendMessage...

However, I have not tried to use the FindWindow API on a window that is not visible via me.hide but if it is minimized I know it works. Which means you may need to enumerate through the running processes to get the handle to the previous instance of your app so that you can activate it.

Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1