Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would os.path.exists("C:\\windows\\system32\\inetsrv\\metaback") return False even when it exists?

I've got a python program which is supposed to clean up a number of directories and one of them is C:\windows\system32\inetsrv\metaback; however, os.path.exists() returns False on that directory even though it exists (and I have permissions to access it).

What's interesting also is that the tool windirstat completely misses it as well.

Can anyone think of a reason why this might be and what's another way I could check to see if it exist? I can't even seem to run os.listdir() on it.

Update: os.path.exists() works on this directory if the Windows box is 32-bit, but not if it is 64-bit. Also shows up properly in windirstat on a 32-bit box.

like image 352
Jeff Avatar asked Feb 06 '11 04:02

Jeff


2 Answers

This is redirection of system folders at work. When a 32-bit process is running on a 64-bit version of Windows and uses the path %WINDIR%\System32, Windows substitutes %WINDIR%\SysWow64.

The function is returning false to tell you that C:\windows\syswow64\inetsrv\metaback does not exist, and it most likely is absolutely correct.

Try instead:

os.path.exists("C:\\windows\\sysnative\\inetsrv\\metaback")
like image 121
Ben Voigt Avatar answered Nov 19 '22 20:11

Ben Voigt


Windows x64 security is quite a bit tighter than windows x86; especially under the current release OSes (7, 2008).

Sounds like your script doesn't actually have the permissions it needs to run. Generally speaking MS locked down quite a few directory paths (like c:\inetpub) which require elevated priviledges in order to perform any actions.

There are huge reasons for this and it's generally considered a very good thing.

I believe you'll want to mark your script (or whatever executes it) as "Run as administrator" in order to give it the elevated control. Of course, this may require you to confirm execution via the UAC.

For further information, go to serverfault.com and ask there.

like image 1
NotMe Avatar answered Nov 19 '22 22:11

NotMe