davidm / luacom

Microsoft Component Object Model (COM) binding for Lua
http://lua-users.org/wiki/LuaCom
Other
116 stars 51 forks source link

luacom on WScript.Shell, always fails when input string parameter #27

Closed robertlzj closed 2 years ago

robertlzj commented 2 years ago
local luacom=require'luacom'
local shellObject=luacom.CreateObject("WScript.Shell")
local shortcut_file_path='C:\\test_shortcut.lnk'
local shortcut=shellObject.CreateShortcut(shortcut_file_path)
--  "The shortcut pathname must end with .lnk or .url""
shortcut.TargetPath='target_file_path'
shortcut.Save()

I tried UTF8/UTF16LE/UTF16BE/ANSI encode of string shortcut_file_path (import string from encoded file then io.open), but still get the error. And "COM exception:(..\src\library\tLuaCOM.cpp,398):"

Equivalent in powerShell / vbscript (.vbs) works fine. shellObject.CreateShortcut see Create a desktop shortcut with Windows Script Host - Windows Client | Microsoft Docs

I tried other interface (method), like RegRead([[HKEY_LOCAL_MACHINE\SOFTWARE]]), get similar error on input argument. And retrieve string is EMPTY

local luacom=require'luacom'
    local shellObject=luacom.CreateObject("WScript.Shell")
    local result={pcall(shellObject.RegRead,[[HKEY_LOCAL_MACHINE\SOFTWARE]])}
    assert(result[1]==false and result[2]=='COM exception:(..\\src\\library\\tLuaCOM.cpp,398):registered \"\" root is invalid')

And, tried other COM object, "SAPI.SpVoice", method "Speak" using string parameter works fine. int SpeakStream(ISpeechBaseStream Stream, [Optional] SpeechVoiceSpeakFlags Flags);

robertlzj commented 2 years ago

My fault! should use shellObject:RegRead 😒

Should prompt self parameter error, I think. And there is "self parameter not found" on shortcut.Save().