从下面的问题中,我能够弄清楚如何检查它是否可以在兼容 posix 的文件系统上运行。
How to check if a file is executable in go?
但是,我认为这不适用于 Windows。有什么好办法吗?
最佳答案
我见过四种方法:
AccessCheck
基于此评论:
Windows has
AccessCheck
with which you can check forFILE_GENERIC_EXECUTE
access. First you have to callOpenThreadToken
(or, if that fails,OpenProcessToken
andDuplicateToken
) to get an impersonation token andGetNamedSecurityInfoW
to get the file security (owner, label, attribute, and DACL).
我找到了一个带有函数 UserHasPermission 的 Go 包.我认为这是执行此操作的正确方法。
GetBinaryTypeW
由 PHP 使用和 Rust .这将检查文件是否为可执行文件 类型 , 但
检查可执行文件 权限 .
GetFileAttributesW
由 Go 使用和 Python和 Nim .这里的逻辑是所有文件都是可读的
可执行文件,并且仅区分文件是否可写。
GetFileInformationByHandle
由 Ruby 使用.这里的逻辑是所有文件都是可读可执行的,并且只有
区分文件是否可写。
关于windows - 如何使用golang检查文件在Windows上是否可执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63911706/