// ofcmgr project doc.go /* ofcmgr document */ package main import ( "github.com/golang/sys/windows/registry" "log" ) func registerOp(srcPath string) { key, exists, err := registry.CreateKey(registry.CLASSES_ROOT, "petrotool", registry.ALL_ACCESS) if err != nil { log.Println(err) log.Println("安装失败,请通过右键,以管理员的身份运行,重试安装!") return } defer key.Close() if exists { log.Println("键已存在") return } else { log.Println("新建注册表键") key.SetStringValue("", "dashooProtocol") key.SetStringValue("URL Protocol", srcPath) key1, _, _ := registry.CreateKey(registry.CLASSES_ROOT, "petrotool\\DefaultIcon", registry.ALL_ACCESS) key2, _, _ := registry.CreateKey(registry.CLASSES_ROOT, "petrotool\\shell\\open\\command", registry.ALL_ACCESS) key1.SetStringValue("", srcPath + ",1") key2.SetStringValue("", "\""+ srcPath +"\" \"%1\"") log.Println("安装成功") } }