Hello community,
Windows Management Instrumentation (WMI) is a powerful interface to the operating system, you can find more information here..
Here a report how to use the WMI inside ABAP:
"-Begin-----------------------------------------------------------------
Program zUseWMI.
"-Type pools--------------------------------------------------------
Type-Pools OLE2.
"-Variables---------------------------------------------------------
Data VBSCode Type String Value ''.
Data WMI Type OLE2_OBJECT.
Data CompName Type String Value ''.
Data WMICmd Type String Value ''.
Data oWBEM Type OLE2_OBJECT.
Data Model Type String Value ''.
Data Manufacturer Type String Value ''.
Data TotalPhyMem Type String Value ''.
"-Macros------------------------------------------------------------
Define _.
Concatenate VBSCode &1 cl_abap_char_utilities=>cr_lf
Into VBSCode.
End-Of-Definition.
"-Main--------------------------------------------------------------
PerForm GetWMIObj Changing WMI.
If WMI-Handle <> 0 And WMI-Type = 'OLE2'.
"-Now you can use the Windows Management Instrumentation (WMI)--
PerForm GetComputerName Changing CompName.
Concatenate 'Win32_ComputerSystem=''' CompName ''''
Into WMICmd.
Call Method Of WMI 'Get' = oWBEM Exporting #1 = WMICmd.
Get Property Of oWBEM 'Model' = Model.
Get Property Of oWBEM 'Manufacturer' = Manufacturer.
Get Property Of oWBEM 'TotalPhysicalMemory' = TotalPhyMem.
Write: / Model.
Write: / Manufacturer.
Write: / TotalPhyMem.
"---------------------------------------------------------------
Free Object WMI.
EndIf.
"-End-------------------------------------------------------------------
"-SubRoutines begin-----------------------------------------------------
"-RunScript-----------------------------------------------------------
Form RunScript Using Cmd Type String Changing Result Type Any.
"-Variables-------------------------------------------------------
Data ScriptCtrl Type OBJ_RECORD.
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
If sy-subrc = 0.
Set Property Of ScriptCtrl 'AllowUI' = 1.
Set Property Of ScriptCtrl 'Language' = 'VBScript'.
Call Method Of ScriptCtrl 'AddCode' Exporting #1 = VBSCode.
Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
If sy-subrc = 0.
Call Method Of ScriptCtrl 'Eval' = Result Exporting #1 = Cmd.
Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
EndIf.
EndIf.
Free Object ScriptCtrl.
EndForm.
"-GetWMIObj-----------------------------------------------------------
Form GetWMIObj Changing Result Type OBJ_RECORD.
Clear VBSCode.
_ 'Function GetWMIObj()'.
_ ' Dim oObj'.
_ ' Set oObj = GetObject("winmgmts:", "")'.
_ ' If IsObject(oObj) Then'.
_ ' Set GetWMIObj = oObj'.
_ ' End If'.
_ 'End Function'.
PerForm RunScript Using 'GetWMIObj()' Changing Result.
EndForm.
"-GetComputerName-----------------------------------------------------
Form GetComputerName Changing Result Type String.
Clear VBSCode.
_ 'Function GetComputerName()'.
_ ' Set oWSN = CreateObject("WScript.Network")'.
_ ' If IsObject(oWSN) Then'.
_ ' GetComputerName = oWSN.ComputerName'.
_ ' Set oWSN = Nothing'.
_ ' End If'.
_ 'End Function'.
PerForm RunScript Using 'GetComputerName()' Changing Result.
EndForm.
"-Subroutines end-------------------------------------------------------
The form routine GetWMIObj delivers the OLE object of the WMI and GetComputerName delivers the name of the computer. Both routines works with VBScript in the routine RunScript. The Main routine uses three methods of the Win32_ComputerSystem class: Model, Manufacturer and TotalPhysicalMemory and writes this Information on the screen.
The WMI offers thousands of classes, e.g. about BIOS, Boot configuration, printers, network, installed software etc. etc. etc.
Cheers
Stefan