<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      .net5訪問共享目錄

      windows平臺訪問遠程服務器共享目錄下的access數(shù)據(jù)庫文件

      public class SharedDirectoryManager
          {
              // logon types
              private const int Logon32_Logon_Interactive = 2;
              private const int Logon32_Logon_Network = 3;
              private const int Logon32_Logon_New_Credentials = 9;
      
              // logon providers
              private const int Logon32_Provider_Default = 0;
              private const int Logon32_Provider_Winnt50 = 3;
              private const int Logon32_Provider_Winnt40 = 2;
              private const int Logon32_Provider_Winnt35 = 1;
      
              private WindowsImpersonationContext impersonationContext;
      
              [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
              private static extern int LogonUser(string lpszUserName, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
      
              [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
              private static extern int DuplicateToken(IntPtr hToken, int impersonationLevel, ref IntPtr hNewToken);
      
              [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
              private static extern bool RevertToSelf();
      
              [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
              private static extern bool CloseHandle(IntPtr handle);
      
              public bool ImpersonateValidUser(string userName, string domain, string password)
              {
                  var token = IntPtr.Zero;
                  var tokenDuplicate = IntPtr.Zero;
      
                  if (RevertToSelf())
                  {
                      // 這里使用LOGON32_LOGON_NEW_CREDENTIALS來訪問遠程資源。
                      // 如果要(通過模擬用戶獲得權(quán)限)實現(xiàn)服務器程序,訪問本地授權(quán)數(shù)據(jù)庫可
                      // 以用LOGON32_LOGON_INTERACTIVE
                      if (LogonUser(userName, domain, password, Logon32_Logon_New_Credentials, Logon32_Provider_Default, ref token) != 0)
                      {
                          if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
                          {
                              var tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
                              this.impersonationContext = tempWindowsIdentity.Impersonate();
                              if (this.impersonationContext != null)
                              {
                                  AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
                                  CloseHandle(token);
                                  CloseHandle(tokenDuplicate);
                                  return true;
                              }
                          }
                      }
                  }
      
                  if (token != IntPtr.Zero)
                      CloseHandle(token);
      
                  if (tokenDuplicate != IntPtr.Zero)
                      CloseHandle(tokenDuplicate);
      
                  return false;
              }
      
              public void UndoImpersonation()
              {
                  this.impersonationContext.Undo();
              }
          }

      調(diào)ImpersonateValidUser成功后,按照本地目錄可正常訪問

      如果是訪問共享的access數(shù)據(jù)庫文件

      指定連接字符串:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\192.168.137.200\ShareFolder\test.mdb;OLE DB Services=-4;

      為共享目錄文件地址即可

      如果不加OLE DB Services=-4;,可能會導致web中訪問數(shù)據(jù)庫時發(fā)生:

      Microsoft.Jet.OLEDB.4.0 提供程序不支持 ITransactionLocal 接口。本地事務不可用于當前提供程序 的異常

       

      跨平臺(.net 5)共享目錄訪問解決方案

      通過shell命令實現(xiàn): net use \\192.168.3.163\software /User:administrator 123456  /PERSISTENT:YES

       

       

      public class RemoteFileOperate
          {
              /// <summary>
              /// 遠程訪問目錄
              /// </summary>
              public string remotePath { get; set; }
      
              /// <summary>
              /// 用戶名
              /// </summary>
              public string userName { get; set; }
      
              /// <summary>
              /// 密碼
              /// </summary>
              public string passWord { get; set; }
      
      
              public RemoteFileOperate(string remotePath)
              {
                  this.remotePath = remotePath;
              }
      
              public RemoteFileOperate(string remotePath, string userName, string passWord)
              {
                  this.remotePath = remotePath;
                  this.userName = userName;
                  this.passWord = passWord;
              }
      
              /// <summary>
              /// 檢測遠程訪問連接狀態(tài)
              /// </summary>
              /// <param name="path"></param>
              /// <param name="isNeedPersistent"></param>
              /// <returns></returns>
              public bool CheckConnectState()
              {
                  bool Flag = false;
                  Process proc = new Process();
                  try
                  {
                      proc.StartInfo.FileName = "cmd.exe";
                      proc.StartInfo.UseShellExecute = false;
                      proc.StartInfo.RedirectStandardInput = true;
                      proc.StartInfo.RedirectStandardOutput = true;
                      proc.StartInfo.RedirectStandardError = true;
                      proc.StartInfo.CreateNoWindow = true;
                      proc.Start();
                      string dosLine = string.Empty;
                      string dosLineClean = @"net use * /del /y";
                      if (!string.IsNullOrEmpty(userName) || !string.IsNullOrEmpty(passWord))
                      {
                          dosLine = @"net use " + remotePath + " /User:" + userName + " " + passWord + " /PERSISTENT:YES";
                      }
                      else
                      {
                          dosLine = @"net use " + remotePath + " /PERSISTENT:NO";
                      }
      
                      proc.StandardInput.WriteLine(dosLineClean);
                      proc.StandardInput.WriteLine(dosLine);
                      proc.StandardInput.WriteLine("exit");
                      while (!proc.HasExited)
                      {
                          proc.WaitForExit(1000);
                      }
                      string errormsg = proc.StandardError.ReadToEnd();
                      proc.StandardError.Close();
                      if (string.IsNullOrEmpty(errormsg))
                      {
                          Flag = true;
                      }
                  }
                  catch (Exception ex)
                  {
                  }
                  finally
                  {
                      proc.Close();
                      proc.Dispose();
                  }
                  return Flag;
              }
          }

       

      posted @ 2021-03-23 10:54  扶我起來我還要敲  閱讀(156)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲国产精品成人综合色在| 日韩成人福利视频在线观看| 中文毛片无遮挡高潮免费| 国产成人亚洲精品日韩激情| 精品国产迷系列在线观看| 亚洲国产精品第一二三区| 国产精品99中文字幕| 欧美老少配性行为| 高清无打码一区二区三区| 精品伊人久久久香线蕉| 国产欧美日韩免费看AⅤ视频| 精品av无码国产一区二区| 亚洲成人精品一区二区中| 广东省| 国产精品一线天在线播放| 国产不卡一区不卡二区| 人妻精品动漫H无码中字| 国产国产午夜福利视频| 一区二区丝袜美腿视频| 亚洲国产精品久久久天堂麻豆宅男| 亚洲高清国产拍精品网络战 | 亚洲AV熟妇在线观看| 九九热精品在线视频观看| 吉川爱美一区二区三区视频| 亚洲18禁一区二区三区| 天天干天天日| 中文字幕亚洲人妻系列| 中文字幕第一页国产| 国内视频偷拍一区,二区,三区| 久久亚洲精品中文字幕无| 果冻传媒18禁免费视频| 亚洲av色图一区二区三区| 色偷偷www.8888在线观看| 日韩丝袜欧美人妻制服| 九九热在线观看精品视频| 久久久无码精品亚洲日韩蜜臀浪潮| 国产精品毛片一区二区三| 最近中文字幕国产精品| 亚洲码国产精品高潮在线| 亚洲精品中文字幕第一页| 精品一区二区亚洲国产|