Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Sharing folders

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mystique - 26 Aug 2005 19:57 GMT
Hi guys

How i make a folder to be shared with C# ?

Regards,
Mystique
Chris Taylor - 27 Aug 2005 09:10 GMT
Hi,

You can use WMI to create a share, the following example should get you
started.

using(System.Management.ManagementClass Win32Share = new
ManagementClass("Win32_Share"))
     using(System.Management.ManagementBaseObject parameters =
Win32Share.GetMethodParameters("Create"))
     {
       parameters["Name"] = "ShareName";
       parameters["Path"] = "c:\\Temp";
       parameters["Type"] = 0;
       parameters["Access"] = null;
       parameters["Description"] ="Shared programatically from WMI";
       parameters["MaximumAllowed"] = 5;

       using(System.Management.ManagementBaseObject result =
Win32Share.InvokeMethod("Create", parameters, null))
       {
         if (((uint)result["ReturnValue"]) == 0)
         {
           MessageBox.Show("Folder shared");
         }
         else
         {
           MessageBox.Show("Folder share failed");
         }
       }
     }

Hope this helps

Signature

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

> Hi guys
>
> How i make a folder to be shared with C# ?
>
> Regards,
> Mystique
Mystique - 28 Aug 2005 13:56 GMT
thanks Chris
it worked :-)

do you know how i can get a list of all the folders that i are shared on my
PC?

Regards,
Mystique

> Hi,
>
[quoted text clipped - 35 lines]
>> Regards,
>> Mystique
Jakob Christensen - 29 Aug 2005 10:01 GMT
You can also use the Win32_Share class to list all shares on your computer:

ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Options.EnablePrivileges = true;

ManagementPath path = new ManagementPath("Win32_Share");
ManagementClass osClass = new ManagementClass(scope, path, new
ObjectGetOptions(null));

foreach (ManagementObject os in osClass.GetInstances())
 Console.WriteLine(os.Properties["Path"].Value.ToString());

HTH, Jakob.
Signature

http://www.dotninjas.dk
http://www.powerbytes.dk

> thanks Chris
> it worked :-)
[quoted text clipped - 44 lines]
> >> Regards,
> >> Mystique

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.