You may want to look at some ready-made code, here in the Code Catacombs, NT Admin section:
Hardware/Software Inventory by shonorio.
Some code from the XP cookbook may help:
# From the book "Windows XP Cookbook"
# ISBN: 0596007256
# Note that you cannot use this to connect to the local machine.
# ------ SCRIPT CONFIGURATION ------
use Win32::OLE;
$strServer = '<HostName>';
# e.g. wks01
$strUser = '<User>';
# e.g. AMER\rallen.adm
$strPasswd = '<Password>';
# ------ END CONFIGURATION ---------
$objLocator = Win32::OLE->new('WbemScripting.SWbemLocator');
$objWMI = $objLocator->ConnectServer($strServer, 'root\\cimv2', $strUs
+er, $strPasswd);
if ((0 + Win32::OLE::LastError()) != 0) {
print 'Authentication failed: ' . ('' . Win32::OLE::LastError()),
+"\n";
}
# Now you can use the objWMI object to get an instance of a class
# or perform a WQL query. Here is an example:
$colDisks = $objWMI->InstancesOf('Win32_LogicalDisk')->Item;
..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.