Hi, All,
I wrote a function to share a folder to individual user account with
WMI.
When I call it :
ShareFolder("c: \\test", "Test", "Shared by Riven", 8,
Environment.Mac hineName, "Administrator" );
The folder will be shared, but nobody has permission to access it.
(The share permissions list of this folder is empty)
Could you help me?
Thanks!
private void ShareFolder(str ing path, string name, string description,
int maxAllowed, string domain, string account)
{
//==0. Create Win32_Trustee
ManagementObjec t trustee = new ManagementClass (new
ManagementPath( "Win32_Trustee" ), null);
trustee["Domain"] = null;
trustee["Name"] = account;
string strSid = this.GetSID(dom ain, account);
//==1. Create win32_ace
ManagementObjec t ACE = new ManagementClass (new
ManagementPath( "Win32_Ace" ), null);
ACE["AccessMask "] = AccessMasks.Mod ify;
ACE["AceFlags"] = AceFlags.OBJECT _INHERIT_ACE |
AceFlags.CONTAI NER_INHERIT_ACE ;
ACE["AceType"] = AceType.Allow;
ACE["Trustee"] = trustee;
//==2. Create Win32_SecurityD escriptor
ManagementObjec t secDescriptor = new ManagementClass (new
ManagementPath( "Win32_Security Descriptor"), null);
secDescriptor["ControlFla gs"] = 4; //SE_DACL_PRESENT
secDescriptor["DACL"] = new object[] { ACE };
//==3. Using Win32_Share
ManagementClass classObj = new ManagementClass (new
ManagementPath( "Win32_Shar e"), null);
ManagementBaseO bject inParams =
classObj.GetMet hodParameters(" Create");
inParams["Access"] = secDescriptor;
inParams["Descriptio n"] = description;
inParams["MaximumAllowed "] = maxAllowed;
inParams["Name"] = name;
//inParams["Password"] = ""; //default is no password
inParams["Path"] = path;
inParams["Type"] = 0; //0: Disk Drive, 1: Print
Queue ,2: Device , 3: IPC
ManagementBaseO bject outParams =
classObj.Invoke Method("Create" , inParams, null);
uint ret =
(uint)(outParam s.Properties["ReturnValu e"].Value);
}
public string GetSID(string domain, string username)
{
string result = null;
ManagementScope scope = new ManagementScope ("root\\cimv2") ;
string queryString = string.Format(" SELECT SID FROM
Win32_UserAccou nt WHERE Domain=\"{0}\" AND Name=\"{1}\"", domain,
username);
SelectQuery userQuery = new SelectQuery(que ryString);
ManagementObjec tSearcher userSearcher = new
ManagementObjec tSearcher(scope , userQuery);
ManagementObjec tCollection queryCollection =
userSearcher.Ge t();
foreach (ManagementObje ct userAccount in queryCollection )
{
result = (string)userAcc ount["SID"];
}
if (result == null)
{
throw new Exception("Can' t fine user info!");
}
return result;
}
[Flags()]
public enum AccessMasks : int
{
ListDirectory = 0x1,
AddFile = 0x2,
AddSubdirectory = 0x4,
ReadExtendedAtt ributes = 0x8,
WriteExtendedAt tributes = 0x10,
Traverse = 0x20,
DeleteChild = 0x40,
ReadAttributes = 0x80,
WriteAttributes = 0x100,
Delete = 0x10000,
ReadControl = 0x20000,
WriteDac = 0x40000,
WriteOwner = 0x80000,
Synchronize = 0x100000,
Read = ListDirectory | ReadExtendedAtt ributes | ReadAttributes
| ReadControl | Synchronize,
ReadAndExecute = Read | Traverse,
Write = AddFile | AddSubdirectory | WriteExtendedAt tributes |
WriteAttributes | Synchronize,
Modify = Read | Write | Delete | Traverse,
FullControl = DeleteChild | WriteDac | WriteOwner | Modify
}
[Flags()]
public enum AceType : byte
{
Allow = 0,// Access Allowed
Denied = 1,// Access Denied
Audit = 2
}
[Flags()]
public enum AceFlags : byte
{
OBJECT_INHERIT_ ACE = 0x1,
CONTAINER_INHER IT_ACE = 0x2,
NO_PROPAGATE_IN HERIT_ACE = 0x4,
INHERIT_ONLY_AC E = 0x8,
INHERITED_ACE = 0x10
} 0 2589 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
I have an application where I am providing the user the ability to
select or create a folder on a domain, using SHBrowseForFolder. When
the user selects/creates a folder on a remote computer, it returns the
UNC path of that folder.
Using ADSI IADsFileShare, I would like to create that share, but the
..Path property seems to reject the UNC. Is there a way of converting
that UNC to the logical drive path or some other way of setting the...
|
by: CES |
last post by:
All,
If anyone has been following my trials over the last week see(Setting up a
Web Application on IIS 5.1 and ASP.Net Security Problems).
I'm having a problem running a Asp.Net Web Application. I've finally
narrowed the problem down to a security issue: The ASPNET (aspnet_wp)
account cannot connect to a Network resource instead of using a local path
ie: C:\Inetpub\wwwroot my development site resides on a Network Share...
|
by: Lucas |
last post by:
Hi,
I have an ASP.Net application written with VS.Net 2002 (Net FWK 1.0). This
Web Application uses Exception Management Application Block to log Events to
Windows Event Log. We registered the Exception Management Application Block
using installutil.
Our Application uses impersonation and used to work fine on Windows 2000
Server.
Now we installed it on a Windows Server 2003 and when an exception is
raised, we get an "Access is denied"...
|
by: JR |
last post by:
I have a Web server running on Windows XP. On this Web server, I have a Web
site configured with its home directory on a network share. In the Web site,
there's a virtual folder pointing to a local folder on the Web server
containing an ASP.NET application.
I get a "Failed to start monitoring changes" when I try to run the
application. If I try to debug, I get a message "unable to start debugging
on the Web server".
I put an...
|
by: ASP.NET User |
last post by:
Hi
I am in a shop where developers are required to work off of a networ
share. This is so that code and other documentation is backed up nightly. This is outside the realm of Visual SourceSafe which we also use for code control. The network drive is used as the working folder. This is a configuration this shop has used for 6 years and I do not see it changing any time soon
So I am testing running an ASP.NET Web application with a Clas...
| |
by: pj_servadmin |
last post by:
Server Error in '/<applicationName>' Application
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.
Parser Error Message: Could not load type 'Default.Global'.
Source Error:
Line 1: <%@ Application...
|
by: John Fleming |
last post by:
Hello,
I am building a web application with the following components:
2 Web Servers
- Windows Server 2003
- IIS 6
- .Net Framework version 2.0
- Reside in Domain A
2 Clustered Database Servers
|
by: shapper |
last post by:
Hello,
In have a class inside a compiled DLL where I have the following code:
' Create site map XML document
Dim siteMap As XmlDocument = New XmlDocument
' Load site map XML document from ASP.NET web site map
siteMap.Load(HttpContext.Current.Server.MapPath(Me.SiteMapUrl))
Me.SiteMapUrl is a property.
|
by: amitcool1982 |
last post by:
I am getting the path of share folder "ADMIN$" on a remote machine but this command have any user account issue. if it have any issues then what is the issue. If any developer have any clue then reply me.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |