Alaska Software Inc. - WMI unter VISTA/W2K
Username: Password:
AuthorTopic: WMI unter VISTA/W2K
AUGE_OHRWMI unter VISTA/W2K
on Sat, 20 Jun 2009 22:23:45 +0200
hi,

this Code work unter WinXP but it fail on VISTA / W2K3, why ?

*** Code ***
#include "common.ch"
#include "os.ch"

 need for Xbase++ activeX

#PRAGMA LIBRARY( "ASCOM10.LIB" )

PROCEDURE MAIN
   SET ALTER TO LOGFILE.TXT
   SET ALTER ON

   Win32_OperatingSystem()

   SET ALTER OFF
   SET ALTER TO
RETURN

FUNCTION Win32_OperatingSystem(strComputer)
LOCAL objWMIService
LOCAL colItems
LOCAL aItem := {}
LOCAL bItem := {}
LOCAL i,iMax
LOCAL j,jMax
LOCAL oProperty
LOCAL bCollBlock

   DEFAULT strComputer TO "Localhost"

   ? "OS()",OS(OS_PRODUCT)

   IF "VISTA" $ OS(OS_PRODUCT) .OR. ;
       "WIN2003" $ OS(OS_PRODUCT) .OR. ;
       "WIN2008" $ OS(OS_PRODUCT)
      objWMIService := CreateObject( 
"WbemScripting.SWbemLocator" ):ConnectServer( "Localhost", 
"Root\CIMv2:Win32_OperatingSystem" )
   ELSE
      objWMIService := GetObject( 
"WinMgmts:\\localhost\Root\CIMV2:Win32_OperatingSystem" )
   ENDIF

 it work unter WinXP, but fail on VISTA / W2K3
   iMax           := objWMIService:Properties_:count        Properties_ 
not unter VISTA / W2K3 ?
   ? ":Win32_OperatingSystem:Properties_" ,iMax

   bCollBlock := { |oService,n| AADD(aItem,{ n,PADR(oService:Name,45," 
")} )}
   ComEvalCollection( objWMIService:Properties_ , bCollBlock )
   ? iMax := LEN(aItem)

   objWMIService  := GetObject("WinMgmts:\\"+strComputer+"\Root\CIMV2")
   colItems := objWMIService:ExecQuery("select * from 
Win32_OperatingSystem",,48)

   ComEvalCollection(colItems, { |oService,n| AADD(bItem,{ n,oService } )} )

   ? jMax := LEN(bItem)

   oProperty := bItem[jMax,2]

   FOR i := 1 TO iMax
      ? aItem[i,2],oProperty:&(TRIM(aItem[i,2]))
   NEXT

/***********************************************************************
  ? oProperty:BootDevice
  ? oProperty:BuildNumber
  ? oProperty:BuildType
  ? oProperty:Caption
  ? oProperty:CodeSet
  ? oProperty:CountryCode
  ? oProperty:CreationClassName
  ? oProperty:CSCreationClassName
  ? oProperty:CSDVersion
  ? oProperty:CSName
  ? oProperty:CurrentTimeZone
  ? oProperty:DataExecutionPrevention_32BitApplications
  ? oProperty:DataExecutionPrevention_Available
  ? oProperty:DataExecutionPrevention_Drivers
  ? oProperty:DataExecutionPrevention_SupportPolicy
  ? oProperty:Debug
  ? oProperty:Description
  ? oProperty:Distributed
  ? oProperty:EncryptionLevel
  ? oProperty:ForegroundApplicationBoost
  ? oProperty:FreePhysicalMemory
  ? oProperty:FreeSpaceInPagingFiles
  ? oProperty:FreeVirtualMemory
  ? oProperty:InstallDate
  ? oProperty:LargeSystemCache
  ? oProperty:LastBootUpTime
  ? oProperty:LocalDateTime
  ? oProperty:Locale
  ? oProperty:Manufacturer
  ? oProperty:MaxNumberOfProcesses
  ? oProperty:MaxProcessMemorySize
  ? oProperty:Name
  ? oProperty:NumberOfLicensedUsers
  ? oProperty:NumberOfProcesses
  ? oProperty:NumberOfUsers
  ? oProperty:Organization
  ? oProperty:OSLanguage
  ? oProperty:OSProductSuite
  ? oProperty:OSType
  ? oProperty:OtherTypeDescription
  ? oProperty:PlusProductID
  ? oProperty:PlusVersionNumber
  ? oProperty:Primary
  ? oProperty:ProductType
  ? oProperty:QuantumLength
  ? oProperty:QuantumType
  ? oProperty:RegisteredUser
  ? oProperty:SerialNumber
  ? oProperty:ServicePackMajorVersion
  ? oProperty:ServicePackMinorVersion
  ? oProperty:SizeStoredInPagingFiles
  ? oProperty:Status
  ? oProperty:SuiteMask
  ? oProperty:SystemDevice
  ? oProperty:SystemDirectory
  ? oProperty:SystemDrive
  ? oProperty:TotalSwapSpaceSize
  ? oProperty:TotalVirtualMemorySize
  ? oProperty:TotalVisibleMemorySize
  ? oProperty:Version
  ? oProperty:WindowsDirectory
***********************************************************************/
RETURN NIL

*** eof ***
i do not want to "hardcode" every Property so how to get Them under VISTA / 
W2K3 ?

greetungs by OHR
Jimmy
AUGE_OHRRe: WMI unter VISTA/W2K
on Sat, 20 Jun 2009 22:26:12 +0200
Note : WMI Service must run so look at Taskmanager for "wmiapsrv.exe", else 
goto Service and start WMI
AUGE_OHRRe: WMI unter VISTA/W2K
on Sat, 20 Jun 2009 22:47:43 +0200
forgot to say : same Code does not work with v331 "pure" under WinXP

(BUG ist before ComEvalCollection() so i just use a Dummy for it to link )
greetungs by OHR
Jimmy