Logon failure: unknown user name or bad password.error while accessing other server

前端 未结 1 1195
情深已故
情深已故 2021-01-22 08:24

I\'m accessing other server with the login credentials. My problem is if I run the code initially, it wil show the error as



        
相关标签:
1条回答
  • 2021-01-22 09:06

    Found out the solution. See the updated code for the answer.

    try
         {
            IntPtr admin_token = default(IntPtr);
            //Added these 3 lines
            WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
            WindowsIdentity wid_admin = null;
            WindowsImpersonationContext wic = null;
    
    
            if(LogonUser("myusername","domain","pwd",9,0,ref admin_token) != 0)
            {
            //Newly added lines
             wid_admin = new WindowsIdentity(admin_token);
             wic = wid_admin.Impersonate();
    
             DirectoryInfo dir = new DirectoryInfo(sourceDirName);
             DirectoryInfo[] dirs = dir.GetDirectories();
             }
         }
    
    0 讨论(0)
提交回复
热议问题