Could not find a part of the path and access denied

I have 2 problems which I think are related and need some help with.  I am writing a small program to clean some temp directories.

1) I get the following error when I run this code anywhere in my program
System.IO.Directory.GetFiles("C:\Users\xxx\AppData\Local\Microsoft\Windows\Temporary Internet Files\")

DirectoryNotFoundException was unhandled
Could not find a part of the path 'C:\Users\xxx\AppData\Local\Local\Microsoft\Windows\Temporary Internet Files'.

Basically I am trying to clean the temporary internet files folder.  I am assuming that because it is a hidden folder the program cannot see it.

2) My program is getting the following error when attempting to delete the files
Access to the path 'C:\Users\xxx\AppData\Local\Temp\test.txt' is denied.

Wierd thing is that 98% of the files in this directory it will delete but has a problem with a few. (It is not because they are in use).  The current user can manual delete this file with no problems but the program cannot.  It seems as though it is a permission problem but I am not sure why.  I have tried adding everyone with full control to the file and the file still cannot be deleted. I am currently running on vista.

Thanks for the help.
LVL 1
inimicaljordsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BraidenGCommented:
Hi Jordan,

I would think a better way to do that would to instead of hard-coding the Directory, get the current user directory, then work from there.

Or else you could just run the program as an Administrator. If not it may be the fact that it is a hidden folder, or the program is open, either of those.

Hope that helps

Braiden
0
inimicaljordsAuthor Commented:
hard coding or using environment variables didn't change anything.  Same result.

I know cleaning temp internet files for a user can be done from that user account and not the administrator.  I have used many programs that can accomplish this.  I just can't figure out why the program cannot see the folder but the user can.
0
gisTimmyCommented:
Try this to get the path (VB.NET 2005):

System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)

See if this gives you a different path than the ones you tried or the environment variables you had.
 
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

inimicaljordsAuthor Commented:
ok guys, i haven't abandon this question but have been extremely busy.  I tried the internet cache and it doesn't give me the error anymore so it sees that directory but it doesn't see any directories in it.

FYI this is coding for Vista:

When I run this it scans:
C:\Users\xxx\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low\Content.IE5\

which on my current machine I have 4 folders with random names like 5REDNR1R
The program cannot see the 5REDNR1R folder now.  If I hard code it like this:
            For Each d In Directory.GetDirectories(internetTemp & "\Low\Content.IE5\5REDNR1R\")
I get the same error as before, path cannot be found

Any clues?

Dim internetTemp As String = System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)            
Dim s, d As String
            
For Each s In System.IO.Directory.GetFiles(internetTemp & "\Low\Content.IE5\")
                Try
                    MsgBox(s)
                    fcount += FileLen(s)
                    System.IO.File.Delete(s)
                Catch ex As Exception
                    fcount -= FileLen(s)
                    WriteToErrorLog(ex.Message)
                End Try
            Next s
            For Each d In Directory.GetDirectories(internetTemp & "\Low\Content.IE5\")
                Try
                    MsgBox(d)
                    System.IO.Directory.Delete(d, True)
                Catch ex As Exception
                    WriteToErrorLog(ex.Message)
                End Try
            Next d

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
inimicaljordsAuthor Commented:
no solution found
0
gisTimmyCommented:
inimicaljords,  Thanks for the points. I don't have any experience with Vista security yet, but FWIW, have you seen these links about the internet cache in Vista and IE protected mode?  

Code Project - A Developer's Survival Guide to IE Protected Mode
This one is in C++, but informative to me:
http://www.codeproject.com/KB/vista-security/PMSurvivalGuide.aspx   

IEBlog - Protected Mode in Vista IE7
http://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx

MSDN
Understanding and Working in Protected Mode Internet Explorer
http://msdn.microsoft.com/en-us/library/bb250462.aspx

Best o' luck,

gisTimmy
0
BraidenGCommented:
Change your Programs app.manifest file to look something like the code snippet. Change your project settings to compile a user created/modified Manifest, this will request Admin Rights before running.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
                <security>
                        <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                                
                                <requestedExecutionLevel level="requireAdministrator"/>
                        </requestedPrivileges>
                </security>
        </trustInfo>
</assembly>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.