摘要: 使用前要引用 System.Management /// <summary> /// 建立共享文件夹 /// </summary> /// <param name="shareName">共享名</param> /// <param n
使用前要引用 System.Management
/// <summary>
/// 建立共享文件夹
/// </summary>
/// <param name=shareName>共享名</param>
/// <param name=path>要共享的本地文件夹路径</param>
/// <returns>若返回值为0则成功</returns>
PRivate bool ShareAdd(string shareName, string path)
{
ManagementClass o = new ManagementClass(@\\\\localhost\\root\\cimv2, Win32_Share, null);
ManagementBaSEObject inputArgs = o.GetMethodParameters(Create);
inputArgs[Name] = shareName;
inputArgs[Path] = path;
inputArgs[Type] = 0; //Drive
ManagementBaseObject outParams = o.InvokeMethod(Create, inputArgs, null);
int ret = (int)(outParams.Properties[ReturnValue].Value);
o.Dispose();
return (ret == 0);
}
/// <summary>
/// 删除共享
/// </summary>
/// <param name=shareName>要删除的共享名</param>
private void ShareDel(string shareName)
{
string wsql = Select * From Win32_Share Where Name=\'C\';
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wsql);
if (searcher == null) return;
foreach (ManagementObject o in searcher.Get())
{
o.Delete();
}
}
相关文章推荐
智能手机建站的优点是什么?网站页面布局有哪些关键点? 2022-01-10
2022年中国云计算面临的问题及发展前景预测分析2021-12-28
绿色智能基础设施连接可持续未来-IDCC2021万国数据第一代Smart DC发布会议程揭晓2021-12-27
阿里云:早期未意识到Apache log4j2漏洞情况的严重性 将强化漏洞管理2021-12-27
云计算开发:Python3-replace()方法详解2021-12-27