Twitter github

Tales from the Crypt

Sometimes, while browsing source code, you come across things that make you think twice. While working on an enhancement recently, I came across this snippet:

public static boolean canWrite(File installDir) {
if (installDir.canWrite() == false)
return false;

if (!installDir.isDirectory())
return false;

File fileTest = null;
try {
// we use the .dll suffix to properly test on Vista virtual directories
// on Vista you are not allowed to write executable files on virtual directories like "Program Files"
fileTest = File.createTempFile("writtableArea", ".dll", installDir); //$NON-NLS-1$ //$NON-NLS-2$
} catch (IOException e) {
//If an exception occured while trying to create the file, it means that it is not writtable
return false;
} finally {
if (fileTest != null)
return true;

It seems Vista has a really stupid problem in regards to writing executable files. I was aware of the new virtual directory madness in Vista, I didn’t know of this particular workaround. I guess you learn something new everyday 😉