github.com/himawarisunflower/go-update@v0.0.0-20210917073417-3bee296db6a2/hide_windows.go (about)

     1  package update
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  )
     7  
     8  func hideFile(path string) error {
     9  	kernel32 := syscall.NewLazyDLL("kernel32.dll")
    10  	setFileAttributes := kernel32.NewProc("SetFileAttributesW")
    11  
    12  	r1, _, err := setFileAttributes.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))), 2)
    13  
    14  	if r1 == 0 {
    15  		return err
    16  	} else {
    17  		return nil
    18  	}
    19  }