Copying file from Remote server to local and vice versa

前端 未结 2 513
梦如初夏
梦如初夏 2021-01-16 19:33

thanks for ur quick response. but im stucked with login only. im using following code to try to login:

bool success = LogonUser(\"username\", \"000.000.000.         


        
2条回答
  •  星月不相逢
    2021-01-16 19:54

    you need impersonation :

     [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool LogonUser(
                string lpszUsername,
                string lpszDomain,
                string lpszPassword,
                int dwLogonType,
                int dwLogonProvider,
                out IntPtr phToken);
    
    IntPtr userToken = IntPtr.Zero;
    
    bool success = External.LogonUser(
      "john.doe", 
      "domain.com", 
      "MyPassword", 
      (int) AdvApi32Utility.LogonType.LOGON32_LOGON_INTERACTIVE, //2
      (int) AdvApi32Utility.LogonProvider.LOGON32_PROVIDER_DEFAULT, //0
      out userToken);
    
    if (!success)
    {
      throw new SecurityException("Logon user failed");
    }
    
    using (WindowsIdentity.Impersonate(userToken))
    {
      // do the stuff with john.doe's credentials
    }
    

提交回复
热议问题