Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Geting Windows NT services and drives.

Reply
Thread Tools

Geting Windows NT services and drives.

 
 
490
Guest
Posts: n/a
 
      02-15-2007
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.

 
Reply With Quote
 
 
 
 
490
Guest
Posts: n/a
 
      02-16-2007
On Feb 15, 8:32 pm, Christian Winter <(E-Mail Removed)> wrote:
> 490 wrote:
> > 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,(securit y)}//' .
> $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'}
> );}
>
> ----------------------------------------------------------------
>
> HTH
> -Chris


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Geting Checkboxlist value in javascript Satheesh Babu B ASP .Net 14 05-24-2007 08:29 AM
Geting physical path of IIS directories DagoFlores ASP .Net 0 09-19-2005 03:39 PM
ASP.NET textbox control is not geting refreshed.. Jitendra Singh via .NET 247 ASP .Net 1 03-29-2005 02:12 PM
Geting class attributes types harry ASP .Net 1 05-11-2004 06:17 AM
geting the sdk Jay Java 1 09-14-2003 06:15 AM



Advertisments