"-Begin-----------------------------------------------------------------
Program zUseWMI.
"-Variables---------------------------------------------------------
Data:
VBSCode Type String,
WMI Type OLE2_OBJECT,
CompName Type String,
WMICmd Type String,
oWBEM Type OLE2_OBJECT,
Model Type String,
Manufacturer Type String,
TotalPhyMem Type String
.
"-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-------------------------------------------------------
"-Begin-----------------------------------------------------------------
REPORT ZGETSCREENRESOLUTION.
DATA:
ScriptCtrl TYPE OBJ_RECORD,
VBSCode TYPE String,
Result TYPE String
.
DEFINE _.
VBSCode = VBSCode && &1 && cl_abap_char_utilities=>cr_lf.
END-OF-DEFINITION.
_ 'Function GetScreenResolution()'.
_ ' Set oObj = GetObject("winmgmts:\\.\root\cimv2", "")'.
_ ' If IsObject(oObj) Then'.
_ ' Set colItems = oObj.ExecQuery("Select * from Win32_VideoController")'.
_ ' For Each oItem in colItems'.
_ ' Res = Res & oItem.CurrentHorizontalResolution & ":" & _'.
_ ' oItem.CurrentVerticalResolution & " / "'.
_ ' Next'.
_ ' GetScreenResolution = Res'.
_ ' End If'.
_ 'End Function'.
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
Check sy-subrc = 0 And ScriptCtrl-Handle <> 0 And ScriptCtrl-Type = 'OLE2'.
"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.
Call Method Of ScriptCtrl 'Eval' = Result Exporting #1 = 'GetScreenResolution()'.
Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
Free Object ScriptCtrl.
Write: / Result.
"-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |