When accessing Process.MainWindowTitle as follows...
Process[] processes = Process.GetProcessesByName( "iexplore" );
...and then loop over the resulting array, I always end up with the MainWindowTitle being empty for all but one item in the array. In my case I've got two Internet Explorer windows open, one with a single tab and one with two tabs in it.
Running my code I always get the MainWindowTitle for the window and tab that I had last active - all the others remain empty. The strange thing is that the process ID in which the MainWindowTitle is filled is always the same - if I activate the other IE window or tab before running my code, the process ID is always the same:
if ( !processes.Any() )
{
MessageBox.Show( "TODO - No matching process found" );
return;
}
if ( processes.Count() > 1 )
{
foreach ( Process currentProcess in processes )
{
// More than one matching process found
checkedListBox1.Items.Add( currentProcess.Id + " - " + currentProcess.MainWindowTitle + " - " + currentProcess.ProcessName );
}
return;
}
Output could therefore be for the first run like:
4824 - - iexplore
3208 - - iexplore
4864 - Google - Windows Internet Explorer - iexplore
Next run (with the other IE window selected beforehand):
4824 - - iexplore
3208 - - iexplore
4864 - id Software - Windows Internet Explorer - iexplore
I've read about this post, but I didn't get any further with my problem (and it seems to go into a somewhat different direction anyway).
Why do I always only get one non-empty MainWindowTitle?
Remember that internet explorer uses a hosting model - one iexplore.exe instance hosts the internet explorer frame, the other iexplore.exe instances just display the contents of tabs.
The only IE instance with a top level window is the iexplore.exe process which hosts the frame.
This article discusses the multi-process architecture of various web browsers. As I understand it, browsers are moving to a multi-process model - that way a failure in one web page won't affect other pages. This article goes into more detail about IE's multi-process model.
One option to make this happen reliabely (see comments above) is to implement a BHO - esp. the DWebBrowserEvents2::WindowStateChanged Event is usefull in this scenario.
BHOs are implementations of a bunch of COM interfaces and get loaded into the browser process/each tab... best way to implement them is in C++ IMO.
But it is certainly possible to do so in .NET (although not recommended):
http://www.codeproject.com/Articles/350432/BHO-Development-using-managed-code
http://www.codeguru.com/csharp/.net/net_general/comcom/article.php/c19613/Build-a-Managed-BHO-and-Plug-into-the-Browser.htm
AddIn-Express for IE (commercial library for .NET-based BHOs)
I had the same problem. With Teamviewer Host, we have the QuickConnect Button on some Application. In my case WinWord. If you remove or disable the QuickConnect, the MainWindowTitle will be enhanced
Related
I am using C# , Selenium , AutoIt and Google Chrome.
I can launch the browser, and can see the authentication pop up.
Pop up window disappears when below code is executed and after that the browser stays there forever.
autoItX3 autoIt = new AutoItX3();
Driver.Instance.Manage().Window.Maximize();
Driver.Instance.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(2);
try
{
Driver.Instance.Navigate().GoToUrl(Driver.BaseAddress);
}
catch
{
return;
}
autoIt.WinWait("Authentication Required");
autoIt.WinActivate("Authentication Required");
autoIt.Send("admin");
autoIt.Send("{TAB}");
autoIt.Send("pass");
autoIt.Send("{ENTER}");
Driver.Instance.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(-1);
You are trying to automate a child window.
Autoit doesn't see child windows untill told to.
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
Allows the window search routines to search child windows as well as
top-level windows. 0 = (default) Only search top-level windows 1 =
Search top-level and child windows
hard to make comment without knowing the internals of the authentication implementation on the server. One thing is sure - it is a bad idea from security view because parameters appended to the URL are not secure.
like : http://myURL.com/index.jsp/j_security_check?j_username=username&j_password=password
or
"http://username:password#www.example.com/")
this is what worked for me according to our internal authentication :
https://myURL.com/login/Login.aspx?usestandardlogin=1
so its => "http:YouURL.com" + "?" + "usestandardlogin=1"
now I am not seeing any pop up , it just re-direct me on login.
We are making a web browser to experiment with Oracle's ADT/Forms technology. All it needs to do is go to the web address and run the Java applet.
I'm using (trying to, at least) CefSharp3 (fresh clone from https://github.com/cefsharp/CefSharp).
I created a WPF project for this, got it working (I can navigate to Google, here, Oracle, etc) however, when I navigate to our Java applet I seem to get nothing but a blank screen.
I have set browser-attributes
"JavaDisabled"
"PluginsDisabled"
"WebSecurityDisabled"
(grasping at straws there!) appropriately and still I only see a blank screen.
I'm wondering if maybe the app does not have permissions to the JRE? Maybe the JRE needs to be included in the project?
This is the result of the Debug file (after a fresh run that ONLY goes to the Java applet)
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:ERROR:renderer_main.cc(226)] Running without renderer sandbox
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
The Java applet works no problem in Firefox, Chrome, IE, and Chromium (with WinForms). It could just be that WPF and Java don't jive.
Here's some code! -- it's not much, but it doesn't take much to use this framework -- I AM quite impressed.
public partial class MainWindow : Window
{
public MainWindow() {
InitializeCef();
InitializeComponent();
SetBrowserSettings();
((IWebBrowser)webBrowser).Load("URL_To_Java_Applet");
}
private void InitializeCef() {
var settings = new CefSharp.CefSettings()
{
PackLoadingDisabled = true
};
settings.IgnoreCertificateErrors = true; // could be preventing the JRE?
Cef.Initialize(settings);
}
private void SetBrowserSettings() {
BrowserSettings settings = new BrowserSettings();
settings.JavaDisabled = false;
settings.PluginsDisabled = false;
settings.WebSecurityDisabled = true; // desperate attempt to allow JRE to run!
webBrowser.BrowserSettings = settings;
}
}
Looks like you're right...
It could just be that WPF and Java don't jive.
Try with WinForms, not WPF where prospects doesn't look good (note WPF run in OSR mode)
See this CEF forum thread
update: I tried with http://java.com/en/download/installed8.jsp and Win32 builds of CefSharp.Winforms|Wpf.Example - they both work as expected with JRE 7.67 x86. Of course the x64 Examples didn't work as I don't have a x64 JRE on my PC.
I'm trying to write a simple program that should search in Firefox window for duplicated tabs (checking the url of the tab) and then close the found duplicated tabs.
The idea is simple, but the implementation seems a nightmare.
Doing a lot of researchs messing with WinAPI I've found nDde library, which could retrieve the url of the current tab easy like this example:
VB.NET
Imports NDde.Client
Using dde As New DdeClient("Firefox", "WWW_GetWindowInfo")
dde.Connect()
Dim Url As String = dde.Request("URL", Integer.MaxValue).
Trim({ControlChars.NullChar, ControlChars.Quote, ","c})
MessageBox.Show(Url)
dde.Disconnect()
End Using
C#:
using (DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo")) {
dde.Connect();
string Url = dde.Request("URL", int.MaxValue).Trim({
ControlChars.NullChar,
ControlChars.Quote,
','
});
MessageBox.Show(Url);
dde.Disconnect();
}
//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: #telerik
//Facebook: facebook.com/telerik
//=======================================================
But my knowledges about this library or dde in general are zero, so what I'm doing by the moment is sending ctrl+Tab keys to Firefox to change between tabs to get the url of each tab and then close duplicated founds sending ctrl+w, but this way I have not a reference point to know which tab was the "starting point" to know when I need to stop the dup-tab searching 'cause the first checked url could have a duplicated tab too, and also I can't know the exact number of opened tabs to have an Index reference.
I'm lost.
My question is, this library (or another library related to dde, or another totally different way) could retrieve at least one of those things in a dynamic way?:
· The url of the first tab, I mean the tab that is at the top-left, the first of all opened tabs.
· The total amount count of opened tabs.
· The url of all tabs.
There is already a Firefox extension that:
https://addons.mozilla.org/en-US/firefox/addon/duplicate-tabs-closer/
Using the answer in this question I can get the "screen" count. However, this doesn't seem to work with monitors that are set to "duplicate" (one monitor is reported instead of 2). My application prompts a user to switch from VGA to HDMI (this is on a device with both output ports), and then puts a "can you see this?" prompt on screen to verify that both video ports are working.
I am trying to detect that the switch has happened before showing the prompt, but due to the above mentioned problem the code does not see the monitor count decrement, then increment (that is how I am detecting the switch).
How can I detect the video device switch if everything is set to duplicate? The existing code works if the monitors are set to "extend". There is an internal video device that is always present as well (not trying to test this one).
See This question and use the provided (and fixed in the answer) wrapper for QueryDisplayConfig.
change the signature of the import to have out DisplayConfigTopologyId topology as the last parameter.
Use the QueryDisplayFlags.DatabaseCurrent for the display flags, otherwise you'll get status 87 (invalid parameter)
After calling QueryDisplayFlags the topology will be Clone, Extend etc.
call the method...
var status = CCDWrapper.QueryDisplayConfig(
CCDWrapper.QueryDisplayFlags.DatabaseCurrent,
ref numPathArrayElements, pathInfoArray, ref numModeInfoArrayElements,
modeInfoArray, out currentTopologyId);
In my tests numPathArrayElements always came back as the number of monitors currently In Use. If I changed it to "Show Only Screen 1", It said 1 screen, topology internal. "Show Only Screen 2" came back with 1 screen external. "Cloned" showed 2 screens.
James Barrass' answer didn't work for me. I ended up going with the answer here: link
Here's the code:
public static int GetScreenCount()
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PnPEntity where service =\"monitor\"");
return searcher.Get().Count;
}
How do I retrieve the starting time of a process using c# code? I'd also like to know how to do it with the functionality built into Widows, if possible.
public DateTime GetProcessStartTime(string processName)
{
Process[] p = Process.GetProcessesByName(processName);
if (p.Length <= 0) throw new Exception("Process not found!");
return p[0].StartTime;
}
If you know the ID of the process, you can use Process.GetProcessById(int processId). Additionaly if the process is on a different machine on the network, for both GetProcessesByName() and GetProcessById() you can specify the machine name as the second paramter.
To get the process name, make sure the app is running. Then go to task manager on the Applications tab, right click on your app and select Go to process. In the processes tab you'll see your process name highlighted. Use the name before .exe in the c# code. For e.g. a windows forms app will be listed as "myform.vshost.exe". In the code you should say
Process.GetProcessesByName("myform.vshost");
Process has a property "StartTime":
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.starttime.aspx
Do you want the start time of the "current" process? Process.GetCurrentProcess will give you that:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.getcurrentprocess.aspx
In Code
Suppose you want to find the start time of Notepad, currently running with PID 4548. You can find it, using the PID or the process name, and print it to the debug window like this:
//pick one of the following two declarations
var procStartTime = System.Diagnostics.Process.GetProcessById(4548).StartTime;
var procStartTime = System.Diagnostics.Process.GetProcessesByName("notepad").FirstOrDefault().StartTime;
System.Diagnostics.Debug.WriteLine(procStartTime.ToLongTimeString());
In Windows
You can use Process Explorer, which has an option to display the process start time, or you can list all the currently running processes, and their start times, from the command line with the following:
wmic process get caption,creationdate
You can get process metadata by inspecting the Process object returned by Process.GetProcessesByName().
System.Diagnostics.Process.GetProcessById(xxx).StartTime;//fails for certain processes with access denied