Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Active Process

by holycamel (Initiate)
on Sep 30, 2003 at 21:31 UTC ( #295451=perlquestion: print w/replies, xml ) Need Help??

holycamel has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm looking for a way to retrieve the calling command, with params, of an active process. Via WMI I can get PID, path, programm etc. In Perl 5.6 and Win2000 Thanks in advance Jan

Replies are listed 'Best First'.
Re: Active Process
by BrowserUk (Pope) on Sep 30, 2003 at 22:47 UTC

    Take a look at Win32::Process::Info.

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

Re: Active Process
by AcidHawk (Vicar) on Oct 01, 2003 at 03:44 UTC
    I am not sure I know exactally what you need but what follows is some code to list all the active processes and their pids. Inotepad is running it will kill it.. if several notepads are running they will ALL be killed.
    #! /usr/bin/perl use strict; use warnings; use Win32::OLE qw( in ); use Win32::OLE::Variant; use Win32::Process; my $srv = "\\\\" . $ENV{'COMPUTERNAME'}; my $CLASS = "winmgmts:{impersonationLevel=impersonate}$srv\\Root\\cimv +2"; my $WMI = Win32::OLE->GetObject( $CLASS ) || die; foreach my $Proc ( in($WMI->InstancesOf( "Win32_Process" ) ) ) { if ($Proc->{Name} =~ /^notepad/i) { printf( "%d\t- %s ***KILLING***", $Proc->{ProcessID}, $Proc->{ +Name}); print "\n"; Win32::Process::KillProcess($Proc->{ProcessID}, 0); } else { printf( "%d\t- %s", $Proc->{ProcessID}, $Proc->{Name}); print "\n"; } }

    Of all the things I've lost in my life, its my mind I miss the most.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://295451]
Approved by jdtoronto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2021-04-19 20:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found