I need create smb share using c# in local machine. Is possible? Need I use powershell? I am using Visual Studio 2019. I don't found any documentation about this
-
You can create a "share" in PowerShell ... or in C# ... or manually, in Windows file Explorer ... or many other ways. Q: Must you create the share programmatically (e.g. in a C# program), or can you use Windows Explorer? Q: Any constraints/restrictions (e.g. must the share be compatible with Ubuntu Samba)? For example: askubuntu.com/questions/1009455/…– paulsm4Commented Aug 13, 2020 at 19:34
1 Answer
I need create smb share using c# in local machine. Is possible?
Given that other programs do it, and C# is capable at the end as last resort to call the native API, it is obviously possible.
Need I use powershell?
No.
I am using Visual Studio 2019.
As irrelevant as it gets - VS is an IDE, which is a VERY glorified editor. It does not write code for you.
You have basically multipel avenues:
- Use the NORMAL command line tools (net use command etc. that you would call from a command line) by means if Process.Start
- use WMI. Links i.e. https://social.technet.microsoft.com/Forums/windowsserver/en-US/64d1e369-2c33-4448-8e87-4a2ceb54eb80/how-to-create-file-share-using-wmi?forum=winserverfiles
Sample code, which I found in 30 seconds using google (but you ahve to know "WMI" as keyword) is in example at https://www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C
Using WMI you can use
ManagementClass managementClass = new ManagementClass("Win32_Share");
THere is a whole code sample there, but I am not going to steal it.