![]() |
General Reading »
Hardware & System »
General
Intermediate
License: The GNU General Public License (GPL)
How to Share Windows Folders Using C#By Qasem Heyrani Nobariby using this Method you can Easly Share Folders using C# Programming. |
C# 2.0, VB 9.0.NET 1.0, .NET 1.1, .NET 2.0, Win2K, WinXP, Win2003, Vista, .NET 3.0VS2005, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

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 ...
At the first you have to Add Reference : System.Management
From Visual Studio like This Image:

And Then with this Method You Can Easly Share Any Folder You Want :
//
//
private static void QshareFolder(string FolderPath, string ShareName, string Description)
{
try{
// 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!
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
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 2 May 2007 Editor: |
Copyright 2007 by Qasem Heyrani Nobari Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |