P pnp Nov 26, 2004 #1 Hi all, How can I make a folder shared from a pc through C# code? Thanks in advance, Peter
M Michael Giagnocavo [MVP] Nov 26, 2004 #2 Use Platform Invocation to call NetShareAdd: http://www.pinvoke.net/default.aspx/netapi32.NetShareAdd
Use Platform Invocation to call NetShareAdd: http://www.pinvoke.net/default.aspx/netapi32.NetShareAdd
W Willy Denoyette [MVP] Nov 26, 2004 #3 Easy, Using System.Management classes.... using System.Management; .... using (ManagementClass o = new ManagementClass("\\\\.\\root\\cimv2", "Win32_Share", null)) { string method = "create"; ManagementBaseObject inputArgs = o.GetMethodParameters(method); inputArgs["Name"] = "SharedTemp"; // share as inputArgs["Path"] = "c:\\temp"; // directory to share inputArgs["Description"] = "this is public share"; inputArgs["Type"] = 0; // 0 = Disk share type ManagementBaseObject outParams = o.InvokeMethod(method, inputArgs, null); uint ret = (uint)(outParams.Properties["ReturnValue"].Value); if(ret != 0) Console.WriteLine("Failed {0}", ret); } Willy.
Easy, Using System.Management classes.... using System.Management; .... using (ManagementClass o = new ManagementClass("\\\\.\\root\\cimv2", "Win32_Share", null)) { string method = "create"; ManagementBaseObject inputArgs = o.GetMethodParameters(method); inputArgs["Name"] = "SharedTemp"; // share as inputArgs["Path"] = "c:\\temp"; // directory to share inputArgs["Description"] = "this is public share"; inputArgs["Type"] = 0; // 0 = Disk share type ManagementBaseObject outParams = o.InvokeMethod(method, inputArgs, null); uint ret = (uint)(outParams.Properties["ReturnValue"].Value); if(ret != 0) Console.WriteLine("Failed {0}", ret); } Willy.
G Guest Nov 30, 2004 #5 I have seen the way used by Willy quite often. For those who don't understand what it is going about, check: http://www.c-sharpcorner.com/Code/2004/Sept/WMIPart1.asp http://www.c-sharpcorner.com/Code/2004/Sept/WMIPart2.asp I reading it right now and I hope it will help me to understand WMI.
I have seen the way used by Willy quite often. For those who don't understand what it is going about, check: http://www.c-sharpcorner.com/Code/2004/Sept/WMIPart1.asp http://www.c-sharpcorner.com/Code/2004/Sept/WMIPart2.asp I reading it right now and I hope it will help me to understand WMI.