1,105,417 Community Members

Access to the path is denied.

Member Avatar
raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am trying to retrieve all the names of the mp3 files from my hard drive, heres the full code, what i am facing is "Access to the path 'D:\System Volume Information' is denied." error, but i have changed the manifest file as below

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>
 />

but still no luck any idea?

Heres the code

Dim filenames() As String = Directory.GetFiles(Cpath, "*.mp3", SearchOption.AllDirectories) 'this is where the D:\System Volume Information' is denied. error pops up
        Dim i As Integer
        Dim filename As String
        pgr1.Value += 2

        For i = 0 To filenames.Length - 1
            filename = Path.GetFileName(filenames(i))
            lst_cres.Items.Add(filename)
            pgr1.Value += 1
        Next i

        Label1.Text = "Total File Names : " & lst_cres.Items.Count
Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
1
 

Try changin your requestedExecutionLevel to level="requireAdministrator". Once your program runs as Admin it should be able to access everything. Or alter your code to check real file info is coming back from your getFiles().

Member Avatar
aldeene
Junior Poster in Training
71 posts since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

do you use Windows 7 OS?, I also encountered this problem previously, just run everything as an administrator will solve the problem

Member Avatar
raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have tried the code on a removable external hard disk with MP3 files the code works very good and as expected but when I try it on C drive and D drive it says Access Denied. I have changed requestedExecutionLevel to level="requireAdministrator too without any luck :( And yes i am using Vista and am running everything as admin

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
0
 

I have tried the code on a removable external hard disk with MP3 files the code works very good and as expected but when I try it on C drive and D drive it says Access Denied. I have changed requestedExecutionLevel to level="requireAdministrator too without any luck :( And yes i am using Vista and am running everything as admin

This is a system folder and by default it's security rights allow control only to SYSTEM account. You can either try to run your program as SYSTEM (ie part of OS) or go to the folder properties and change it's security rights to allow administrator to read the folder and it's contents.

If you choose to go with the security permissions and you can't find the folder to change the permissions you need to get to Folder Options (It's under Organize as Folder and Search Options), go to tab View and in the advanced settings list you'll find a checkbox named Hide protected operating system files (Recommended). Untick this checkbox and after the warning (Read it) you'll be able to see the folder in C: and D:

Member Avatar
aldeene
Junior Poster in Training
71 posts since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

usually when I encounter this problem, I run Visual Studio as administrator..

Member Avatar
raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This is a system folder and by default it's security rights allow control only to SYSTEM account. You can either try to run your program as SYSTEM (ie part of OS) or go to the folder properties and change it's security rights to allow administrator to read the folder and it's contents.

If you choose to go with the security permissions and you can't find the folder to change the permissions you need to get to Folder Options (It's under Organize as Folder and Search Options), go to tab View and in the advanced settings list you'll find a checkbox named Hide protected operating system files (Recommended). Untick this checkbox and after the warning (Read it) you'll be able to see the folder in C: and D:

could you please tell me what you mean by "ou can either try to run your program as SYSTEM" and i didn't quite get you concept yet because i am running VS as Admin and i don't know why access is denied

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
1
 

Not even admin has access to act as part of the OS. If you go to local policy settings, you can grand permission to user accounts to act as part of the OS. I've never had to use this, but here is an article on what is SYSTEM account and how to launch an app under it's account: http://www.tech-recipes.com/rx/1288/how-to-run-applications-in-the-local-system-account-lsa/

Hope this helps.

Member Avatar
raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Guys, I have found out that access denied popsup at certain folder like "C:\Windows\Debug\WIA" and "D:\System Volume Information",where it is not neccesary to browse those folders so I was thinking how i can skip looking into those folders using my code, so how can i modify this code in such a way that I can skip those access denied folders?

Dim fnm As String = ""
        Dim filenames() As String = Directory.GetFiles(Cpath, "*.mp3", SearchOption.AllDirectories)
        Dim filename As String
        Dim i As Integer
        For i = 0 To filenames.Length - 1
            filename = Path.GetFileName(filenames(i))
            itm_add(filename)
            setval(1)
        Next i

And by the way thanks for the infomation adam k :)

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
0
 

MSDN has a demonstration on how to go through all directories and get filenames here: http://msdn.microsoft.com/en-us/library/07wt70x2.aspx

Hopefully it will give you a hint.

barjoe
Newbie Poster
1 post since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

ahm... how can you open a text file from "D:\" i have tried this:

 Dim fs As FileStream
        Dim str As StreamReader
        Dim st As String
        'ofd.ShowDialog()
        fs = New FileStream(TextBox6.Text, FileMode.OpenOrCreate, FileAccess.Read)
        str = New StreamReader(fs)
        str.BaseStream.Seek(0, SeekOrigin.Begin)
        Do While str.Peek > -1
            TextBox5.Text = str.ReadToEnd
        Loop

but it keeps on saying that access to path is denied.

Member Avatar
Reverend Jim
Noli mentula
5,441 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

This thread is more than a year old. Please read the rules which talk about resurrecting or hijacking old threads. If you want an answer then please start a new thread.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article