Visual Basic .NET Access to the path 'C:\' is denied
Dim UserAccount As String = "<user here>" 'Specify the user here
Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo("path")
Dim FolderAcl As New DirectorySecurity
FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
FolderAcl.SetAccessRuleProtection(False, False)
FolderInfo.SetAccessControl(FolderAcl)
Note you have to add: Imports.System.Security.AccessControl
By the way I got it from here: Give folder full access when created so credit goes to that person. (Jacques Bronkhorst) Hope this solves the issue :)
Bob Ma
Updated on June 04, 2022Comments
-
Bob Ma almost 2 years
I am using Visual Studio 2012 and Visual Basic .NET to build the application (with Windows 7)
I currently build the install package and i install to another pc to test program.
When I was creating txt file by my app, i was getting "Access to the path 'C:\' is denied" error
I know that I was using sub account to run my application.
If I run as administrator, it is was working fine. However, the program should be able to run application without using administrator account .
These are what I tried to solve this problem so far.
First, I change the location to write file in "Program file folder" such as "C:\Program file\My App"
However, it didn't work
Second, I was trying to change
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
to
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
at app.config
However, After I replaced to "requireAdministrator" , I am getting compiling error
ClickOnce does not support the request execution level 'requireAdministrator'. WindowsApplication2
Third, I went to Computer->manager->service-> and Enable Application experience.
However, it does not work.
I am not really sure what to do for this problem.
Does anybody know any solution ?
thanks