Add regedits

This commit is contained in:
2025-10-14 19:02:40 +02:00
parent 35766a6988
commit 2cc7872274
3 changed files with 46 additions and 0 deletions

15
install_context_menu.reg Normal file
View File

@@ -0,0 +1,15 @@
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\AddToPath]
@="Add to PATH"
"Icon"="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
[HKEY_CLASSES_ROOT\Directory\shell\AddToPath\command]
@="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath]
@="Add to PATH"
"Icon"="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath\command]
@="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"

26
main.go
View File

@@ -10,6 +10,7 @@ import (
) )
func main() { func main() {
undo := flag.Bool("u", false, "Remove current directory from PATH")
flag.Parse() flag.Parse()
logger.InitFlag() logger.InitFlag()
@@ -45,6 +46,31 @@ func main() {
} }
} }
if *undo {
if !currentDirInPath {
logger.Info("Current directory is not in PATH")
return
}
// Remove current directory from PATH
var newDirs []string
for _, dir := range pathDirs {
if !strings.EqualFold(strings.TrimSpace(dir), currentDir) {
newDirs = append(newDirs, dir)
}
}
newPath := strings.Join(newDirs, ";")
err = key.SetStringValue("PATH", newPath)
if err != nil {
logger.Error("Failed to update PATH in registry: %v", err)
os.Exit(1)
}
logger.Info("Successfully removed current directory from PATH")
return
}
if currentDirInPath { if currentDirInPath {
logger.Info("Current directory is already in PATH") logger.Info("Current directory is already in PATH")
return return

View File

@@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\shell\AddToPath]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath]