zoukankan      html  css  js  c++  java
  • 连接远程服务器共享

      1    public class NetWork
      2    {
      3        [StructLayout(LayoutKind.Sequential)]
      4        public class NetResource
      5        {
      6            Create net use sturcture
     69
     70            public RESOURCE_SCOPE dwScope;
     71            public RESOURCE_TYPE dwType;
     72            public RESOURCE_DISPLAYTYPE dwDisplayType;
     73            public RESOURCE_USAGE dwUsage;
     74            public string LocalName;
     75            public string RemoteName;
     76            public string Comment;
     77            public string Provider;
     78        }

     79
     80        ///   
     81        /// mpr.dll  
     82        ///   

     83        [DllImport("mpr.dll", CharSet = CharSet.Ansi)]
     84        public static extern int WNetAddConnection2A(NetResource netResource,
     85                                                     String password,
     86                                                     String Username,
     87                                                     int Flag);
     88
     89
     90        ///   
     91        /// Create net use.  
     92        ///   

     93        public int CreateNetConnection(string RemoteName, string Password, string UserName)
     94        {
     95            NetResource myNetResource = new NetResource();
     96            myNetResource.dwScope = NetResource.RESOURCE_SCOPE.RESOURCE_GLOBALNET;
     97            myNetResource.dwType = NetResource.RESOURCE_TYPE.RESOURCETYPE_ANY;
     98            myNetResource.dwDisplayType = NetResource.RESOURCE_DISPLAYTYPE.RESOURCEDISPLAYTYPE_GENERIC;
     99            myNetResource.dwUsage = NetResource.RESOURCE_USAGE.RESOURCEUSAGE_CONNECTABLE;
    100            //myNetResource.LocalName = "Z:"; // Mapping to local dirver  
    101            myNetResource.RemoteName = RemoteName; // Remote host IP or host name.  
    102            myNetResource.Provider = null;
    103            return WNetAddConnection2A(myNetResource, Password, UserName, 0);
    104        }

    105
    106    }
  • 相关阅读:
    frog-jump
    nth-digit
    binary-watch
    elimination-game
    evaluate-division
    random-pick-index
    integer-replacement
    rotate-function
    longest-substring-with-at-least-k-repeating-characters
    decode-string
  • 原文地址:https://www.cnblogs.com/elzero/p/869329.html
Copyright © 2011-2022 走看看