This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calling javascript methods on variants creates temporary variant arrays for passing parameters. | |
// To avoid access violations after freeing the runtime, make sure all your code using Variants gets out of scope first. | |
procedure Test(Context: TChakraCoreContext); | |
var | |
Global, Json, MyObj: Variant; | |
begin | |
// assign javascript Global to a Variant | |
Global := JsValueToVariant(Context.Global); | |
// read its (JSON) property and assign it to another Variant | |
Json := Global.JSON; | |
// call its method, assign result to another Variant | |
MyObj := Json.parse('{ "name": "world" }'); | |
// access property | |
Writeln(Format('Hello, %s!', [MyObj.name])); | |
// call another method | |
Writeln(Json.stringify(MyObj)); | |
end; | |
procedure Main; | |
var | |
Runtime: TChakraCoreRuntime; | |
Context: TChakraCoreContext; | |
begin | |
Runtime := nil; | |
Context := nil; | |
try | |
Runtime := TChakraCoreRuntime.Create; | |
Context := TChakraCoreContext.Create(Runtime); | |
Context.Activate; | |
Test(Context); | |
finally | |
Context.Free; | |
Runtime.Free; | |
end; | |
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ask host to create an Automation object instance | |
let locator = createOleObject('WbemScripting.SWbemLocator'); | |
const computerName = '.'; | |
const namespace = ''; | |
const userName = ''; | |
const password = ''; | |
// use it (access its properties and methods) from Javascript | |
let service = locator.ConnectServer(computerName, namespace, userName, password); | |
const className = 'Win32_OperatingSystem'; | |
console.log(`***** InstancesOf('${className}') *****`); | |
let items = service.InstancesOf(className); | |
items.forEach((item, i) => { | |
if (i > 0) { | |
console.log(''); | |
} | |
item.Properties_.forEach((p) => { | |
console.log(`${p.Name}: ${item[p.Name]}`); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
***** InstancesOf('Win32_OperatingSystem') ***** | |
BootDevice: \Device\HarddiskVolume1 | |
BuildNumber: 19041 | |
BuildType: Multiprocessor Free | |
Caption: Microsoft Windows 10 Pro | |
CodeSet: 1252 | |
CountryCode: 1 | |
CreationClassName: Win32_OperatingSystem | |
CSCreationClassName: Win32_ComputerSystem | |
CSDVersion: null | |
CSName: TLEILAX | |
CurrentTimeZone: 60 | |
DataExecutionPrevention_32BitApplications: true | |
DataExecutionPrevention_Available: true | |
DataExecutionPrevention_Drivers: true | |
DataExecutionPrevention_SupportPolicy: 2 | |
Debug: false | |
Description: | |
Distributed: false | |
EncryptionLevel: 256 | |
ForegroundApplicationBoost: 2 | |
FreePhysicalMemory: 11170572 | |
FreeSpaceInPagingFiles: 2451164 | |
FreeVirtualMemory: 13871392 | |
InstallDate: 20200610091003.000000+060 | |
LargeSystemCache: null | |
LastBootUpTime: 20201030112159.586692+060 | |
LocalDateTime: 20201030143957.032000+060 | |
Locale: 0409 | |
Manufacturer: Microsoft Corporation | |
MaxNumberOfProcesses: -1 | |
MaxProcessMemorySize: 137438953344 | |
MUILanguages: en-US,de-DE,en-GB | |
Name: Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk0\Partition2 | |
NumberOfLicensedUsers: null | |
NumberOfProcesses: 171 | |
NumberOfUsers: 2 | |
OperatingSystemSKU: 48 | |
Organization: | |
OSArchitecture: 64-bit | |
OSLanguage: 1033 | |
OSProductSuite: 256 | |
OSType: 18 | |
OtherTypeDescription: null | |
PAEEnabled: null | |
PlusProductID: null | |
PlusVersionNumber: null | |
PortableOperatingSystem: false | |
Primary: true | |
ProductType: 1 | |
RegisteredUser: ??????? | |
SerialNumber: ?????-?????-?????-????? | |
ServicePackMajorVersion: 0 | |
ServicePackMinorVersion: 0 | |
SizeStoredInPagingFiles: 2490368 | |
Status: OK | |
SuiteMask: 272 | |
SystemDevice: \Device\HarddiskVolume2 | |
SystemDirectory: C:\WINDOWS\system32 | |
SystemDrive: C: | |
TotalSwapSpaceSize: null | |
TotalVirtualMemorySize: 19267124 | |
TotalVisibleMemorySize: 16776756 | |
Version: 10.0.19041 | |
WindowsDirectory: C:\WINDOWS |