From the question below, I was able to figure out how to check if it can be run on a posix compatible file system.
How to check if a file is executable in go?
However, I don't think this works for Windows. Is there a good way?
I have seen four ways of doing this:
Based on this comment:
Windows has
AccessCheckwith which you can check forFILE_GENERIC_EXECUTEaccess. First you have to callOpenThreadToken(or, if that fails,OpenProcessTokenandDuplicateToken) to get an impersonation token andGetNamedSecurityInfoWto get the file security (owner, label, attribute, and DACL).
I found a Go package with the function UserHasPermission. I think this is the correct method to do this.
Used by PHP and Rust. This checks if a file if of executable type, but does check executable permission.
Used by Go and Python and Nim. The logic here is all files are readable and executable, and only differentiates on if a file is writable.
Used by Ruby. The logic here is all files are readable and executable, and only differentiates on if a file is writable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With