Question

Pop up dialog for entering login credentails

Please let me know how to handle web adapter login where the credential has to be entered in Windows Security pop up dialog box (these control are not recognized for interrogation using Pega).

***Edited by Moderator Marissa to update platform capability tags****

Correct Answer
December 12, 2019 - 2:21am

Hi,
I used below script to perform login. It worked for me.

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Windows.Forms;
  9. using System.Xml;
  10. using System.Runtime.InteropServices;
  11. using System.Windows;
  12.  
  13. namespace Dynamic.Script_8D764454627C233
  14. {
  15. // Script generated by Pega Robotics Studio 8.0.2012.0
  16. // Please use caution when modifying class name, namespace or attributes
  17. [OpenSpan.TypeManagement.DynamicTypeAttribute()]
  18. [OpenSpan.Design.ComponentIdentityAttribute("Script-8D764454627C233")]
  19. public sealed class Script
  20. { [DllImportAttribute("User32.dll")]
  21. public static extern IntPtr FindWindow(String ClassName, String WindowName);
  22. [DllImportAttribute("User32.dll")]
  23. public static extern IntPtr SetForegroundWindow(IntPtr hWnd);
  24. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  25. public static extern IntPtr SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam);
  26. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  27. public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  28.  
  29. public void LoginWindow(string Uname,string Password)
  30. {
  31. try
  32. {
  33. System.Threading.Thread.Sleep(2000);
  34. IntPtr hWnd = FindWindow(null, "Windows Security");
  35. // Windows Security is the title of the alert box
  36. SetForegroundWindow(hWnd);
  37. System.Threading.Thread.Sleep(2000);
  38.  
  39. SendKeys.SendWait(Uname);
  40. System.Threading.Thread.Sleep(1000);
  41. SendKeys.SendWait("{Tab}");
  42.  
  43. SendKeys.SendWait(Password);
  44. System.Threading.Thread.Sleep(1000);
  45.  
  46. SendKeys.SendWait(@"{Enter}");
  47. }
  48. catch(Exception ex)
  49. {
  50. OpenSpan.Diagnostics.Diagnostic.PublishException(ex, null);
  51. }
  52.  
  53. }
  54. }

 

Comments

Keep up to date on this post and subscribe to comments

December 12, 2019 - 2:21am

Hi,
I used below script to perform login. It worked for me.

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Windows.Forms;
  9. using System.Xml;
  10. using System.Runtime.InteropServices;
  11. using System.Windows;
  12.  
  13. namespace Dynamic.Script_8D764454627C233
  14. {
  15. // Script generated by Pega Robotics Studio 8.0.2012.0
  16. // Please use caution when modifying class name, namespace or attributes
  17. [OpenSpan.TypeManagement.DynamicTypeAttribute()]
  18. [OpenSpan.Design.ComponentIdentityAttribute("Script-8D764454627C233")]
  19. public sealed class Script
  20. { [DllImportAttribute("User32.dll")]
  21. public static extern IntPtr FindWindow(String ClassName, String WindowName);
  22. [DllImportAttribute("User32.dll")]
  23. public static extern IntPtr SetForegroundWindow(IntPtr hWnd);
  24. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  25. public static extern IntPtr SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam);
  26. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  27. public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  28.  
  29. public void LoginWindow(string Uname,string Password)
  30. {
  31. try
  32. {
  33. System.Threading.Thread.Sleep(2000);
  34. IntPtr hWnd = FindWindow(null, "Windows Security");
  35. // Windows Security is the title of the alert box
  36. SetForegroundWindow(hWnd);
  37. System.Threading.Thread.Sleep(2000);
  38.  
  39. SendKeys.SendWait(Uname);
  40. System.Threading.Thread.Sleep(1000);
  41. SendKeys.SendWait("{Tab}");
  42.  
  43. SendKeys.SendWait(Password);
  44. System.Threading.Thread.Sleep(1000);
  45.  
  46. SendKeys.SendWait(@"{Enter}");
  47. }
  48. catch(Exception ex)
  49. {
  50. OpenSpan.Diagnostics.Diagnostic.PublishException(ex, null);
  51. }
  52.  
  53. }
  54. }

 

December 17, 2019 - 7:28am

Thanks for sharing the code.  This code works when the machine is not locked