Windows Perl Scripting Forums » News

Need help in Perl scripting to get system details in windows XP operating system

(3 posts)
  • Started 3 years ago by dineshkhanna
  • Latest reply from freebsdboy

Tags:


  1. dineshkhanna
    Member

    Need help in Perl scripting to get system details in windows XP operating system.Currently I am using win32 class to get the system details like RAM size, processor speed ,Hard disk capacity and fetching the list of installed software.I would like to write the Perl script to get the above system details without using win32 class.
    I will be great if you could able to guide me to write the Perl script to get the above system details without using win32 class.
    Below is the sample code which I am currently using to get Hard Disk capacity in Perl,
    use strict;
    use Win32::OLE('in');
    use constant wbemFlagReturnImmediately => 0x10;
    use constant wbemFlagForwardOnly => 0x20;
    my @computers = ($_[0]);
    foreach my $computer (@computers)
    {
    my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection failed.\n";
    my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL",
    wbemFlagReturnImmediately | wbemFlagForwardOnly);
    foreach my $objItem (in $colItems)
    {
    print "\n";
    print "Hard Disk capacity : $objItem->{Size}\n";
    print "\n";
    }
    }

    Posted 3 years ago #
  2. freebsdboy
    Member

    Here is some easy code to use. We use it to help assist unattended installs know what drivers to install.

    use Win32::OLE qw(in with);
    use Win32::Registry;

    # Pick a host that you have the necessary rights to monitor

    $host = "localhost";
    $path = 'c:\\temp';

    $WMI = Win32::OLE->new('WbemScripting.SWbemLocator') ||
    die "Cannot access WMI on local machine: ", Win32::OLE->LastError;

    $Services = $WMI->ConnectServer($host) ||
    die "Cannot access WMI on remote machine: ", Win32::OLE->LastError;

    # Gather Computer System Information

    $sys_set = $Services->InstancesOf("Win32_ComputerSystem");
    foreach $sys (in($sys_set))
    {
    $system_name = $sys->{'Caption'};
    $system_type = $sys->{'SystemType'};
    $system_manufacturer = $sys->{'Manufacturer'};
    $system_model = $sys->{'Model'};
    }

    # Gather Processor Information
    $processor_set = $Services->InstancesOf("Win32_Processor");
    foreach $proc (in($processor_set))
    {
    $proc_description = $proc->{'Caption'};
    $proc_manufacturer = $proc->{'Manufacturer'};
    $proc_mhz = $proc->{'CurrentClockSpeed'};
    }

    # Gather BIOS Information

    $bios_set = $Services->InstancesOf("Win32_BIOS");
    foreach $bios (in($bios_set))
    {
    $bios_info = $bios->{'Version'};
    }

    # Gather Time Zone Information

    $loc_set = $Services->InstancesOf("Win32_TimeZone");
    foreach $loc (in($loc_set))
    {
    $loc_timezone = $loc->{'StandardName'};
    }

    # Gather Operating System Information

    $os_set = $Services->InstancesOf("Win32_OperatingSystem");
    foreach $os (in($os_set))
    {
    $os_name = $os->{'Caption'};
    $os_version = $os->{'Version'};
    $os_manufacturer = $os->{'Manufacturer'};
    $os_build = $os->{'BuildNumber'};
    $os_directory = $os->{'WindowsDirectory'};
    $os_locale = $os->{'Locale'};
    $os_totalmem = $os->{'TotalVisibleMemorySize'};
    $os_freemem = $os->{'FreePhysicalMemory'};
    $os_totalvirtmem = $os->{'TotalVirtualMemorySize'};
    $os_freevirtmem = $os->{'FreeVirtualMemory'};
    $os_pagefilesize = $os->{'SizeStoredInPagingFiles'};
    }

    # Now convert the system's Locale to a string
    # Use the Rfc1766 Database stored in the Registry as a lookup table

    $main::HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Classes\\MIME\\Database\\Rfc1766",$Rfc1766);
    $Rfc1766->GetValues(\%Values);
    foreach $key (keys %Values)
    {
    $key = $Values{$key};
    if ($$key[0] eq $os_locale)
    {
    ($lang, $country) = split(/\;/, $$key[2]);
    last;
    }
    }

    # make a file by the name of the system model and put all this in it.
    $system_model = laptop if ($system_model eq '');
    open( FILE_HANDLE, ">$path\\$system_model") or die "Can't write to $path\\$system_model\n" ;

    print FILE_HANDLE "System Summary Information\n";
    print FILE_HANDLE "--------------------------\n";
    print FILE_HANDLE "OS Name\t\t\t\t$os_name\n";
    print FILE_HANDLE "Version\t\t\t\t$os_version Build $os_build\n";
    print FILE_HANDLE "OS Manufacturer\t\t\t$os_manufacturer\n";
    print FILE_HANDLE "System Name\t\t\t$system_name\n";
    print FILE_HANDLE "System Manufacturer\t\t$system_manufacturer\n";
    print FILE_HANDLE "System Model\t\t\t$system_model\n";
    print FILE_HANDLE "System Type\t\t\t$system_type\n";
    print FILE_HANDLE "Processor\t\t\t$proc_description $proc_manufacturer ~$proc_mhz Mhz\n";
    print FILE_HANDLE "BIOS Version\t\t\t$bios_info\n";
    print FILE_HANDLE "Windows Directory\t\t$os_directory\n";
    print FILE_HANDLE "Locale\t\t\t\t$country\n";
    print FILE_HANDLE "Time Zone\t\t\t$loc_timezone\n";
    print FILE_HANDLE "Total Physical Memory\t\t$os_totalmem KB\n";
    print FILE_HANDLE "Available Physical Memory\t$os_freemem KB \n";
    print FILE_HANDLE "Total Virtual Memory\t\t$os_totalvirtmem KB\n";
    print FILE_HANDLE "Available Virtual Memory\t$os_freevirtmem KB\n";
    print FILE_HANDLE "Page File Space\t\t\t$os_pagefilesize KB\n";
    close (FILE_HANDLE);

    Posted 3 years ago #
  3. freebsdboy
    Member

    To get the list of installed software you'll need to use
    Win32::TieRegistry
    and look in
    $Registry->{"LMachine/Software/Microsoft/Windows/CurrentVersion/Uninstall/"};

    Posted 3 years ago #

RSS feed for this topic

Reply

You must log in to post.