469,315 Members | 2,130 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Folder permissions in .NET

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.

Nov 21 '05 #1
5 26855
Hi,

Have you tried impersonation?

http://www.dotnet247.com/247referenc...28/144136.aspx
FileIOPermission
http://msdn.microsoft.com/library/de...sctorTopic.asp
Ken
--------------

"hiram" <oy*****@earthlink.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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.
Nov 21 '05 #2
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
Nov 21 '05 #3
Thanks Ken,
The impersonation code at www.dotnet247.com solved the problem.

Nov 21 '05 #4
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.

Nov 21 '05 #5
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
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andrew Crowe | last post: by
7 posts views Thread by Kim Lots | last post: by
reply views Thread by Srilatha | last post: by
4 posts views Thread by Richard | last post: by
reply views Thread by Tom C. | last post: by
4 posts views Thread by Joey | last post: by
2 posts views Thread by skinnybloke | last post: by
reply views Thread by Mark | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.