1

I have some C# code for extracting url from Chrome. It usually works on Win7/Win 8.1, but on some computers with the same configuration it doesn't work. And, probably, there is no difference between these configurations. Why does it happen?

Process[] procsChrome = Process.GetProcessesByName("chrome");
foreach(Process chrome in procsChrome)
{
   if(chrome.MainWindowHandle == IntPtr.Zero)
   {
    continue;
   }
   AutomationElement mainWindow = AutomationElement.FromHandle(chrome.MainWindowHandle);
   elmUrlBar = mainWindow.FindFirst(TreeScope.Descendants,  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));

  //elmUrlBar on some computers inited, on some NULL. But versions of Chrome are identical.
...
}

3 Answers3

0

It's possible that this is a Windows security issue. There is some security in Windows to disable communication from one application to another, called User Account Control (UAC).

If you usually start Visual Studio as an Administrator, then the child process it spawns to run your application will also be elevated, and your automation will likely work.

Trying it on another machine will likely fail because of UAC. Or it might succeed on a machine that has some UAC settings disabled.

On the machines that fail, I would try to temporarily disable UAC as mentioned here, and if it now works, then you know that's the issue. You can actually get it working even when UAC is enabled, by adding a manifest to your application as mentioned here.

Community
  • 1
  • 1
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • Thank you for your response. I turned off uac and restart pc, it didn't help. I also tried to use another class TreeWalker to get recursive all nodes, so there were a very limited list, and of course there wasn't "url control". But on another machine it's ok. May be you still have some versions, please help. – Alexey Potapov Sep 02 '14 at 19:18
0

(1) Have you verified that Accessibility was turned on in Chrome in those situations where your application failed? It either must be enabled from the Chrome's command line or turned on for individual tabs.

(2) You may have run afoul of User Interface Privilege Isolation (UIPI). It's not a problem if you're running an Admin login, but with a Standard login the requirements to bypass UIPI are:

  1. Have uiAccess=True in the application's manifest.
  2. Sign the application via a valid code signing authority. (You can test with a self-signed executable however--we have done that successfully.)
  3. Install the executable file to the System32 directory (or SysWOW64 for 32-bit applications installed on 64-bit windows).
Mark Wilsdorf
  • 751
  • 1
  • 5
  • 18
  • Thank you for your response. 1. I tried to find url in firefox also. It was not found on 2 machines. (But on 5 machines that's ok) 2. I set uiAccess=true, so the app failed with error and I tried to use makecert and so on. The app started correctly, but it didnt find url. Then I copy all files include executable file in SysWOW64 and I tried to launch from this location - no url found again. (May be I did wrong third point, what does it mean install, i did usual copy of release folder?) – Alexey Potapov Sep 02 '14 at 19:51
  • Yes, simply copying the signed executable to SysWOW64 will work. – Mark Wilsdorf Sep 02 '14 at 21:19
  • Hi Alexey, I also facing same issue in capturing the current Chrome URL. Have you found any solution? – Pankaj Jun 01 '15 at 09:52
0

I had a similar issue in a server where the UI Automation worked just fine one day and it didn't the other day.

Someone with admin privileges had added some System Environment variables and restarted the server. Not sure how they messed up something in this step, but my app stopped working after that.

After pulling hair for a day out of frustration, I decided to log off from the user account I was logged into that server and logged back in again. And I ran my app, and bam, it started working!

Ash K
  • 1,802
  • 17
  • 44