Folder permissions in .NET

H

hiram

I have a folder on a local machine that has the access security
settings set in Windows so that only the administrator can perform
write or create operations on the folder. Everyone else is given read
only access to the folder.


I am trying to write a vb.net program that can create and modify files
and folders in the above mentioned folder. I am running into problems
with access permissions when I try to create a new sub-directory in the

folder because the users running the program do not have access to the
folder. I would like to give the vb.net program full and unrestricted
access to the folder without having to give the user that runs the
program the same access. Does anyone know how to do this in vb.net? I
can't have an administrator password box pop up in the program because
the users don't have the administrator password and I don't want them
to.
 
K

Ken Tucker [MVP]

Hi,

Have you tried impersonation?

http://www.dotnet247.com/247reference/msgs/28/144136.aspx


FileIOPermission
http://msdn.microsoft.com/library/d...nsFileIOPermissionAttributeClassctorTopic.asp


Ken
--------------

I have a folder on a local machine that has the access security
settings set in Windows so that only the administrator can perform
write or create operations on the folder. Everyone else is given read
only access to the folder.


I am trying to write a vb.net program that can create and modify files
and folders in the above mentioned folder. I am running into problems
with access permissions when I try to create a new sub-directory in the

folder because the users running the program do not have access to the
folder. I would like to give the vb.net program full and unrestricted
access to the folder without having to give the user that runs the
program the same access. Does anyone know how to do this in vb.net? I
can't have an administrator password box pop up in the program because
the users don't have the administrator password and I don't want them
to.
 
C

Crouchie1998

Try this:

Imports System.Security.Permissions

Dim strPath As String = "C:\MyPath"
Dim strSubDirectory As String = IO.Path.Combine(strPath,
"MySubDirectory")

Dim fp As New FileIOPermission(FileIOPermissionAccess.AllAccess,
strPath)
fp.Assert()
IO.Directory.CreateDirectory(strSubDirectory)
fp.RevertAssert()
fp = Nothing

Add the Dim fp... behind a button...

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
 
H

hiram

This code did not work for this problem. I had found this code on msdn
before during my search. I am not exactly sure what the
FileIOPermissionAccess class does. I do know that it will not allow me
to access a directory that I don't already have permissions on.

Thanks for the suggestion.
 
C

Crouchie1998

Its always worked for me in the situation you described. Yes, of course
impersonating the administrator is used to, but in my experience I've seen
it used more in web applications rather than Windows progs.

Crouchie1998
BA (HONS) MCP MCSE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top