private void FormMain_Load(object sender, EventArgs e) { ShareDirec(); } public void ShareDirec() { ManagementClass management =new ManagementClass("Win32_share"); ManagementBaseObject inParams = management.GetMethodParameters("Create"); ManagementBaseObject outParams; string strPath = @"Z:\"; string strName = "网络磁盘Z"; inParams["Name"] = strName; inParams["Path"] = strPath; inParams["Type"] = 0x0; outParams = management.InvokeMethod("Create", inParams, null); if ((uint)(outParams.Properties["ReturnValue"].Value) != 0) { txtLog.AppendText(string.Format("【{0}】共享失败", strPath)); return; } else { string strLog = string.Format("已将路径【{0}】设置为共享目录,共享名称为【{1}", strPath, strName); txtLog.AppendText(strLog); } }
标签:management,string,Windows,strName,inParams,共享,目录,strPath From: https://www.cnblogs.com/chengeng/p/18092362