Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Activity Monitoring

Status
Not open for further replies.

blundellp

Technical User
Apr 6, 2005
25
GB
Does anyone know a way of bringing information from the (ctrl-alt-del) system activity prog, into a perl program useing windowsXP, i can do this in linux, but i would prefer to do it in XP.

I mean to import the programs being run on my system, or the network traffic or even the procesor utilisation.
Does anyone have any ideas please? Or some links to some information where i could read up on this?

Thanks for any help
Paul
 
Code:
use Win32::Process::Info;

		my $pi = Win32::Process::Info->new;

		my @info = $pi->GetProcInfo;
		foreach my $proc (@info) {
			if ($proc->{Name} =~ /fwink\.exe/i) {
				my $id = $proc->{ProcessId};
				print "Kill Fwink ($proc->{Name}; $proc->{ProcessId}\n";

				my $killer = Win32::OLE->GetObject ('winmgmts:\\\\.\\root\\cimv2:Win32_Process.Handle=\'' . $id . '\'');
				my $dead = $killer->Terminate();
				if ($dead == 0) {
					print "Successfully killed\n";
				}
				else {
					print "Could not kill: $dead\n";
				}
			}
		}

Here's an example of the information returned about each process:

Code:
$VAR35 = {
           'TerminationDate' => undef,
           'QuotaNonPagedPoolUsage' => 14096,
           'ParentProcessId' => 3612,
           'Status' => undef,
           'OSName' => 'Microsoft Windows XP Home Edition|C:\\WINDOWS|\\Device\\Harddisk0\\Partition1',
           'CSName' => 'MAIN',
           'PeakPageFileUsage' => 18345984,
           'PageFileUsage' => 17862656,
           'QuotaPeakNonPagedPoolUsage' => 18256,
           'WorkingSetSize' => '15802368',
           'CreationDate' => 1152556023,
           'HandleCount' => 438,
           'WindowsVersion' => '5.1.2600',
           'PeakWorkingSetSize' => 27140096,
           'MaximumWorkingSetSize' => 1413120,
           'PeakVirtualSize' => '122486784',
           'WriteOperationCount' => '3283',
           'SessionId' => 0,
           'PrivatePageCount' => '17862656',
           'Owner' => 'MAIN\\Owner',
           'ProcessId' => 2860,
           'Caption' => 'aim.exe',
           'CommandLine' => '"C:\\Program Files\\AIM\\aim.exe" -cnetwait.odl',
           'OSCreationClassName' => 'Win32_OperatingSystem',
           'Priority' => 8,
           'MinimumWorkingSetSize' => 204800,
           'CreationClassName' => 'Win32_Process',
           'ThreadCount' => 8,
           'KernelModeTime' => '174.90625',
           'ExecutionState' => undef,
           'CSCreationClassName' => 'Win32_ComputerSystem',
           'InstallDate' => undef,
           'WriteTransferCount' => '344659',
           'OtherTransferCount' => '48593576',
           'PageFaults' => 148394,
           'VirtualSize' => '111116288',
           'QuotaPagedPoolUsage' => 74132,
           'OwnerSid' => 'S-1-5-21-1026996838-2534805282-80610558-1003',
           'ReadTransferCount' => '76664453',
           'OtherOperationCount' => '673843',
           'ReadOperationCount' => '141956',
           'QuotaPeakPagedPoolUsage' => 81180,
           'ExecutablePath' => 'C:\\Program Files\\AIM\\aim.exe',
           'UserModeTime' => '72.34375',
           'Name' => 'aim.exe',
           'Description' => 'aim.exe',
           'Handle' => '2860'
         };

-------------
Kirsle.net | Kirsle's Programs and Projects
 
Sorry i'm not that advanced when i type TLIST.EXE in startmenu/run it says 'windows cannot find' , the code that you recommended kirlse could you tell me under what heading this would come so i can google it for more information please?
 
The code I posted above was just something I pulled out of one of my scripts, it was part of a code that would kill and restart fwink.exe every 5 minutes (Fwink being a webcam capture program which doesn't tend to be stable and randomly quits updating with the cam, hence the 5 minute lifespan allowed by my Perl script).

And so all the red code was something I put in to kill fwink.exe, and doesn't really have anything to do listing and looping through the list of processes, but I didn't have much time so I just pasted a full chunk of code I had lying around.

Code:
use Win32::Process::Info;

        my $pi = Win32::Process::Info->new;

        my @info = $pi->GetProcInfo;
        foreach my $proc (@info) {
            if ($proc->{Name} =~ /fwink\.exe/i) {
                my $id = $proc->{ProcessId};
                print "Kill Fwink ($proc->{Name}; $proc->{ProcessId}\n";

                [COLOR=red]my $killer = Win32::OLE->GetObject ('winmgmts:\\\\.\\root\\cimv2:Win32_Process.Handle=\'' . $id . '\'');
                my $dead = $killer->Terminate();
                if ($dead == 0) {
                    print "Successfully killed\n";
                }
                else {
                    print "Could not kill: $dead\n";
                }[/color]
            }
        }

Of course, being able to kill a process by name is a pretty useful thing to have around too, so this code may have helped solve this and future questions.

-------------
Kirsle.net | Kirsle's Programs and Projects
 
thanks for sharing the clarification Kirsle.

your script summarized:

[cannon] fwink.exe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top