Question

Auto restart VB application after illegal kill by end process

Asked by: thuannc

Hi Experts
How can I automaticly restart my app as soon as it is illegal killed by end process in TaskManager (XP/NT/2K).
Thank

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-03-04 at 19:40:11ID20907840
Tags

vb

Topic

Visual Basic Programming

Participating Experts
5
Points
250
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. How to detect process killed from TaskManager
    MFC app. How to detect if the process is being killed from taskmanager by clicking on "End process" button. The app needs to clean up and exit gracefully.
  2. Using Proxy illegal?
    I am running a local proxy on windows98. Have some users who connect to my proxy by telnet. Many of my users are teenagers who chat on chat lines/IRC net. Lately I have had a lot of warning E-mails from webmasters about illegal proxy connection. They have banned my IP from so...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: vinnyd79Posted on 2004-03-04 at 19:45:39ID: 10519841

I think you would have to have a second app running to monitor the first app and launch it if the process doesn't exist anymore.

 

by: thuanncPosted on 2004-03-04 at 20:50:47ID: 10520122

user can illegal kill the second app also. I want to forbid any illegal kill my app

 

by: EDDYKTPosted on 2004-03-05 at 04:46:47ID: 10521968

If you write as service and run on W2k or higher,

You should be able to let the system to restart your app.

Check the recovery tab on service properties

 

by: thuanncPosted on 2004-03-08 at 00:29:17ID: 10538947

1. My App have to run in any Windows OS (9x,XP,NT,2K) so that services is not very good for me. Further more it is also can not forbid any illegal killing action.
2. for vinnyd97 solution: do you have any sample code for your solutions?
thank

 

by: NazdorPosted on 2004-03-09 at 05:39:27ID: 10549968

http://www.thescarms.com/vbasic/StopReBoot.asp

Not to sound to facetous, but could you not have an app A than monitors app B, while app B is monitoring app A ?   Using ctrl-alt-del, a user can only close one app at a time.

 

by: thuanncPosted on 2004-03-09 at 18:37:36ID: 10557189

Yes you are right Mr Nazdor. The sample in your link to restrict using TaskManager but it is not good for XP/NT/2K because it have to reboot to apply restriction.
I dont know how to monitor an app. from another one. Please give me a small example or some guide for it.
Thank

 

by: LeithauserPosted on 2004-04-09 at 13:53:21ID: 10794221

I am also working on a several programs that users might want to shut down illegally (security programs to prevent employees from accessing certain programs or children from getting on certain sites and such), so I have encountered the same problem. I have also been thinking along the lines of having two programs monitor each other, and each starts up the other if the other is shut down. One way to do this I can see is to have each program write a file to the disk, and the other erase it. For example, every 15 seconds or so, program A writes file ggg.txt (the name is arbitrary) to the Windows folder (or any other folder). Every 20 seconds program B checks to see if ggg.txt exists. If the file exists, Program B deletes it. If it does not exist, program B reruns program A. That way, if program A stops, the file is not there the next time that program B looks for it and program A gets restarted. Program B writes a similar file for A to look for. Likewise, program B writes a different file every 15 seconds, and Program A checks for this file every 20 seconds.
    I can see several problems with this, such as the fact that it consumes a bit of system resources, but it might be worth it if it is really important to keep the programs running.

 

by: BlueDevilFanPosted on 2004-04-17 at 19:24:05ID: 10851642

The problem with two applications watching each other is that both could be killed within the alloted span of time leaving neither in a position to restart the other.  That may be unlikely, but it is possible.  After some thought I've come up with three other possibilities.  The first option is to use Windows' built-in task scheduler.  By scheduling the watching task, i.e. the program that's to check and see if the critical program is running, to run periodically it makes it more difficult for a user to find and dispose of it.  The watcher program runs just long enough to check and see if the production app is running.  If it's not, then it restarts it.  If it is, then it takes no action and terminates until the next scheduled run.  Option two will only work if the computers are all operating on a network.  The idea here is to use the Winsock control and have the watcher program running on a server or some other remote machine.  Periodically the central process can query user machiens to see if the required app is running.  If it isn't, then the central watcher app can start it remotely.  This approach is better in that it separates the watcher app from the required app and makes it impossible for a user to halt them both.  The downside though is that it requires bandwidth and, of course, won't be of any use for a PC not connected to the network.  The final possibility is to stick some code in the unload event of the production app to launch an app that'll restart it.  That'll only work if the app is shut down in a normal fashion though.  It won't work if the app is killed via Task Manager.  Maybe a hybrid approach that uses multiple methods to keep the production app running is best.

Here's a link to some code that lists running tasks.  One of them also includes code that is supposed to start a task remotely.  I can't vouch for whether it works or not.

http://www.freevbcode.com/ShowCode.Asp?ID=1861
http://www.andreavb.com/tip020014.html

 

by: LeithauserPosted on 2004-04-18 at 12:24:10ID: 10854562

  I have this same problem (people illegally killing the program), so I have come up with a solution. It does involve running two copies of the program, each of which monitors the other.
    When you first run the program, it runs another copy of itself. (When the program runs the second copy, it includes a command line to tell the second copy that it is a second copy.) The programs give themselves different title bars to distinguish between them. They then monitor each other using API calls. When one disappears, the other relaunches it. The monitoring is done with the timer control, which can be set to very short intervals, too short for anyone to kill both in time. I have tested this with half second intervals, and been totally unable to kill both. Someone who is really concerned can shorten it further. Since the programs use API calls, it is not as resource intensive as my original suggestion of using files to communicate. My solution works very well. I can post code if thuannc is still interested in this. Since I plan to use it in several programs, I have put all the code and global constants in one portable module, with directions where to put links to the subs. (I create security programs designed to limit access to computers.)

 

by: thuanncPosted on 2004-04-18 at 18:40:33ID: 10855961

Hi all
I think BlueDeviFan have some good idea but I more prefer Leithauser solution be cause if I monitor app. remotely user easy to disconnect computer from network and then kill my app. I do it myself before (like vinnyd97 or Leithauser solution) but I have small problem with communicating beetween two app. Could you please give me your sample to learn more, Leithauser.
Thank

 

by: LeithauserPosted on 2004-04-19 at 07:57:02ID: 10860237

Create a module (VB4 or higher) with this code in it:

Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Declare Function GetForegroundWindow Lib "user32" () As Long

Global Const Name1 = "APT1" ' Caption to go on main form of instance of the program to be run first. Use any string you like.

Global Const Name2 = "APT2" ' Caption to go on main form of second instance of the program (which will be run by the first instance of the program). Use any string you like, different from the first one.

Global OtherCaption$




Sub Protect(frm As Form)

' a call to this sub goes in a timer on the main form. The code is "Protect Me". Set timer interval to about 500 (.5 seconds between triggers)

Static HoldiRet As Long
Dim iRet As Long, iRet2 As Long
Dim Buffer$
Dim BufLen&, JunkL&

iRet = FindWindow&(vbNullString, OtherCaption$)

If iRet = 0 Then
    Shell App.Path & "\" & App.EXEName & ".exe " & OtherCaption$ & ":" & frm.Caption, 4
    DoEvents
    HoldiRet = FindWindow&(vbNullString, OtherCaption$)
Else
    If HoldiRet <> 0 And HoldiRet <> iRet Then
        iRet2 = GetForegroundWindow()
        Buffer$ = Space$(255)
        BufLen& = 254
        JunkL& = GetWindowText(iRet2, Buffer$, BufLen&)
        Buffer$ = Left$(Buffer$, InStr(Buffer$, Chr$(0)) - 1)
        On Error Resume Next
        AppActivate OtherCaption$
        If Err Then
            Err = 0
            Shell App.Path & "\" & App.EXEName & ".exe " & OtherCaption$ & ":" & frm.Caption, 4
            DoEvents
            HoldiRet = FindWindow&(vbNullString, OtherCaption$)
        Else
            AppActivate Buffer$
        End If
    End If
End If

If iRet <> 0 Then HoldiRet = iRet

End Sub




Sub SetCaption(frm As Form)

' A call to this sub goes in the Form_Load module on the main form. The code is "SetCaption Me".

Dim S$, N As Integer

If Len(Command$) Then
    S$ = Command$
    N = InStr(S$, ":")
    frm.Caption = Left$(S$, N - 1)
    OtherCaption$ = Mid$(S$, N + 1)
Else
    frm.Caption = Name1
    OtherCaption$ = Name2
End If

End Sub


Note:  It is VERY important to be able to shut down the program legitimately in order to be able to upgrade or uninstall the program. I cannot stress this too much!
    In order to be able to shut down the program, you will need to have the first instance send a signal to the second instance telling it to end first.

   In the KeyPress module of the main form, I include something like

If KeyAscii = Asc("X") then
    If Me.Caption = Name1 Then
          Timer1.Enabled = False ' Stop timer from restarting other Instance of the program
          AppActivate Name2
          Sendkeys "X", True
          End
     Else
          Timer1.Enabled = False
          End
     End if
End If

   This enables you to shut down the program legitimately by giving it the focus and pressing the X key. You should also include

If  Me.Caption = Name1 Then
       Timer1.Enabled = False
        AppActivate Name2
        Sendkeys "X", True
        End
End If

in the legitimate Exit function of the program for the same reason.

  Another possibility is to have some code in the program that searches for a certain file. If it finds the file, the program ends. Something like
If Len(Dir$("C:\NoRun.txt")) then End
You can put this in the timer module  before the
Protect Me
statement. This will allow your uninstall program to create this file and then wait a few seconds for the program to terminate before it deletes the files from the computer.

(Use code like
Open "C:\NoRun.txt" for Output as 1
Close 1
StartCount! = Timer
Do
   DoEvents
Loop until Timer - StartCount >5
Kill "C:\NoRun.txt"
to create this file and then wait.)


 

by: LeithauserPosted on 2004-06-08 at 07:36:26ID: 11260405

One last comment from me:

It is a good idea to include an
On Error Resume Next
command at the beginning of the Protect Sub. Otherwise, it occasionally generates an error when you close down Windows if Windows happens to try to close the program down at just the right (or should I say, wrong) point in hte protect proceedure. This appears to happen because Windows closes down the main form before it closes down the code in Protect, so Protect tries to refer to the form when it does not exist.

David Leithauser

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...