상세 컨텐츠

본문 제목

공유폴더 설정

C#

by 탑~! 2016. 1. 14. 15:21

본문

//참조추가 System.Management;
using System.Management;

private void ShareFolderPermission(string FolderPath, string ShareName)
{
    try
    {
        ManagementClass managementClass = new ManagementClass("Win32_Share");
        ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
        ManagementBaseObject outParams;
        inParams["Description"] = "";
        inParams["Name"] = ShareName;
        inParams["Path"] = FolderPath;
        inParams["Type"] = 0x0;
                
        outParams = managementClass.InvokeMethod("Create", inParams, null);
                
        if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
            Console.WriteLine("Folder might be already in share or unable to share the directory");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

관련글 더보기