How to handle windows

Handle v4.22

By Mark Russinovich

Published: June 14, 2019

Download Handle (887 KB)

Introduction

Ever wondered which program has a particular file or directory open? Now you can find out. Handle is a utility that displays information about open handles for any process in the system. You can use it to see the programs that have a file open, or to see the object types and names of all the handles of a program.

You can also get a GUI-based version of this program, Process Explorer, here at Sysinternals.

Installation

You run Handle by typing «handle». You must have administrative privilege to run Handle.

Usage

Handle is targeted at searching for open file references, so if you do not specify any command-line parameters it will list the values of all the handles in the system that refer to open files and the names of the files. It also takes several parameters that modify this behavior.

usage: handle [[-a] [-u] | [-c [-l] [-y]] | [-s]] [-p

Parameter Description
-a Dump information about all types of handles, not just those that refer to files. Other types include ports, Registry keys, synchronization primitives, threads, and processes.
-c Closes the specified handle (interpreted as a hexadecimal number). You must specify the process by its PID.
WARNING: Closing handles can cause application or system instability.
-l Dump the sizes of pagefile-backed sections.
-y Don’t prompt for close handle confirmation.
-s Print count of each type of handle open.
-u Show the owning user name when searching for handles.
-p Instead of examining all the handles in the system, this parameter narrows Handle’s scan to those processes that begin with the name process. Thus:
handle -p exp
would dump the open files for all processes that start with «exp», which would include Explorer.
name This parameter is present so that you can direct Handle to search for references to an object with a particular name.
For example, if you wanted to know which process (if any) has «c:\windows\system32» open you could type:
handle windows\system
The name match is case-insensitive and the fragment specified can be anywhere in the paths you are interested in.

Handle Output

When not in search mode (enabled by specifying a name fragment as a parameter), Handle divides its output into sections for each process it is printing handle information for. Dashed lines are used as a separator, immediately below which you will see the process name and its process id (PID). Beneath the process name are listed handle values (in hexadecimal), the type of object the handle is associated with, and the name of the object if it has one.

When in search mode, Handle prints the process names and id’s are listed on the left side and the names of the objects that had a match are on the right.

More Information

You can find more information on the Object Manager in Windows Internals, 4th Edition or by browsing the Object Manager name-space with WinObj.

Download Handle (887 KB)

How to handle multiple windows in Selenium?

By Neha Vaidya, Community Contributor — June 26, 2020

Software testing plays a vital role in creating error-free products that offer seamless user experiences. Therefore, it is essential to test the software before putting it into production.

As technology advances, it is necessary to adopt automation testing into the development pipeline. Selenium is the most widely used framework for automated software testing of a website. Every website must be tested by putting it through multiple real-world user scenarios. One such scenario is the handling of multiple windows. This article will discuss how to automate this action with Selenium so that the website’s behavior can be monitored by testers.

Handling Multiple Windows in Selenium

The user scenario being automated here is: Open a new tab and then switch back to the last window to complete the other pending activities. In such scenarios, Selenium helps to handle multiple windows through window handlers and javascript executors.

What is a window handle?

It is a unique identifier that holds the address of all the windows. Think of it as a pointer to a window, which returns the string value. It is assumed that each browser will have a unique window handle. This window handle function helps to retrieve the handles of all windows.

Syntax

  1. get.windowhandle(): This method helps to get the window handle of the current window
  2. get.windowhandles(): This method helps to get the handles of all the windows opened
  3. set: This method helps to set the window handles in the form of a string. set set= driver.get.windowhandles()
  4. switch to: This method helps to switch between the windows
  5. action: This method helps to perform certain actions on the windows

These are some of the methods that will be used to handle multiple windows in Selenium.

Example of handling multiple windows

Scenario: Navigate to the Browserstack home page. This is the parent window. From the parent window, let’s see how to handle the child windows and then again navigate back to the parent windows.

Steps to execute:

  1. Get the handle of the parent window using the command: String parentWindowHandle = driver.getWindowHandle();
  2. Print the window handle of the parent window.
  3. Find the element on the web page using an ID which is an element locator.
  4. Open multiple child windows.
  5. Iterate through child windows.
  6. Get the handles of all the windows that are currently open using the command: Set allWindowHandles = driver.getWindowHandles(); which returns the set of handles.
  7. Use the SwitchTo command to switch to the desired window and also pass the URL of the web page.

Refer to the complete program below.

Before running the code, one should do a quick check on 6 things to avoid while running selenium scrips. Check it out.

Output:

On executing the parent window handle, it will open multiple child windows and then navigate back to the final window handle.

Now let’s perform some actions on the Browserstack website.

  • Use the javascriptexecutor to scroll down through a page.
  • Find the element using XPath and send keys (which is of the form string) to that particular element location.
  • Declare the web element Link to click on a particular link on the page. In this case, the link must open in a new window.
  • Get the window handles of all the windows and print them in a sequential manner.
  • Switch to the parent window and check if the title matches. If it does, scroll down the page using the javascriptexecutor.
  • Find another element on the web page using the element locator and specify the position of the new window.
  • Switch back to the parent window and scroll down through the page.


Code Snippet

On executing the code above, it will launch multiple windows and the window handle will be retrieved. Run the code, automate user navigation through multiple windows, and ensure the website works perfectly in real user conditions. With Selenium WebDriver, ensure that websites offer an optimal user experience in all possible circumstances.

How to handle “End Task” from Windows Task Manager on a background process?

I wrote a simple test program (TestProgram.exe) to learn how to handle the CTRL_CLOSE_EVENT and here are my observations and my question:

1) When I double click TestProgram.exe to launch it, and if I now go to Task Manager, TestProgram.exe is listed under «Apps». When I do «End Task» on TestProgram.exe, my handler for CTRL_CLOSE_EVENT is getting called.

2) When I open a command prompt and launch TestProgram.exe, it is listed under «Background Processes» under Task Manager and doing an «End Task» on the same doesn’t result in a CTRL_CLOSE_EVENT.

My real application is used as described in case 2) above. I want to do some cleanup when users do an End Task on my app (which is listed under Background processes in Task Manager).

10 seconds to do any necessary cleanup. Also, as I originally mentioned, why am I able to handle it in case 1 but not case 2 above? – Krishna Aug 27 ’13 at 0:39

2 Answers 2

In general, when a process is listed as an «Application», it means Task Manger has detected the process has a GUI, and an «End Task» on a GUI will first attempt to graceful close the GUI via standard WM_CLOSE and/or WM_QUIT messages before then resorting to a brute-force termination of the GUI’s process via TerminateProcess() . On the other hand, doing an «End Task» on a «Background Process» will perform a brute-force termination immediately.

So in your situation, double-clicking on the .exe file results in a new dedicated console process that is running just your app by itself, so the console’s GUI gets flagged as an «Application», but when you open a console window first and execute your .exe via the command-line, your app is running within the existing console and is sharing the console’s original GUI, so your app does not have its own GUI and thus gets flagged as a «Background Process» instead.

When a process is terminated (not closed) nothing realy can be done unless you start do some hooking, either by hooking TerminateProcess or NtTerminateProcess in the Task Manger process, example of how it works:

This hooks TerminateProcess in the same process, you need to ship it in a DLL and inject it in the Task Maneger process, didn’t test it. But this method is overwork and not safe, some AV products may detect it as harmful program.

A simple solution is to clean up on the program start-up as @Martin James suggested. On your program start-up create a file or use the registry to store some value like 0 , if the program was closed, received WM_CLOSE if it’s GUI or CTRL_CLOSE_EVENT if you closed the command prompt, you do the clean-up and store 1 .

On the next start-up you you check back that value if it stills 0 , this mean do the program was not closed properly, do do the clean up, if it’s 1 no need to the clean-up, store 0 and move on.

Many programs use this method to detect if the program was closed properly.

How to handle Windows 10 updates

Step 1: Understand that there are updates, and then there are updates.

Contributing Editor, Computerworld |

Confused about how updates work in Windows 10? Join the club. Over the years, Microsoft has transformed what was once a straightforward procedure into an ever-changing, often complicated process that varies according to whether you have Windows 10 Home, Windows 10 Pro, or an enterprise or education edition — and that varies according to the specific version number of the operating system. As a result, there have been lots of misperceptions about how Windows Update works in Windows 10, and how to best use it.

With this article, we hope to make things clearer for you. We’ve delved deep into Windows Update and come up with answers to users’ most pressing questions: whether you have to accept all updates, whether you can uninstall existing updates, and how to reduce the bandwidth some updates use. We’ve also included some extras, like how to stop all updates if you want.

You can check for new updates in Settings. (Click any image in this article to enlarge it.)

We have updated this article for the current Windows 10 release, the October 2020 Update (also called version 20H2). The features that are described here and the screenshots you see may differ from what you see if you have an older version of Windows 10.

Read on for details.

To continue reading this article register now

How to handle the new window in Selenium WebDriver using Java?

This is my code:

Now I have the next error:

Exception in thread «main» org.openqa.selenium.NoSuchElementException: Unable to find element with txtEnterCptCode (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 404 milliseconds.

6 Answers 6

It seems like you are not actually switching to any new window. You are supposed get the window handle of your original window, save that, then get the window handle of the new window and switch to that. Once you are done with the new window you need to close it, then switch back to the original window handle. See my sample below:

I have an utility method to switch to the required window as shown below

It will take you to desired window once title of the window is passed as parameter. In your case you can do.

and then again switch to parent window using the same method

Webdriver parentDriver = Utility.getHandleToWindow(«titleOfParentWindow»);

This method works effectively when dealing with multiple windows.

I have a sample program for this:

public class BrowserBackForward <

i was having some issues with windowhandle and tried this one. this one works good for me.

Читайте также:  Плеер для mac os с эквалайзером
Оцените статью