I don't much about WMI. In theory Scripter can execute anything, it's just Dephi. Either you could some import DLL functions directly, if the parameter and result types are supported, or you can simply add Delphi wrappers to the API/DLL and then register those Delphi wrappers in scripter to be called from it.
Set objService = GetObject("winmgmts:root\cimv2")
Set objVolumes = objService.ExecQuery("Select * from Win32_Volume Where Name = 'C:\\'")
For Each objVolume In objVolumes
nError = objVolume.DefragAnalysis(bDefragRecommended, objDA)
If Not nError Then
Wscript.Echo objDA.FilePercentFragmentation & "% of files are fragmented."
If bDefragRecommended Then
Wscript.Echo "This volume should be defragged."
Else
Wscript.Echo "This volume does not need to be defragged."
End If
End If
Next
I'm not sure what is Wscript? Is this a COM object?
Locator := CreateOleObject('WbemScripting.SWbemLocator');
WMIService := Locator.ConnectServer('', 'root\CIMV2', '', '');
WMIService.ExecQuery ...
Scripter supports Basic syntax. That would be something like this:
DIM Locator
DIM WMIService
Locator = CreateOleObject("WbemScripting.SWbemLocator")
WMIService = Locator.ConnectServer("", "root\CIMV2", "", "")
WMIService.ExecQuery ...
DIM Locator
DIM WMIService
DIM Volume
DIM DeviceID
Locator = CreateOleObject("WbemScripting.SWbemLocator")
WMIService = Locator.ConnectServer("", "root\CIMV2", "", "")
Volume = WMIService.ExecQuery("SELECT * FROM Win32_Volume WHERE name='C'")
I can't test it as I don't know how to use WMI nor how to test it. But if ExecQuery returns a set, you should probably iterate through it:
Source: SWbemObjectSet
Description: Invalid query when evaluating instruction CallProc (SFFFFFFFF,SO,S1904C854,S3E237D70,'Count'). Stack content is: [(unknown),(unknown),(unknown)].
Source position: 11,27 Position: 11, 27.
Unfortunately not. You will have to find the documentation of SWbemObjectSet:
DIM Volume
DIM nError
Locator = CreateOleObject("WbemScripting.SWbemLocator")
WMIService = Locator.ConnectServer("", "root\CIMV2", "", "")
Volume = WMIService.ExecQuery("Select * from Win32_Volume WHERE Name='C:\\'")
showmessage("Caption: " & Volume.ItemIndex(0).Caption)
Hello Michael,
Wrap it in a Delphi function and register the Delphi function in the scripter.
Thank you. Will try that.