Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Access Denied while trying to delete file from python script

Reply
Thread Tools

Access Denied while trying to delete file from python script

 
 
Viewer T.
Guest
Posts: n/a
 
      07-14-2007
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.

 
Reply With Quote
 
 
 
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      07-14-2007
On Jul 14, 3:39 am, "Viewer T." <(E-Mail Removed)> 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/pyt...ry/367441.html
http://www.thescripts.com/forum/thread28850.html
http://aspn.activestate.com/ASPN/doc...d_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

 
Reply With Quote
 
 
 
 
Jay Loden
Guest
Posts: n/a
 
      07-14-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Jul 14, 3:39 am, "Viewer T." <(E-Mail Removed)> 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/pyt...ry/367441.html
> http://www.thescripts.com/forum/thread28850.html
> http://aspn.activestate.com/ASPN/doc...d_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.


I think what you want is this one:
http://aspn.activestate.com/ASPN/Coo.../Recipe/303343

I wrote/maintain an Win32 antivirus tool written in C and it uses the same Win32 functions to unset any hidden/system attributes on files before attempting to delete them. In the same vein, you'll find that some files are locked and unable to be deleted, so you're probably want to look into the following also:

* killing processes to remove currently running files
http://www.answermysearches.com/how-...-in-python/57/

* scheduling files for removal on reboot using MoveFileEx
(you'd have to use win32 extensions to access the MoveFileEx function)
http://msdn2.microsoft.com/En-US/library/aa365240.aspx

Hope that helps,

-Jay
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Denied errors when trying delete a WIndows XP folder farseer Computer Support 1 02-11-2007 06:36 PM
Pernisssion denied when trying to delete or mv file Carl Graff Ruby 0 10-13-2006 02:52 PM
403 Forbidden: You were denied access because: Access denied by access control list Southern Kiwi NZ Computing 6 03-19-2006 05:19 AM
Access to the path is denied - trying to write a file =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= ASP .Net 3 12-16-2005 06:30 AM
Access denied while trying QI on a DCOM object Craig Lee ASP .Net Security 1 02-28-2004 01:37 AM



Advertisments