Want to use .Net ShowWindow() function

I want to use the .Net function ShowWindow() so that I can maximize a window by passing the window handle. Is there a package I need to include? If not, how do I make this accessible in UiPath?

You might be able to take care of that with an Invoke Code activity but I’m not certain.

I could, if I was able to get UiPath to recognize the function.

ShowWindow() is a part of Win32 API and you need a DLL call to invoke it. Unfortunately, there doesn’t seem be any easy way to do that in UiPath unless you want to create a custom activity/library.

May I ask why you can’t solve it with the Attach Window and Maximize activities? How do you get hold of the window handle?

A workaround I can think of is to invoke a script that would call ShowWindow() inside the user32.dll for you.

Since some of the users of this attended robot will have multiple windows open to the same page, the robot looks for browsers based on selector including a URL: “< html app=‘chrome.exe’ url=‘viewCall.cfm’ idx=’{0}’ />”, using an incrementing Int32 variable to populate the {0} in the URL string.

I use this formatted selector in a BrowserScope activity to attempt to locate the browser, with ContinueOnError set to True and a time out of 2 seconds. If found, I use the UiBrowse variable specified in the activity to access the browser. I do not start reading from the pages until the browsers are actually found. In the event multiple browsers are found, the robot presents a dialog to allow the user to select the desired browser window (based on patient name read from each page).

The problem is that sometimes the browser window cannot be found by the robot, even though it is clearly visible on the screen. My thought was to get all Chrome processes and attempt to maximize each window to ensure it is visible to the robot. Since I have the window handle, I’d like to be able to use the ShowWindow function, passing the handle, to maximize the window.

I don’t think it would make much of a difference if the window is maximized or not. But if you want to test either way here’s a workaround I implemented using the Run auto hot key script activity. You will need to install the package UiPath.Script.Activities if you don’t have it installed already.

The attached example will search for all Notepad windows and maximize them via a DLL call. ShowWindowAHK.zip (1.7 KB)

Code in Win32.ahk:

ShowWindow(handle,  nCmdShow) {
	DllCall("ShowWindow", "UInt", handle, "Int", nCmdShow)
}
1 Like

This works great! Thanks for the assist!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.