Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

uninstall/delete running program

Posted on 2005-05-03
14
Medium Priority
?
427 Views
Last Modified: 2008-02-01
I have a program that runs continuously once an hour that looks something like this:

while (1 == 1)
    {
   #  stuffs ......
    sleep(3600);
    }

During uninstall or deletion of this program, windows won't allow you to.  You can just go into task manager and just stop it, but is there a way I can make perl run once an hour like this, but have it stop when I uninstall?  
0
Comment
Question by:tedhyu
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 13922506
while( -e __FILE__ ){
   #  stuffs ......
    sleep(3600);
}
0
 

Author Comment

by:tedhyu
ID: 13922638
Thanks.  I tried it, and it is kind of buggy.  Do I need to add any "USE" statements on the top.  

In addition, I use the following on the top:

use Net::FTP;
use Shell;
Win32::SetChildShowWindow(0);
use File::stat;
use Win32;
use Xbase;
use Spreadsheet::ParseExcel;

and compile it with perlapp --gui option to make the black window not appear.  Are there any compatibility issues?
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 13922655
you could run your script as a window service
http://aspn.activestate.com/ASPN/docs/ActivePerl/faq/Windows/ActivePerl-Winfaq4.html#How_do_I_run_a_Perl_script_as

Also you use Start->Accesories->System Tools->Scheduled Tasks to schedule a task to run every hour.
0
Technology Partners: 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!

 

Author Comment

by:tedhyu
ID: 13923078
Is there anything you can do with the die statement such as:

die("! -e __FILE__");
0
 
LVL 85

Expert Comment

by:ozo
ID: 13923195
In what way is is buggy?
0
 
LVL 20

Expert Comment

by:jmcg
ID: 13923732
I'll echo Teraplane's suggestion that you use your OS's task scheduler to run the working part of your script once per hour. This will complicate, slightly, your install and uninstall procedure, but should be  overall simpler.
0
 

Author Comment

by:tedhyu
ID: 13928933
-->I'll echo Teraplane's suggestion that you use your OS's task scheduler to run the working part of your script once per hour. This will complicate, slightly, your install and uninstall procedure, but should be  overall simpler.

I'm trying to avoid scheduled tasks, because it does not allow me to access network files such as z:\file.txt

 

0
 

Author Comment

by:tedhyu
ID: 13928952
-->In what way is is buggy?

I created the following test file and compiled with "perlapp test.pl --gui".  When it runs, i tried to delete it, and it does not allow me to.:

Win32::SetChildShowWindow(0);
use Win32;


while( -e __FILE__ ){

Win32::MsgBox ("This is working", 64, "Test");

sleep(3600);

}      


die("");
0
 
LVL 20

Expert Comment

by:jmcg
ID: 13932482
Why would scheduled tasks be any less able to access network files?

To get around the problems you are having, you probably need to separate the issues of whether or not the program is running/enabled from the issue of whether or not the program is installed/present.

Write your script so that it tests for the presence of some file other than itself. Ozo's initial suggestion was based on the notion that the __FILE__ name actually referred to the running script (I'd be surprised if this was always true for a compiled program) and on the notion that the file could be removed while the program was running.
0
 

Author Comment

by:tedhyu
ID: 13941324
->Why would scheduled tasks be any less able to access network files?

I posted a couple of questions on this before.

http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21359111.html
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21360360.html

From what i've been told, when scheduled tasks runs, the user is NT AUTHORITY/SYSTEM, which does not have access to network drives.  

->  To get around the problems you are having, you probably need to separate the issues of whether or not the program is running/enabled from the issue of whether or not the program is installed/present.

The program is running/enabled, during the uninstall.  

Any other suggestions?
0
 
LVL 20

Accepted Solution

by:
jmcg earned 1000 total points
ID: 13942000
I should probably shut up, since my knowledge of Windows is so meager, but here goes...

I took your meaning to say that the running program could not be uninstalled -- Windows prevents you from removing it while it's still running. What that says to me is that you need to separate the issues. You can't have an equivalency between INSTALLED and RUNNING.

There are lots of ways to control the running of a program but one simple, fairly portable way is to have the program check for the presence of a file. Ozo had you checking for the the script itself, but if you can't reliably know the name of the program or if you can't remove it while it is running, that won't work.

Since you want the program to be reasonably responsive, it can't wait around for blocks of time like 3600 seconds. Maybe 360 waits of 10 seconds between checks for the file would be okay.


use Win32;
Win32::SetChildShowWindow(0);
my $reason = 'Normal Termination';

while( 1 ){

    Win32::MsgBox ("This is working", 64, "Test");

    my $timecount = 360;
    while( $timecount-- > 0 ) {
        do { $reason = 'Termination by request'; last } if -r 'c:/dontrun';
        sleep 10;
    }
}    

die $reason;

======

This program should behave much the same as your earlier one. Unless you create a file named c:\dontrun. If you do that, it should stop running within 10 seconds.

Your install procedure should be modified to ensure that the dontrun file is removed. Your uninstall procedure should include the writing of the dontrun file, a pause for the program to stop, then it can proceed with whatever it was trying to do.

With this sort of control in place, though, you don't need to uninstall the program just to stop it from running.
0
 
LVL 85

Expert Comment

by:ozo
ID: 13942762
> I created the following test file and compiled with "perlapp test.pl --gui".
Oh, you _compiled_ it.  Sorry, i thought you wanted to run it with "perl test.pl"
0
 

Author Comment

by:tedhyu
ID: 13948569
Just wanted to share the solution I adopted in case people come with this problem in the future.  

I created a batch file and created a link to it as the uninstall link

Just for reference, the uninstall program is called unins000.exe and the program that is continuously running is test.exe

Batch file code:

taskkill /f /im test.exe
unins000.exe

I'm still trying to figure out a way to make the black window not appear when this batch file is called.  Any suggestions?  In any case, thanks for all your help.

0
 
LVL 20

Expert Comment

by:jmcg
ID: 13949561
In the olden days, I think you'd use the PIFEDIT program to set the parameters so a batch file would not create a window. Nowadays, I think you do this with Windows shortcuts - they allow you to specify things like "run minimized" and "close on exit". If you want to be thoroughly modern, I guess you'd use WSH directives.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

572 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