windows - 如何使用golang检查文件在Windows上是否可执行?

标签 windows go

从下面的问题中,我能够弄清楚如何检查它是否可以在兼容 posix 的文件系统上运行。
How to check if a file is executable in go?
但是,我认为这不适用于 Windows。有什么好办法吗?

最佳答案

我见过四种方法:
AccessCheck
基于此评论:

Windows has AccessCheck with which you can check for FILE_GENERIC_EXECUTE access. First you have to call OpenThreadToken (or, if that fails, OpenProcessToken and DuplicateToken) to get an impersonation token and GetNamedSecurityInfoW to get the file security (owner, label, attribute, and DACL).


我找到了一个带有函数 UserHasPermission 的 Go 包.我认为这是执行此操作的正确方法。
GetBinaryTypeW
PHP 使用和 Rust .这将检查文件是否为可执行文件 类型 , 但
检查可执行文件 权限 .
GetFileAttributesW
Go 使用和 PythonNim .这里的逻辑是所有文件都是可读的
可执行文件,并且仅区分文件是否可写。
GetFileInformationByHandle
Ruby 使用.这里的逻辑是所有文件都是可读可执行的,并且只有
区分文件是否可写。

关于windows - 如何使用golang检查文件在Windows上是否可执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63911706/

相关文章:

c++ - 如何将路径作为参数传递给 vc++ 中的第二个应用程序?

go - 解码 json 错误,即使提供了匹配的数据结构

node.js - 如何在 Travis-CI 中运行 Go 服务器?

go - 使用 for 范围内的 goroutine 运行范围

http - golang 获取大量读取 tcp ip :port i/o timeout in ubuntu 14. 04 LTS

c++ - Winpcap 开发人员在 Cygwin C++ 和 Netbeans IDE 中的使用

windows - 比较和排序 Unicode 文件名

windows - dll 中的导出是否区分大小写?

python - queue.Queue 上的多路复用?

c++ - 在 MessageBox husing 句柄中显示 dll 的路径