Click here to Skip to main content
11,932,857 members (51,921 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked

How to Share Windows Folders Using C#

, 2 May 2007 GPL3
Rate this:
Please Sign up or sign in to vote.
by using this Method you can Easly Share Folders using C# Programming.

Screenshot - fig2.jpg


By using this Method you can Easly Share Folders with in C# Programming.

I'm wrote Advanced Feature in Source Code Like Maximum Connection and ...

Using the code

At the first you have to Add Reference : System.Management

From Visual Studio like This Image:

Screenshot - fig1.jpg

And Then with this Method You Can Easly Share Any Folder You Want :

private static void QshareFolder(string FolderPath, string ShareName, string Description)
    // Create a ManagementClass object

    ManagementClass managementClass = new ManagementClass("Win32_Share");

    // Create ManagementBaseObjects for in and out parameters

    ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");

    ManagementBaseObject outParams;

    // Set the input parameters

    inParams["Description"] = Description;

    inParams["Name"] = ShareName;

    inParams["Path"] = FolderPath;

    inParams["Type"] = 0x0; // Disk Drive

    //Another Type:

    // DISK_DRIVE = 0x0
    // PRINT_QUEUE = 0x1

    // DEVICE = 0x2

    // IPC = 0x3

    // DISK_DRIVE_ADMIN = 0x80000000

    // PRINT_QUEUE_ADMIN = 0x80000001

    // DEVICE_ADMIN = 0x80000002

    // IPC_ADMIN = 0x8000003

    //inParams["MaximumAllowed"] = int maxConnectionsNum;

    // Invoke the method on the ManagementClass object

    outParams = managementClass.InvokeMethod("Create", inParams, null);

    // Check to see if the method invocation was successful

    if ((uint) (outParams.Properties["ReturnValue"].Value) != 0)


        throw new Exception("Unable to share directory.");


}catch (Exception ex)
//MessageBox.Show(ex.Message, "error!");
Sample Usage: 

QshareFolder("c:\\TestShare","Test Share", "This is a Test Share");

As you see I'm Upload Source code of Sample Program i wrote ,and i hope it's useful to Start!

Points of Interest

I'm using this method in one of my Projects that my Users wants to Share Folder With the others And they don't now How! And i think they will be happy now!

And This Link is an Article About How To Reset Windows Administartor Password:



Version 1.0, By: Qasem Heirani Nobari


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Ghasem Heyrani Nobari
Software Developer (Senior)
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Ghasem - Heyrani-Nobari

You may also be interested in...

Comments and Discussions

QuestionOK - but it's not all Pin
Tomasz Bąk24-Aug-14 9:53
memberTomasz Bąk24-Aug-14 9:53 
GeneralThanks Pin
Member 1088098812-Jun-14 9:08
memberMember 1088098812-Jun-14 9:08 
Questionmodify-description property Pin
Member 1075602817-Apr-14 2:31
memberMember 1075602817-Apr-14 2:31 
GeneralMy vote of 5 Pin
Amir Mohammad Nasrollahi9-Aug-13 21:46
professionalAmir Mohammad Nasrollahi9-Aug-13 21:46 
GeneralBravo! Pin
bahman0110-Jul-13 22:22
memberbahman0110-Jul-13 22:22 
BugReturnValue is 9 when FolderPath has trailing back slash Pin
Member 843421321-Dec-12 3:43
memberMember 843421321-Dec-12 3:43 
GeneralMy vote of 4 Pin
Burak Tunçbilek9-Jul-12 3:56
memberBurak Tunçbilek9-Jul-12 3:56 
Questionتشكر خيلي به كارم اومد Pin
ehsan_wwe20-Sep-11 6:25
memberehsan_wwe20-Sep-11 6:25 
AnswerRe: تشكر خيلي به كارم اومد Pin
Amir Mohammad Nasrollahi9-Aug-13 21:46
professionalAmir Mohammad Nasrollahi9-Aug-13 21:46 
GeneralWhat do the return values mean? Pin
Bernhard Hiller17-Jun-11 3:24
memberBernhard Hiller17-Jun-11 3:24 
Generalممنون Pin
ali foroughi24-Apr-11 0:15
memberali foroughi24-Apr-11 0:15 
AnswerRe: ممنون Pin
Amir Mohammad Nasrollahi9-Aug-13 21:48
professionalAmir Mohammad Nasrollahi9-Aug-13 21:48 
GeneralMy vote of 4 Pin
sds192012-Dec-10 1:34
membersds192012-Dec-10 1:34 
GeneralMy vote of 5 Pin
dekmeaw10-Oct-10 21:49
memberdekmeaw10-Oct-10 21:49 
GeneralThanks.. And please try this tool.. Pin
Geek139-Jun-10 21:28
memberGeek139-Jun-10 21:28 
QuestionRights Pin
Wamuti3-Jun-10 0:03
memberWamuti3-Jun-10 0:03 
AnswerRe: Rights Pin
devvvy18-May-11 20:50
memberdevvvy18-May-11 20:50 
AnswerRe: Rights Pin
Michael900027-Jul-11 23:46
memberMichael900027-Jul-11 23:46 
GeneralThanks mate! Some useful additions... Pin
Geek1311-May-10 1:38
memberGeek1311-May-10 1:38 
GeneralNice! Pin
doung3030-Mar-09 21:31
memberdoung3030-Mar-09 21:31 
GeneralPrevious Shared Folder Pin
Sally Marlino12-Jul-08 9:56
memberSally Marlino12-Jul-08 9:56 
GeneralCache settings Pin
Member 25942017-Mar-08 10:55
memberMember 25942017-Mar-08 10:55 
GeneralExample code to set permissions after sharing Pin
RandyStimpson25-Oct-07 11:48
memberRandyStimpson25-Oct-07 11:48 
GeneralRe: Example code to set permissions after sharing Pin
ionymous30-Mar-09 6:20
memberionymous30-Mar-09 6:20 
GeneralRe: Example code to set permissions after sharing Pin
devvvy18-May-11 19:03
memberdevvvy18-May-11 19:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 2 May 2007
Article Copyright 2007 by Ghasem Heyrani Nobari
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid