Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program
Terminating a previous instance of a VB program Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Go Back  Xtreme Visual Basic Talk > > > Terminating a previous instance of a VB program


Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2003, 01:26 PM
topspin topspin is offline
Newcomer
 
Join Date: Oct 2003
Location: aaaaa
Posts: 3
Default Terminating a previous instance of a VB program


I can prevent a new instance of a vb prorgam from running by checking for a previous instance and unloading the new instance. See code below:

If App.PrevInstance then
Unload Me
endif

But what I really wanted is to kill the old instance when the new instance is run. How can I do that?
Reply With Quote
  #2  
Old 11-19-2003, 01:36 PM
VeRiTo's Avatar
VeRiTo VeRiTo is offline
Contributor
 
Join Date: Nov 2003
Location: Buenos Aires
Posts: 614
Default

why do you want to do that?
__________________
.:.VeRiTo.:.
Reply With Quote
  #3  
Old 11-19-2003, 01:55 PM
topspin topspin is offline
Newcomer
 
Join Date: Oct 2003
Location: aaaaa
Posts: 3
Default

Quote:
Originally Posted by VeRiTo
why do you want to do that?



I just want it to start fresh all the time and if there is a crashed version running in the background that I get it kicked out first. I do not know how complicated it is to do this but if it is easy then I do not have to know the state or status of the old version that is running, I do not care where it is, I just want it out of my way. It this asking too much?
Reply With Quote
  #4  
Old 11-19-2003, 02:19 PM
Techno Techno is offline
Senior Contributor
 
Join Date: Mar 2002
Location: Edinburgh
Posts: 983
Default

you can kill the PID of it

i've done it - but using a different solution

it was an MS solution - running a 3rd party app and when it closes - it returns back to your VB program
Reply With Quote
  #5  
Old 11-20-2003, 03:45 AM
JordanChrisTerminating a previous instance of a VB program JordanChris is offline
Senior Contributor

* Expert *
 
Join Date: Jan 2003
Location: Newbury, UK
Posts: 1,092
Default

To kill the previous application:
Code:
Public Declare Function FindWindow Lib "user32" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Public Declare Function PostMessage Lib "user32" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function WaitForSingleObject Lib "kernel32" _ (ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As Long Public Const WM_CLOSE = &H10 Public Const INFINITE = &HFFFFFFFF Sub Form_Load Dim AppName, X, hWindow AppName = App.Title App.Title = "Nothing" hWindow = FindWindow(vbNullString, AppName) App.Title = AppName If hWindow <> 0 Then X = PostMessage(hWindow, WM_CLOSE, vbNull, vbNull) X = WaitForSingleObject(hWindow, INFINITE) End If End Sub
Reply With Quote
  #6  
Old 11-20-2003, 01:30 PM
topspin topspin is offline
Newcomer
 
Join Date: Oct 2003
Location: aaaaa
Posts: 3
Default

Quote:
Originally Posted by JordanChris
To kill the previous application:
Code:
Public Declare Function FindWindow Lib "user32" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Public Declare Function PostMessage Lib "user32" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function WaitForSingleObject Lib "kernel32" _ (ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As Long Public Const WM_CLOSE = &H10 Public Const INFINITE = &HFFFFFFFF Sub Form_Load Dim AppName, X, hWindow AppName = App.Title App.Title = "Nothing" hWindow = FindWindow(vbNullString, AppName) App.Title = AppName If hWindow <> 0 Then X = PostMessage(hWindow, WM_CLOSE, vbNull, vbNull) X = WaitForSingleObject(hWindow, INFINITE) End If End Sub



Thanks Jordan, I'll try it
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
lifting by your bootstraps: can I make a no-DLL vb program? Glade General 2 11-04-2003 09:24 AM
How To fire up another program using VB ? wingyean General 13 08-21-2003 01:47 AM
Spawning a separate 2nd VB program flowers General 2 03-06-2003 02:32 PM
QB to VB Conversion - By AIO BillSoo Tutors' Corner 0 08-06-2002 11:37 AM
Inserting a irc channel/room into a vb program? cow General 0 09-07-2000 10:19 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
 
Terminating a previous instance of a VB program
Terminating a previous instance of a VB program
 
-->