472,958 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Access Denied while trying to delete file from python script

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.

Jul 14 '07 #1
2 9160
On Jul 14, 3:39 am, "Viewer T." <dtgead...@yahoo.comwrote:
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

Jul 14 '07 #2
ky******@gmail.com wrote:
On Jul 14, 3:39 am, "Viewer T." <dtgead...@yahoo.comwrote:
>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
Jul 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: calfdog | last post by:
Hello, Does anyone know a workaround for calling fireEvent. With the latest from Microsoft OS XP2 and Hot fixes to IE it now gives an "access denied" error in Python when called. Here is what...
1
by: paritycheck | last post by:
Hi Guys, I'm stuck with a terribly persistant "Access to the path *** is denied" problem. I'm trying to upload a foile using the file control. The code checks if a file of the same name as...
3
by: februs | last post by:
Was just trying a small script to load a file and while it works if I run it locally on my own pc if I try and access it on a remote web server it generates an error code 0: Access is denied in IE:...
6
by: ASP.Confused | last post by:
I have an ASP.NET page writtein in VB that uses ADODB. I just had to force-install MDAC 2.8 after I tried to rollback to 2.6 (my web host uses this, and I wanted to be compatible with them.) I...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
11
by: Alec Wysoker | last post by:
Using Python 2.3.5 on Windows XP, I occasionally get OSError: Permission denied when calling os.remove(). This can occur with a file that is not used by any other process on the machine, and is...
5
by: wo20051223 | last post by:
Deleting some files with C# fails with "Access to the path 'X' is denied". I have files copied from a CD that I burned (and not locked by a process) and a text file that I created in Windows...
0
by: Tim Golden | last post by:
aditya shukla wrote: Why on earth are you *specifying* c:\python25 as the directory for this file? It's automatically created in your user-specific temp directory which has specific permissions...
2
by: W. eWatson | last post by:
I had just finished working with IDLE, and tried to double-click on a py file. It produced an OK dialog with the path to the file and the msg "access denied." All my py files act that way. I...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.