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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting the real and effective UID of a process

Status
Not open for further replies.

ranadhir

Programmer
Joined
Nov 4, 2003
Messages
54
Location
IN
How do i retrieve the real and effective UID of a perl process on windows?
Also, i understand that there is not absolute portability between activestate and cygwin perl .so it will be very helpful if icould know which function works in which particular environment.
Any help on this will be very much appreciated
 
See Win32::Process::Info

Code:
use Win32::Process::Info;

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

my @info = $pi->GetProcInfo;

foreach my $process (@info) {
   my $filepath = $process->{ExecutablePath};
   my $owner    = $process->{Owner};

   print "$filepath\n"
      . "Owner: $owner\n\n";
}

The output of that code for me, for a process I'm running (i.e. aim.exe), Owner is "MAIN\\Owner" (where \\ is a Perl escape code, so "MAIN\Owner" in plain text). My user name is Owner. MAIN is my computer's name on my network. So the Owner key may differ depending on your setup.
 
I could also add:

If you use Data::Dumper to show the output of @info or any of the $process hashrefs within, you can see all the keys for each process and their values.

Here's my output from aim.exe (AOL Instant Messenger):
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'
         };
 
thanks a lot for the quick response.I am new to perl scripting and am not exactly sure of the data dumper approach,though it looks very useful.
Can you provide a sample of exactly how to get about it?
thanks again.
 
Code:
use Data::Dumper;

print Dumper (@array);
print Dumper (%hash);
print Dumper ($reference);

If you do Dumper @info from the last code I post, it'll post each hashref as its own variable (hence the $VAR35 in my example, it was the 35th item in the array).

Sometimes data structures are really large so you'd want to write it to a file to view later

Code:
open (OUT, ">./file.txt");
print OUT Dumper($data);
close (OUT);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top