473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

get share permissions

Hi,

how can I get the users or groups which are listed in the shared
permission of a shared folder?

Thanks,

Ralph

Jan 19 '07 #1
4 7550
Hi Jakob,

thanks again, for your code snippet. Unfortunately, this only works if
I want to check the permissions for the local machine (the one I'm
working on as an administrator).
But I have to solve the following problem:
I have a folder, where I want to store a file and have to check the
access rights. If it's a shared folder, I have to check the share
permissions for this folder, which is on a remote folder. In this
case, the scope.Connect method fails.
Can you help me again?

Thanks,

Ralph

On 22 Jan., 09:50, Jakob Christensen
<JakobChristen...@discussions.microsoft.comwrote :
Hi Ralph,

You can do this by using WMI. I wrote the following example for you. The
example lists all shares on a given computer including the users/groups that
are granted persmisssions to the shares. The "ace" object can also give you
information about the access rights (take a look at the Win32_ACE class of
WMI on MSDN).

string machine = "YourMachine";
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

"Ralph" wrote:
Hi,
how can I get the users or groups which are listed in the shared
permission of a shared folder?
Thanks,
Ralph- Zitierten Text ausblenden -- Zitierten Text anzeigen -
Jan 29 '07 #2
Hi Ralph,

Which error are you getting? Is it access denied?

Kind regards, Jakob.

--
http://www.dotninjas.dk

"Ralph" wrote:
Hi Jakob,

thanks again, for your code snippet. Unfortunately, this only works if
I want to check the permissions for the local machine (the one I'm
working on as an administrator).
But I have to solve the following problem:
I have a folder, where I want to store a file and have to check the
access rights. If it's a shared folder, I have to check the share
permissions for this folder, which is on a remote folder. In this
case, the scope.Connect method fails.
Can you help me again?

Thanks,

Ralph

On 22 Jan., 09:50, Jakob Christensen
<JakobChristen...@discussions.microsoft.comwrote :
Hi Ralph,

You can do this by using WMI. I wrote the following example for you. The
example lists all shares on a given computer including the users/groups that
are granted persmisssions to the shares. The "ace" object can also give you
information about the access rights (take a look at the Win32_ACE class of
WMI on MSDN).

string machine = "YourMachine";
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

"Ralph" wrote:
Hi,
how can I get the users or groups which are listed in the shared
permission of a shared folder?
Thanks,
Ralph- Zitierten Text ausblenden -- Zitierten Text anzeigen -

Jan 30 '07 #3
Yes, I get an UnauthorizedAccessException. Unfortunately I don't have
any influence on the remote computer in the network in my project. I
just get a shared folder, and I have to check the permissions I have
for this folder.

On 30 Jan., 03:26, Jakob Christensen
<JakobChristen...@discussions.microsoft.comwrote :
Hi Ralph,

Which error are you getting? Is it access denied?

Kind regards, Jakob.

--http://www.dotninjas.dk

"Ralph" wrote:
Hi Jakob,
thanks again, for your code snippet. Unfortunately, this only works if
I want to check thepermissionsfor the local machine (the one I'm
working on as an administrator).
But I have to solve the following problem:
I have a folder, where I want to store a file and have to check the
access rights. If it's a shared folder, I have to check theshare
permissionsfor this folder, which is on a remote folder. In this
case, the scope.Connect method fails.
Can you help me again?
Thanks,
Ralph
On 22 Jan., 09:50, Jakob Christensen
<JakobChristen...@discussions.microsoft.comwrote :
Hi Ralph,
You can do this by using WMI. I wrote the following example for you. The
example lists all shares on a given computer including the users/groups that
are granted persmisssions to the shares. The "ace" object can also give you
information about the access rights (take a look at the Win32_ACE class of
WMI on MSDN).
string machine = "YourMachine";
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
"Ralph" wrote:
Hi,
how can I get the users or groups which are listed in the shared
permission of a shared folder?
Thanks,
Ralph- Zitierten Text ausblenden -- Zitierten Text anzeigen -- Zitierten Text ausblenden -- Zitierten Text anzeigen -
Jan 30 '07 #4
Hi Ralph,

You may be able to do it using ADSI and COM interop but you may run into
other security issues. You need a reference to ActiveDs.dll (usually placed
in c:\windows\system32.dll). I wrote the following example for you:

ActiveDs.IADsAccessControlList dacl;
ActiveDs.IADsSecurityDescriptor sd;
ActiveDs.ADsSecurityUtility sdUtil = new
ActiveDs.ADsSecurityUtility();

sd = (ActiveDs.IADsSecurityDescriptor)
sdUtil.GetSecurityDescriptor(@"\\machinename\share name", (int)
ActiveDs.ADS_PATHTYPE_ENUM.ADS_PATH_FILESHARE, (int)
ActiveDs.ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);
dacl = (ActiveDs.IADsAccessControlList) sd.DiscretionaryAcl;

foreach (ActiveDs.IADsAccessControlEntry entry in dacl)
{
Console.WriteLine("AccessMask: {0}", entry.AccessMask);
Console.WriteLine("AceType: {0}", entry.AceType);
Console.WriteLine("AceFlags: {0}", entry.AceFlags);
Console.WriteLine("Trustee: {0}\n", entry.Trustee);
}

HTH, Jakob.

--
http://www.dotninjas.dk

"Ralph" wrote:
Yes, I get an UnauthorizedAccessException. Unfortunately I don't have
any influence on the remote computer in the network in my project. I
just get a shared folder, and I have to check the permissions I have
for this folder.

On 30 Jan., 03:26, Jakob Christensen
<JakobChristen...@discussions.microsoft.comwrote :
Hi Ralph,

Which error are you getting? Is it access denied?

Kind regards, Jakob.

--http://www.dotninjas.dk

"Ralph" wrote:
Hi Jakob,
thanks again, for your code snippet. Unfortunately, this only works if
I want to check thepermissionsfor the local machine (the one I'm
working on as an administrator).
But I have to solve the following problem:
I have a folder, where I want to store a file and have to check the
access rights. If it's a shared folder, I have to check theshare
>permissionsfor this folder, which is on a remote folder. In this
case, the scope.Connect method fails.
Can you help me again?
Thanks,
Ralph
On 22 Jan., 09:50, Jakob Christensen
<JakobChristen...@discussions.microsoft.comwrote :
Hi Ralph,
You can do this by using WMI. I wrote the following example for you. The
example lists all shares on a given computer including the users/groups that
are granted persmisssions to the shares. The "ace" object can also give you
information about the access rights (take a look at the Win32_ACE class of
WMI on MSDN).
string machine = "YourMachine";
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
"Ralph" wrote:
Hi,
how can I get the users or groups which are listed in the shared
permission of a shared folder?
Thanks,
Ralph- Zitierten Text ausblenden -- Zitierten Text anzeigen -- Zitierten Text ausblenden -- Zitierten Text anzeigen -

Jan 31 '07 #5

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

Similar topics

7
by: Marek | last post by:
Whe i'm running my .net aplication from share on other server, i've got an error. Can someone explain what i must do? Unhandle exception:System.Security.SecurityException: Permission demand type...
6
by: Salty Dog | last post by:
Code: <%Response.Buffer = False%> <HTML> <HEAD> <title>Printing</title> </HEAD> <BODY> <center> <% FilePath = "c:\WUTemp\441817810_receiver.txt"
2
by: Joey | last post by:
Hey, I need to change a Share's "Share Permissions" using .NET, and without using WMI, is it possible? Thanks ahead! --Joey
4
by: rajesh | last post by:
I am trying to upload a file using .Net's HttpPostedFile.SaveAs() to a share on a remote server. It works fine when the share is on the same server. I looked at the permissions on the share and...
2
by: yxq | last post by:
Hello I want to create and delete the folder share, i found that it is ok for generic folder, but it does not work for Root directory(i.e c:\, d:\) The code...
2
by: Johnny Fugazzi | last post by:
I would like to access a network share from my vb.net application. I do not want to map a drive to the share, however. I would also like to specifiy a user credential to use when connecting to...
2
by: Bill Fallon | last post by:
I have a VS2005 VB.Net windows form application deployed to a share drive. The windows explorer security permissions for this application (.exe) file is set for Everyone with List Folder/Read Data...
1
by: Langedal, Roger | last post by:
I'm trying to setup a simple test on writing to a file on an UNC share from an asp.net 2.0 webpage. This is whats happing in default.aspx: ...
1
by: =?Utf-8?B?aGVjc2FuMDc=?= | last post by:
Hello I am fairly new to .NET Development. I need to query folders within a network drive and return some metadata related to the directories. For instance, I might have the following path:...
2
by: Thierry Kennes | last post by:
Hello, I'm trying to get the permissions on a shared folder using NetShareGetInfo api. I've got this function above that is supposed to give me the permission thanks to shi2_permission. The...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.