472,958 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

determine network directory permissions

Can anyone point me to code samples that can get the permission set
for a network drive? I tried the FileInfo and DirectoryInfo classes
but they do not seem to list what I need.

Feb 12 '07 #1
1 1645
Do you need to get the permissions for a share or do you need to get the ACLs
for a mapped network drive?

In the latter case you should be able to do it using
DirectoryInfo.GetAccessControl().

In the first case you can do it using WMI:

string machine = "MachineName";
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.EnablePrivileges = true;

ManagementScope scope = new ManagementScope("\\\\" + machine +
"\\root\\cimv2", co);
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM
Win32_LogicalShareSecuritySetting");

ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);

ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
string shareName = "\\\\" + machine + "\\" + m["Name"];
Console.WriteLine(shareName);

InvokeMethodOptions options = new InvokeMethodOptions();

ManagementBaseObject outParamsMthd =
m.InvokeMethod("GetSecurityDescriptor", null, options);
ManagementBaseObject descriptor =
outParamsMthd["Descriptor"] as ManagementBaseObject;

ManagementBaseObject[] dacl = descriptor["DACL"] as
ManagementBaseObject[];

foreach (ManagementBaseObject ace in dacl)
{
ManagementBaseObject trustee = ace["Trustee"] as
ManagementBaseObject;
string domain = (string) trustee["Domain"];
string name = (string)trustee["Name"];

Console.WriteLine(domain + "\\" + name);
}
}
HTH, Jakob.

--
http://www.dotninjas.dk

"The ants are driving me crazy" wrote:
Can anyone point me to code samples that can get the permission set
for a network drive? I tried the FileInfo and DirectoryInfo classes
but they do not seem to list what I need.

Feb 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stanley J, Mroczek | last post by:
My disk was replaced and i reload all my software. I think that i named my computer best-si-01 instead of BEST-SI-01 and thats my error? Login failed for user 'NT AUTHORITY\NETWORK SERVICE'....
1
by: brian.oneil2 | last post by:
Is there a way to install this onto a network file share and allow a team to access it? I would say share a CD from a networked CD drive, but there are multiple CD's that would have to be inserted....
2
by: Peter O'Reilly | last post by:
I am experiencing difficulty access a mapped network drive in an ASP.NET application. While using the .Net framework v 1.1 implementation of System.IO.Directory.Exists(), it fails to recognize a...
4
by: Kim Kragh | last post by:
Hi. I've tried to save, move files from asp.net (using the FileInfo object). It works fine locally, but I can't make it work on network drives. I have granted the aspnet user all required...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
5
by: Mitchell S. Honnert | last post by:
Is there a way, given the full path of a folder on a network, that one can programatically tell if you have Read access to that folder? I have an application where the user is able to select a...
2
by: Jerad Rose | last post by:
I have a fairly simple C# console app which copies files from a network folder to a local folder. When the app resides on my local C: drive, it runs just fine. However, when the app resides on a...
1
by: Raymond Du | last post by:
Hi, I try to use ASP.Net 2.0 FileUpload control to upload files. The page is working fine when I upload files and save them into my local computer, but fails when the files are to be saved to...
1
by: pxpilot | last post by:
HELP! I know there's a lot of urls out there, please don't reply with a link. I have tried them all but i guess i am missing something. I have 2 servers on the same network, my ASP.NET runs on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.