日期:2014-05-17 浏览次数:21085 次
private void Form1_Load(object sender, EventArgs e)
{
//创建文件夹
if (!Directory.Exists(@"D:\aaaaaa"))
{
Directory.CreateDirectory(@"D:\aaaaaa");
}
int result = ShareNetFolder(@"D:\aaaaaa","共享文件","共享注释");
if (result >= 0)
MessageBox.Show("共享成功!");
}
/// 设置文件夹共享
/// </summary>
/// <param name="FolderPath">文件夹路径</param>
/// <param name="ShareName">共享名</param>
/// <param name="Description">共享注释</param>
/// <returns></returns>
public int ShareNetFolder(string FolderPath, string ShareName, string Description)
{
try
{
ManagementClass managementClass = new ManagementClass("Win32_Share");
// Create ManagementBaseObjects for in and out parameters
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
// Set the input parameters
inParams["Description"] = Description;
inParams["Name"] = ShareName;
&nb