473,399 Members | 4,254 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,399 software developers and data experts.

Setting permissions on a folder using WMI

Hello.

I am writing some code that accepts a DFS Link and Username and grants that
User permissions to the physical directory that the DFS Link corresponds to.
I am using the System.Management namespace and WMI queries.

When I run the code below and check the Security tab of the folder , I find
that all entries have been cleared – which is ok and this is expected, main
problem is that the User that I have set up the Trustee and ACE object for,
has not been added. Interestingly (just before I set the permissions) I
retrieve the first ACE in the access list and then add it back into the
DACL[] property of the SecurityDescriptor object. In the code below, this
where I add ‘firstAce’ to the DACL property instead of ‘Ace’. When I check
the folder, the entry is added to the list.

I can probably assume that the code that actually sets the permissions does
work. What must be going wrong is either the way I have configured the
Trustee or the ACE object. The user to which we need to set permissions for
can be identified by the SID. I recover the SIDString using a WMI query,
passing in the Username and Domain, and then convert the resultant string
value into a byte array (SID needs to be in this format). I do this
conversion using the ASCIIEncoding class of System.Text, perhaps this is
where things are going wrong. Is there a more effective way of converting
from String to Byte Array?

Any thoughts on where there could be issues ?

Thanks,

Praveen.

Here is the code below:

//***TRUSTEE***

//Create Trustee management object (Win32_Trustee) setting the SID
(converted to byte array) and Username

ManagementObject Trustee = new ManagementClass(new
ManagementPath("Win32_Trustee"),null).CreateInstan ce();

Trustee["SID"] = bSID; //SID as a byte array
//***ACE***

//Create ACE management object (Win32_ACE) setting the AccessMask, AceFlags,
AceType and Trustee (to Trustee object)

ManagementObject Ace = new ManagementClass(new
ManagementPath("Win32_ACE"),null).CreateInstance() ;

Ace["AccessMask"] = "2032127";

Ace["AceFlags"] = "3";

Ace["AceType"] = 0;

Ace["Trustee"] = Trustee;

//***SecurityDescriptor***

//Retrieve the Security Descriptor passing in the path to the physical
directory

string dirClassPath1 = @"Win32_LogicalFileSecuritySetting='" + strDFSLink +
"'";

ManagementObject Win32LogicalFileSecuritySetting = new ManagementObject(new
ManagementPath(dirClassPath1),null);

ManagementBaseObject outParams1 =
Win32LogicalFileSecuritySetting.InvokeMethod("GetS ecurityDescriptor",null,
null);

ManagementBaseObject SecurityDescriptor1 = (ManagementBaseObject)
outParams1["Descriptor"];

//Get the first ACE in the existing DACL for this folder

ManagementBaseObject firstAce = ((ManagementBaseObject[])
SecurityDescriptor1["DACL"])[0];

//Set parameters for Security Descriptor

SecurityDescriptor1["ControlFlags"] = "4";

SecurityDescriptor1["DACL"] = new object[1]{Ace};

//ALTERNATIVELY SET TO THE FIRST ENTRY IN THE EXISTING DACL

//SecurityDescriptor1["DACL"] = new object[1]{firstAce};
//***Set Permissions

string dirClassPath2 = @"Win32_Directory='" + strDFSLink + "'";

ManagementObject Win32Directory = new ManagementObject(new
ManagementPath(dirClassPath2),null);

ManagementBaseObject inParams2 =
Win32Directory.GetMethodParameters("ChangeSecurity Permissions");

inParams2["Option"] = "4";

inParams2["SecurityDescriptor"] = SecurityDescriptor1;

ManagementBaseObject outParams2 =
Win32Directory.InvokeMethod("ChangeSecurityPermiss ions", inParams2, null);

Sep 24 '05 #1
0 2305

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

Similar topics

0
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: Maximus | last post by:
Hi, Does anybody know how I can programatically set modify permissions on a folder for the aspnet user. Any help will be appreciated. Thanks.
0
by: Johan | last post by:
Hi I'm using WMI to set and remove folderpermissions and it sems to work fine, sometimes. I start by having the folderpermissons manuly set to Everyone and Everone has full rights. When I'm...
1
by: Jeremy Winchell | last post by:
I have an applications that imports new AD users. It creates a folder to store the user profile information, and a folder for their home directory. I would like to set the Permissions on these...
2
by: Phil Hey | last post by:
I am trying to set permissions on a folder programmatically, and have success fully used the code below for knowledge base article 266461 : How To: Programmatically Set NTFS File System Folder...
0
by: Praveen | last post by:
Hello. I am writing some code that accepts a DFS Link and Username and grants that User permissions to the physical directory that the DFS Link corresponds to. I am using the System.Management...
2
by: steggun | last post by:
Hello, I'm writing a C# windows form application and need some guidance on a couple of issues. First, my application needs to change the permissions on a folder. The application creates a...
0
by: =?Utf-8?B?TGlhbSBNYWM=?= | last post by:
Hi Folks, I have embeded WMI scripting within a Visual Basic application to create remote shares and set permissions, I'm now moving to vb.net environment and having trouble getting my scripting...
5
by: daokfella | last post by:
I have a custom web.config section similar to the following: <CustomAuthSettings attr1="" attr2=""> <Locations RedirectUrl="Invalid.aspx"> <add Path="test.aspx" Roles="1,2,3" Permissions="4,5,6"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.