[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to detect if a file is executable on Windows?

On 2019-02-19, MRAB <python at mrabarnett.plus.com> wrote:
> On 2019-02-19 18:31, Grant Edwards wrote:
>> FWIW, I've noticed that afer downloading a .exe under Linux and
>> scp'ing the file to a Windows machine, it wont run when double-clicked
>> until I fire up a Cygwin shell and do a
>>     chmod +x <whatever>.exe
>> [I assume there's native Windows point-and-grunt means for doing that
>> as well.]
>> So, in addition to the suffix and associations, there's some sort of
>> file-system meta-data that determines whether a file is "executable"
>> in some contexts.
> I've never heard of a Windows equivalent of "chmod +x".

Modern Windows filesystems have a complex set of file-level access
control mechanisms.

> If I copy the contents of a .exe into a new file and give it a .exe
> extension, it just works.

I assume that what I see is a side-effect of the fact that the sshd in
question is a Cygwin app, and it is creating files w/o the Posix "x"
mode bits set.  In the Cygwin libraries, the Posix permission bits for
a directory entry get translated into the Windows ACLs for each file:


Grant Edwards               grant.b.edwards        Yow! BARBARA STANWYCK makes
                                  at               me nervous!!