Solved

How to programmatically create shared folder and assign permission using .Net C# ?

Posted on 2012-03-23
9
2,927 Views
Last Modified: 2012-04-15
How to programmatically create shared folder and assign permission using .Net C# ?

Please provide sample code.
0
Comment
Question by:sepknow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 400 total points
ID: 37760843
I would use WMI to create a share with the Win32_Share class:

Create method of the Win32_Share Class
http://msdn.microsoft.com/en-us/library/windows/desktop/aa389393(v=vs.85).aspx

Assigning permission is another thing.  I would have to research that one.
0
 
LVL 11

Assisted Solution

by:Mihai Stancescu
Mihai Stancescu earned 100 total points
ID: 37764461
For sharing you can use WMI as TheLearnedOne said:
WMI share example or you can use pinovke PInvoke share.

To apply permissions: Folder permissions.
To set sharing permissions you can use WMI again: WMI Share permissions.

Regards,
Mishu
0
 

Author Comment

by:sepknow
ID: 37774661
I am not familiar with unmanaged code.
I am not able to compile this statement :

using ActiveDs;

May I know which reference should be added?
0
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 37774788
WMI is managed code that is in the System.Management namespace.  You need to add a reference to your project to the System.Management.dll, since it is not added by default.
0
 

Author Comment

by:sepknow
ID: 37777199
I think I am close to what I need. Just this one piece missing.

This statement gave everybody full control:
shInfo.shi502_security_descriptor = IntPtr.Zero;

How to set this structure such that the "Administrator" has Read/Write and the rest has only Read access?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37805864
I am not sure what you are working with there.  Can you expound on that idea, please?
0
 

Author Comment

by:sepknow
ID: 37810499
Hi,

Thanks.

I have 3 local user accounts in my computer.
1 built-in administrator and two other under the Users group.

What I need is to be able to (1) create a shared folder and for this newly created shared folder, (2a) assign the read and write permission to the administrator, (2b) assign read access to two other user account, finally (3) remove the Everyone full control permission (cause when the shared folder was created, Everyone full control permission was assigned automatically).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37810820
Can you provide more detail about this concept?

shInfo.shi502_security_descriptor = IntPtr.Zero;

What type of structure is that?  Is that WMI?  I don't recognize the names...
0
 

Author Comment

by:sepknow
ID: 37849368
Sorry for late reply.
I have found an alternate solution.
Thank you for your effort.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question