|
|
@@ -0,0 +1,48 @@
|
|
|
+package win
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/jxeng/shortcut"
|
|
|
+ "io/ioutil"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+func CreateShortCut(softPath, shortcutName string) (err error) {
|
|
|
+ _, name1 := filepath.Split(softPath)
|
|
|
+ ext := filepath.Ext(name1)
|
|
|
+ filename := name1[:len(name1)-len(ext)]
|
|
|
+ startUpFlag := false
|
|
|
+ userHomeDir, _ := os.UserConfigDir()
|
|
|
+ startUpList := []string{
|
|
|
+ fmt.Sprintf(`%s\Microsoft\Windows\Start Menu\Programs\Startup`, userHomeDir),
|
|
|
+ `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp`,
|
|
|
+ }
|
|
|
+ for _, startUp := range startUpList {
|
|
|
+ handles, _ := ioutil.ReadDir(startUp)
|
|
|
+ for _, handle := range handles {
|
|
|
+ if handle.IsDir() {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if strings.Contains(handle.Name(), filename) == true && strings.Contains(handle.Name(), ".lnk") == true {
|
|
|
+ startUpFlag = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if startUpFlag == false {
|
|
|
+ workingDirectory, _ := filepath.Split(softPath)
|
|
|
+ sc := shortcut.Shortcut{
|
|
|
+ ShortcutPath: fmt.Sprintf(`%s\%s.lnk`, startUpList[0], shortcutName),
|
|
|
+ Target: softPath,
|
|
|
+ IconLocation: "%SystemRoot%\\System32\\SHELL32.dll,17",
|
|
|
+ Arguments: "",
|
|
|
+ Description: "",
|
|
|
+ Hotkey: "",
|
|
|
+ WindowStyle: "1",
|
|
|
+ WorkingDirectory: workingDirectory,
|
|
|
+ }
|
|
|
+ err = shortcut.Create(sc)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|