I am using the following code test.nim:
import winim/com
comScript:
const HIDDEN_WINDOW = 12
var strComputer = "."
var objWMIService = GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & r"\root\cimv2")
var objStartup = objWMIService.Get("Win32_ProcessStartup")
var objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
var objProcess = GetObject(r"winmgmts:root\cimv2:Win32_Process")
var errReturn = objProcess.Create("Notepad.exe", nil, objConfig, intProcessID)
nim c --run test.nim
D:\test\test.nim(8, 32) Error: invalid token: trailing underscore
How can I solve this problem.
I'm not on Windows and don't know what does this code do, but trailing underscores are invalid for identifiers. You can try using stropping:
import winim/com
comScript:
const HIDDEN_WINDOW = 12
var strComputer = "."
var objWMIService = GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & r"\root\cimv2")
var objStartup = objWMIService.Get("Win32_ProcessStartup")
var objConfig = objStartup.`SpawnInstance_`
objConfig.ShowWindow = HIDDEN_WINDOW
var objProcess = GetObject(r"winmgmts:root\cimv2:Win32_Process")
var errReturn = objProcess.Create("Notepad.exe", nil, objConfig, intProcessID)
The supported solution is to wrap the ffi class using valid Nim identifiers.
Something like proc SpawnInstance(obj:SWbemObject) {.importc:"SpawnInstance_".}
But I have no clue about winim or windows, even less what that comScript macro does, and this looks like something to file with the maintainer of winim