add windows support
This commit is contained in:
36
config_windows.go
Normal file
36
config_windows.go
Normal file
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func makeLink(src, dst string) error {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
err := ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED|ole.COINIT_SPEED_OVER_MEMORY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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")
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user