zoukankan      html  css  js  c++  java
  • C#里将其他共享目录映射为本地盘符的方法

    C#里将其他共享目录映射为本地盘符的方法

    分享
    from:
    http://gaoxinembed.blog.sohu.com/142397846.html

       

    转载CSDN文章


    1.通过执行命令,会有cmd窗口一闪而过:

      public void Get_Share(string remotepath, string localpath, string username, string password)
      {
       Process.Start("net"," use "+localpath+" "+remotepath+" "+password+" /user:"+username);
      }

      public void Break_Share(string localpath)
      {
       Process.Start("net"," use "+localpath+" /delete");
      }

    2.通过调用WINDOW的API函数:

      [DllImport("mpr.dll")]
      public static extern int WNetAddConnection2A(NETRESOURCE [] lpNetResource, string lpPassword, string lpUserName, int dwFlags);
      [DllImport("mpr.dll")]
      public static extern int WNetCancelConnection2A(string sharename,int dwFlags,int fForce);

      public int GetShare(string remotepath,string localpath,string username,string password)
      {
       try
       {
        NETRESOURCE [] share_driver = new NETRESOURCE[1];
        share_driver[0].dwType = 1;
        share_driver[0].lpLocalName = localpath;
        share_driver[0].lpRemoteName = remotepath;

        BreakShare(localpath);
        int ret = WNetAddConnection2A(share_driver, password, username, 1);

        return ret;
       }
       catch(Exception error)
       {
        throw new Exception(error.Message);
       }
      }

      public void BreakShare(string localpath)
      {
       int ret= WNetCancelConnection2A(localpath, 1, 1);
      }

  • 相关阅读:
    configbody
    add log to ldap
    registerComponent announceExist
    ldap
    6485 commands
    Titled Motor Entry
    ldap pkg
    remove rpm pkg
    创建自定义验证控件,以验证多行文本框中内容长度为例
    ASP.NET利用CustomValidator的ClientValidationFunction与OnServerValidate来double check资料输入的正确性
  • 原文地址:https://www.cnblogs.com/baishahe/p/2414032.html
Copyright © 2011-2022 走看看