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

自古美人都是妖i 提交于 2019-12-22 04:11:20

问题


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.


回答1:


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")



回答2:


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.



来源:https://stackoverflow.com/questions/4911555/why-would-os-path-existsc-windows-system32-inetsrv-metaback-return-fals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!