aatlamaz has asked for the wisdom of the Perl Monks concerning the following question:

I need to write a script that gets windows system information such as host model, ip address, operating system version, release and level. I thought that I could do it with DOS commands. But I cant see any DOS commands that gives any info that I need. Do you guys know any Perl script, or idea how to handle this ? Appreciate your help in advance. Thanks AA

Replies are listed 'Best First'.
Re: Need windows system info
by FitTrend (Pilgrim) on Mar 10, 2005 at 17:29 UTC

    Using WMI will probably be your best approach. However, some information is not available or off by default.

    cpan certainly will have lots of modules for you.

    I've used IO::Socket and Sys::Hostname for Ip address, WMI for model, os info, etc. For network stats, netstat's output could be parsed for statistics.

    For WMI, I've used Win32::OLE and Win32::OLE:Enum.

    Hope this helps

    I have posted some sample code in This node

    .
Re: Need windows system info
by ikegami (Patriarch) on Mar 10, 2005 at 17:29 UTC

    ver gives the OS and its version.

    ipconfig gives the IP address.

    Certain env vars are also available. The following are from Win2k:

    COMPUTERNAME=WEITORDT480 NUMBER_OF_PROCESSORS=1 OS=Windows_NT PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 6, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=0806 USER=ebrine USERDNSDOMAIN=wardrop.biz USERDOMAIN=WARDROP USERNAME=ebrine
Re: Need windows system info
by inman (Curate) on Mar 10, 2005 at 17:32 UTC
    Try PSInfo from the PSTools toolset from SystemInternals. It should give you all the data you need.

    If you want to find the information without executing an external app then you are going to have to locate it in the registry and query it directly.

      I think this will pretty much should get you started
      use strict; use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my @computers = ("PUTYOURCOMPUTERNAMEHERE"); foreach my $computer (@computers) { print "\n"; print "==========================================\n"; print "Computer: $computer\n"; print "==========================================\n"; my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\ +root\\CIMV2") or die "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Opera +tingSystem", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $colItems) { print "BootDevice: $objItem->{BootDevice}\n"; print "BuildNumber: $objItem->{BuildNumber}\n"; print "BuildType: $objItem->{BuildType}\n"; print "CreationClassName: $objItem->{CreationClassName}\n"; print "CSCreationClassName: $objItem->{CSCreationClassName}\n"; print "CSDVersion: $objItem->{CSDVersion}\n"; print "FreePhysicalMemory: $objItem->{FreePhysicalMemory}\n"; print "FreeVirtualMemory: $objItem->{FreeVirtualMemory}\n"; print "InstallDate: $objItem->{InstallDate}\n"; print "LastBootUpTime: $objItem->{LastBootUpTime}\n"; print "LocalDateTime: $objItem->{LocalDateTime}\n"; print "Manufacturer: $objItem->{Manufacturer}\n"; print "Name: $objItem->{Name}\n"; print "NumberOfProcesses: $objItem->{NumberOfProcesses}\n"; print "NumberOfUsers: $objItem->{NumberOfUsers}\n"; print "Organization: $objItem->{Organization}\n"; print "OSType: $objItem->{OSType}\n"; print "RegisteredUser: $objItem->{RegisteredUser}\n"; print "SerialNumber: $objItem->{SerialNumber}\n"; print "ServicePackMajorVersion: $objItem->{ServicePackMajorVersi +on}\n"; print "ServicePackMinorVersion: $objItem->{ServicePackMinorVersi +on}\n"; print "Status: $objItem->{Status}\n"; print "SystemDevice: $objItem->{SystemDevice}\n"; print "SystemDirectory: $objItem->{SystemDirectory}\n"; print "Version: $objItem->{Version}\n"; print "WindowsDirectory: $objItem->{WindowsDirectory}\n"; print "\n"; } system("ipconfig /all"); }sub WMIDateStringToDate(strDate) { return "blah"; }
Re: Need windows system info
by eieio (Pilgrim) on Mar 10, 2005 at 17:31 UTC
    The Win32 module's GetOSVersion function covers some of this information. For example:
    ($verServicePack, $verMajor, $verMinor, $verBuild, $verId) = Win32::GetOSVersion();