日期:2014-05-18  浏览次数:20921 次

C# 网络共享映射本地
C# code
[DllImport("mpr.dll", EntryPoint = "WNetAddConnection2")]
        public static extern uint WNetAddConnection2(
            [In] NETRESOURCE lpNetResource,
            string lpPassword,
            string lpUsername,
            uint dwFlags);

        [DllImport("Mpr.dll")]
        public static extern uint WNetCancelConnection2(
            string lpName,
            uint dwFlags,
            bool fForce);

        [StructLayout(LayoutKind.Sequential)]
        public class NETRESOURCE
        {
            public int dwScope;
            public int dwType;
            public int dwDispalyType;
            public int dwUsage;
            public string LocalName;
            public string RemoteName;
            public string Comment;
            public string Provider;
        }

        private Parent _parent;

        public Parent parent
        {
            get { return _parent; }
            set { _parent = value; }
        }



        
        static void Main()
        {
            Tester t = new Tester();
            NETRESOURCE myNetResource = new NETRESOURCE();
            myNetResource.dwScope = 2;
            myNetResource.dwType = 1;
            myNetResource.dwDispalyType = 3;
            myNetResource.dwUsage = 1;
            myNetResource.LocalName = "L:";
            myNetResource.RemoteName = "\\\\192.168.1.134\\abc";

            uint nret = WNetAddConnection2(myNetResource,"" ,"" , 0);
            Console.WriteLine(nret);
}


这是写的代码,但是在remotename这里,当前这个是我自己共享的文件夹,权限也是EO可以读写,但是总是返回5,然后我设为别人的"\\\\192.168.1.180\\nonva$"也是返回5,但是当用"192.168.1.10"这里的访问需要用户名和密码,建立却正常的,

那两个自己的和别人电脑的,我用windows自己带的映射网络驱动器 来映射的话都没有问题!

求指教啊!!

------解决方案--------------------
一般的无密码共享采用guest账号,密码为空串。
------解决方案--------------------
探讨
可是我想查看的是当前用户所有的映射盘,应该怎么写呢?