首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#设立共享权限真的很难

2013-04-26 
C#设置共享权限真的很难?想用C#代码把共享文件夹的权限设置为everyone可读写。这个用C#真的很难吗?C#真的不

C#设置共享权限真的很难?
想用C#代码把共享文件夹的权限设置为everyone可读写。

这个用C#真的很难吗?

C#真的不怎么样啊。
[解决办法]
语言只是工具,实现方式还要使用人的方式和方法咯。
你觉得很难?
C#->文件夹权  不可行
不可行

我来看呢
C#->dos命令->文件夹权限 可行

另外:你觉得C#没有那种 大喊一声:"把文件夹权限设置成everyone可读写"的功能就是所谓的不怎么样了,我觉得你很有必要停止编程,去反思自己为什么要去学编程了。

[解决办法]
引用命令空间:using System.Security.AccessControl;


string path = "mytest";
DirectorySecurity ds = new DirectorySecurity();
ds.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.ReadAndExecute 
[解决办法]
 FileSystemRights.Write, InheritanceFlags.ContainerInherit 
[解决办法]
 InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
System.IO.Directory.SetAccessControl(path, ds);

[解决办法]
/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2007/07/03
 * Time: 14:02
 * 
 * To change this template use Tools 
[解决办法]
 Options 
[解决办法]
 Coding 
[解决办法]
 Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Management;

namespace Share
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}

public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}

void Button1Click(object sender, System.EventArgs e)
{
shareFolder("d:\","D","Description");
}

 private void shareFolder(string FolderPath, string ShareName, string Description)
        {// 创建共享目录 
            try
            {
                ManagementClass managementClass = new ManagementClass("Win32_Share");
                ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");


                ManagementBaseObject outParams;
                inParams["Description"] = Description;
                inParams["Name"] = ShareName;
               inParams["Path"] = FolderPath;
                inParams["Type"] = 0x0;
                        outParams = managementClass.InvokeMethod("Create", inParams, null);

                if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
                {
                    throw new Exception("Unable to share directory.");
                }
             }
            catch
                 {
                return ;
                 }
             }
}
}



程序
[解决办法]
该回复于2013-04-25 17:03:25被管理员删除

热点排行