Geting Windows NT services and drives.

Discussion in 'Perl Misc' started by 490, Feb 15, 2007.

  1. 490

    490 Guest

    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.
     
    490, Feb 15, 2007
    #1
    1. Advertising

  2. 490

    490 Guest

    On Feb 15, 8:32 pm, Christian Winter <> 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,(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'}
    > );}
    >
    > ----------------------------------------------------------------
    >
    > HTH
    > -Chris


    I thought about that but it steel uses lots of CPU.
    Isn't there a perl module way?
     
    490, Feb 16, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. harry

    Geting class attributes types

    harry, May 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    389
    Natty Gur
    May 11, 2004
  2. =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?=

    Enumerate all the drives including Mapped network drives on a serv

    =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?=, Feb 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,048
    =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?=
    Feb 26, 2005
  3. Jitendra Singh via .NET 247

    ASP.NET textbox control is not geting refreshed..

    Jitendra Singh via .NET 247, Mar 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    694
    Rajesh C K R
    Mar 29, 2005
  4. Tuure Laurinolli

    IDLE; Pythonwin and windows network drives

    Tuure Laurinolli, Jul 1, 2004, in forum: Python
    Replies:
    3
    Views:
    393
    David Fraser
    Jul 1, 2004
  5. BWill
    Replies:
    7
    Views:
    349
    Florian Diesch
    Mar 28, 2006
Loading...

Share This Page