Access Denied while trying to delete file from python script

kyosohma at gmail.com kyosohma at gmail.com
Sat Jul 14 15:39:18 CEST 2007


On Jul 14, 3:39 am, "Viewer T." <dtgead... at yahoo.com> wrote:
> I am trying to write a script that deletes certain files based on
> certain criteria.
>
> What I am trying to do is to automate the process of deleting certain
> malware files that disguise themselves as system files and hidden
> files. When I use os.remove() after importing the os module is raises
> a Windows Error: Access denied probably because the files have
> disguised themselves as system files. Is there anway to get adequate
> privileges under windows to be able to delete system files from within
> a python script. I know it is probably a windows security feature but
> is there anyway to gain such privileges.

You'll need to use the PyWin32 package (AKA win32all). There's a
win32security module. These links might help:

http://mail.python.org/pipermail/python-list/2006-February/367441.html
http://www.thescripts.com/forum/thread28850.html
http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/pywin32/Windows_NT_Files_.2d.2d_Locking.html

Sometimes you can beat windows over the head using its own delete
commands:

os.system('DEL /F /S /Q "%s"' % item)
os.system(r'RD /S /Q "%s"' % item)

I know there's a cookbook recipe on it, but I can't seem to find it
right now. Hopefully this will help you some though.

Mike




More information about the Python-list mailing list