Geting Windows NT services and drives.

4

490

Hi.
I am trying to get win NT services and drives detailes.
I used the code:

'WINMSD /f' ;
'set >info.txt';

And then i go through the details and get what i want form the txt
file.
The problem is that this is a very ugly way and it uses alot of CPU &
Memory Usage.

Does any body have a better and faster way?!

Thanks
490.
 
4

490

490 said:
I am trying to get win NT services and drives detailes.
I used the code:
'WINMSD /f' ;
'set >info.txt';
And then i go through the details and get what i want form the txt
file.
The problem is that this is a very ugly way and it uses alot of CPU &
Memory Usage.
Does any body have a better and faster way?!

I'd use Win32::OLE and the WMI for that. The WMI classes are
well documented over at msdn.microsoft.com (there you will find
all attributes explained, like e.g. the DriveType numbers I'm
using in the example), and using them is quite straight forward.

Though if I recall correctly, WMI has to be installed manually
on NT 4 (requiring SP4 or above), but this has the bonus of
running on later MS-OSes without changes, whereas the "write
text" option of winmsd got lost somewhere along the way.

----------------------------------------------------------------
#!/perl

use strict;
use warnings;
use Win32::OLE qw(in);

my $computer = "."; # MS's short notation for "this host"

my $wmi = Win32::OLE->GetObject(
'winmgmts:{impersonationLevel=impersonate,(security)}//' .
$computer .
'/root/CIMV2'
);

print "Logical Drives:" . $/;
print "===============" . $/;

my $drives = $wmi->ExecQuery(
'SELECT * FROM Win32_LogicalDisk ' .
'WHERE DriveType = 2 OR DriveType = 3'
);

foreach my $drive ( in($drives) )
{
printf( "%s %-12s Bytes, %-12s Bytes free$/",
$drive->{'Name'},
$drive->{'Size'},
$drive->{'FreeSpace'}
);

}

print "Services:" . $/;
print "=========" . $/;

my $services = $wmi->ExecQuery('SELECT * FROM Win32_Service');

foreach my $srvc ( in($services) )
{
printf("%-30s %10s: %-10s (%s)$/",
$srvc->{'Name'},
"[" . $srvc->{'StartMode'} . "]",
$srvc->{'State'},
$srvc->{'PathName'}
);}

I thought about that but it steel uses lots of CPU.
Isn't there a perl module way?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top