We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,548 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Access to the path is denied.

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
6
Contributors
11
Replies
1 Year
Discussion Span
3 Months Ago
Last Updated
22
Views
raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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().

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 10

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

aldeene
Junior Poster in Training
71 posts since Jul 2011
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 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

raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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:

adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11

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

aldeene
Junior Poster in Training
71 posts since Jul 2011
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 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

raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11

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 :)

raaif
Light Poster
39 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11

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.

barjoe
Newbie Poster
1 post since Feb 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

Reverend Jim
Illigitimae non carborundum
Moderator
3,737 posts since Aug 2010
Reputation Points: 585
Solved Threads: 469
Skill Endorsements: 33

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0918 seconds using 2.74MB