Here is one way by searching for a window-name in the variable $Program:

    # Check for another instance of this program.
    use Win32::GUI;
    my $Desktop = GUI::GetDesktopWindow();
    my $Window  = GUI::GetWindow($Desktop, GW_CHILD);
    my $Nbr     = 0;
    # $Program    = ($HostName eq 'mailcd3') ? 'SchedulePDF' :
'ArchivePDF';
    $Program    = 'ArchivePDF';
    while ($Window)
    {
        my $Title  = GUI::Text($Window);
        if (length($Title) > 1 and $Title !~ /command prompt/i) {$Nbr++
if ($Title =~ /^$Program/i)}
        $Window = GUI::GetWindow($Window, GW_HWNDNEXT);
    }

    if ($Nbr > 1)
    {
        print(STDERR "Another instance of this program exists, exiting
program\n");
        print(STDERR "Ending $0\n");
        exit(1);
    }
 
In this example, if an instance of this program is already running, we
will exit the program to prevent multiple occurences of the program.
Note that in this example, we are searching against the window's actual
title.  

Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis MO
- USA Central Time Zone
636-755-2652 fax 636-755-2503

[EMAIL PROTECTED]
www.nisc.coop 

 


________________________________

        From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Darrell Snedecor
        Sent: Tuesday, September 20, 2005 08:47
        To: perl-win32-users@listserv.ActiveState.com
        Subject: Check for running process
        
        
        How do I use Perl to check for the existence of a running
program in Windows?
         
         
        Best Regards
        Darrell Snedecor
        Director
        Harrisburg Project
        800-635-5274  618-253-8504
         


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to