Ale*_*ues 1 windows go desktop-shortcut
我想在Golang中为桌面和startmenu创建Windows快捷方式(.lnk)。
实际上,我是通过gowin模块获得Desktop&Startmenu文件夹的,我想为这些位置创建一个快捷方式。
我进行了搜索,但没有找到任何golang项目。我应该创建它吗?还有其他漂亮的方法吗?
使用https://github.com/go-ole/go-ole:
ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED|ole.COINIT_SPEED_OVER_MEMORY)
oleShellObject, err := oleutil.CreateObject("WScript.Shell")
if err != nil {
return err
}
defer oleShellObject.Release()
wshell, err := oleShellObject.QueryInterface(ole.IID_IDispatch)
if err != nil {
return err
}
defer wshell.Release()
cs, err := oleutil.CallMethod(wshell, "CreateShortcut", dst)
if err != nil {
return err
}
idispatch := cs.ToIDispatch()
oleutil.PutProperty(idispatch, "TargetPath", src)
oleutil.CallMethod(idispatch, "Save")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2116 次 |
| 最近记录: |