How do I determine if a service pack has been installed on a computer?
Use the Win32_OperatingSystem class and check the value of the ServicePackMajorVersion and ServicePackMinorVersion properties.
const wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', ''); FWbemObjectSet:= FWMIService.ExecQuery('SELECT ServicePackMajorVersion,ServicePackMinorVersion FROM Win32_OperatingSystem','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; if oEnum.Next(1, FWbemObject, iValue) = 0 then begin Writeln(Format('ServicePack %d.%d',[Integer(FWbemObject.ServicePackMajorVersion),Integer(FWbemObject.ServicePackMinorVersion)])); FWbemObject:=Unassigned; end; end;
How do I determine when the operating system was installed on a computer?
Use the Win32_OperatingSystem class and the InstallDate property.
const wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; FWbemDateObj : OleVariant; Dt : TDateTime; begin; FWbemDateObj := CreateOleObject('WbemScripting.SWbemDateTime'); FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', ''); FWbemObjectSet:= FWMIService.ExecQuery('SELECT InstallDate FROM Win32_OperatingSystem','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; if oEnum.Next(1, FWbemObject, iValue) = 0 then begin FWbemDateObj.Value:=FWbemObject.InstallDate; Dt:=FWbemDateObj.GetVarDate; Writeln(Format('InstallDate %s',[FormatDateTime('dd mmm yyyy',dt)])); FWbemObject:=Unassigned; end; end;
How do I determine which version of the Windows operating system is installed on a computer?
Use the Win32_OperatingSystem class, and retrieve both the Name and Version properties.
const wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', ''); FWbemObjectSet:= FWMIService.ExecQuery('SELECT Name, Version FROM Win32_OperatingSystem','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; if oEnum.Next(1, FWbemObject, iValue) = 0 then begin Writeln(Format('%s %s',[String(FWbemObject.Name),String(FWbemObject.Version)])); FWbemObject:=Unassigned; end; end;
How do I determine which folder is the Windows folder (%Windir%) on a computer?
Use the Win32_OperatingSystem class, and check the value of the WindowsDirectory property.
const wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', ''); FWbemObjectSet:= FWMIService.ExecQuery('SELECT WindowsDirectory FROM Win32_OperatingSystem','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; if oEnum.Next(1, FWbemObject, iValue) = 0 then begin Writeln(Format('Windows Path %s',[String(FWbemObject.WindowsDirectory)])); FWbemObject:=Unassigned; end; end;
How do I determine what hotfixes have been installed on a computer?
Use the Win32_QuickFixEngineering class. for more samples about this topic check this article search for installed windows updates using Delphi, WMI and WUA
const wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', ''); FWbemObjectSet:= FWMIService.ExecQuery('SELECT Description,HotFixID FROM Win32_QuickFixEngineering','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; while oEnum.Next(1, FWbemObject, iValue) = 0 do begin Writeln(Format('HotFix %s',[String(FWbemObject.HotFixID)])); Writeln(Format('Description %s',[String(FWbemObject.Description)])); FWbemObject:=Unassigned; end; end;
This entry is based in the MSDN article WMI Tasks: Operating Systems
November 4, 2011 at 6:55 am
more of this!!!
November 4, 2011 at 9:43 pm
Excelentes tips. Le has dado duro al WMI demostrando lo poderoso de esta herramienta, por ello estoy muy agradecido y de paso consultar si es posible determinar otras cosas como pro ejemplo, que versión de .NET y/o actualizaciones (parches) de Windows están instaladas.
Gracias por todos tus aportes.
November 4, 2011 at 10:00 pm
Gracias por tu comentarios, sobre tu consulta. para determinar las actualizaciones de winsows instaladas revisa este link https://theroadtodelphi.wordpress.com/2011/03/02/search-for-installed-windows-updates-using-delphi-wmi-and-wua/ y sobre la version de .Net instalada debes revisar el registro de windows http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed, si deseas leer el registro de windows en forma remota aqui tienes un par de respuestas que di hace un tiempo atras en StackOverflow http://stackoverflow.com/questions/5972352/is-it-possible-to-read-write-the-registry-of-a-remote-machine-with-different-cre