Jump to content
Combo

Having trouble with 2 windows with same title

Recommended Posts

Combo

Hi, we have a program that we'd like to login automatically then hide.

Problem is the login window and the program windows itself have same title,

so i googled and one of the solution is to use text inside window to differentiate them.. 

I tried this but it won't work.. any idea why? text1 is login window, text2 is the program window

#RequireAdmin
$smartbilling = "E:\SmartLauncher.exe"
$hWnd = "SmartBilling"
$pasd = "1234"
$text1 = "Pemilik"
$text2 = "Manajemen Server"
Func Logon()
If WinExists($hWnd, [$text1]) Then
   Send("$pasd{ENTER}")
   WinWaitActive($hWnd, [$text2]) Then
   WinSetState($hWnd, "", @SW_HIDE)
Elseif WinExists($hWnd, [$text2]) Then
   WinSetState($hWnd, "", @SW_HIDE)
Else
   Run($smartbilling)
   WinWaitActive($hWnd, [$text1])
   Send("$pasd{ENTER}")
   WinWaitActive($hWnd, [$text2]) Then
   WinSetState($hWnd, "", @SW_HIDE)
EndIf
EndFunc

This is the pic of both windows,

I circled text1 and text2

KYgw6Sl.jpg

 

Edited by Combo

Share this post


Link to post
Share on other sites
iamtheky

maybe its just your send and winwaits being incorrectly formatted

Send($pasd & "{ENTER}")

 

WinWaitActive($hWnd, $text1)

 

the brackets are there to show the parameter is optional, they are not to be included

 

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Combo

maybe its just your send and winwaits being incorrectly formatted

Send($pasd & "{ENTER}")

 

WinWaitActive($hWnd, $text1)

 

the brackets are there to show the parameter is optional, they are not to be included

Sending password worked, i tried it separately without other function.

I think the problem is reading text within windows.
When i run that script it only asks for admin rights then nothing happens

Is there's any other method to differentiate 2 windows with same title?

Edit : fixed it, it opens the login windows, but now it won't login.. I think it still can't read the text inside windows..

#RequireAdmin
$smartbilling = "E:\SmartLauncher.exe"
$hWnd = "SmartBilling"
$hWnd2 = "SB News"
$pasd = "1234"
$text1 = "Pemilik"
$text2 = "Manajemen"
If WinExists($hWnd, $text1) Then
   Send($pasd & "{ENTER}")
   WinWaitActive($hWnd, $text2)
   WinSetState($hWnd, "", @SW_HIDE)
Elseif WinExists($hWnd, $text2) Then
   WinSetState($hWnd, "", @SW_HIDE)
Else
   Run($smartbilling)
   WinWaitActive($hWnd, $text1)
   Send($pasd & "{ENTER}")
   WinWaitActive($hWnd, $text2)
   WinSetState($hWnd, "", @SW_HIDE)
EndIf

Edit2 : Yeah, it's definitely reading text issue, i removed text1 and it logged in.. 

So which text can be used for my case?

Edited by Combo

Share this post


Link to post
Share on other sites
Combo
Posted (edited)

Hi.. well 3 years later i  still need to get this working..

#RequireAdmin
$smartbilling = "C:\Program Files (x86)\Smartbilling_Counter\SmartLauncher.exe"
$hWnd = "SmartBilling"
$pasd = "1234"
$text1 = "Pemilik"
$text2 = "Manajemen Server"
If WinExists($hWnd, $text1) Then
   Send($pasd & "{ENTER}")
   WinWaitActive($hWnd, $text2)
   WinSetState($hWnd, "", @SW_HIDE)
Elseif WinExists($hWnd, $text2) Then
   WinSetState($hWnd, "", @SW_HIDE)
Else
   Run($smartbilling)
   WinWaitActive($hWnd, $text1)
   Send($pasd & "{ENTER}")
   WinWaitActive($hWnd, $text2)
   WinSetState($hWnd, "", @SW_HIDE)
EndIf

This one opens the app correctly but it  still wont send the password,

the username is already present, btw

What did i miss here?

 

Running it in editor only gives me this log :

Quote

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\deny\Documents\SB.au3" /UserParams    
+>12:15:48 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
! Your script requires Admin rights while SciTE is running at normal level.
! This means no Console output from the script will be displayed and SciTE will show the script as ended right away.
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\deny\Documents\SB.au3
+>12:15:48 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\deny\Documents\SB.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>12:15:50 AutoIt3.exe ended.rc:0
+>12:15:50 AutoIt3Wrapper Finished.

 

 

 

Edited by Combo

Share this post


Link to post
Share on other sites
careca

Hi, how can i test this? what is the information from the info tool for the control where you want to paste the text?


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
ternal

You might need to do a click in the right box first (so the cursor gets placed to fill in the logon credentials.
This is just a guess but have you tried sending a click or controlclick first?

there is a tool in the autoit directory (or tools menu in scite and its called au3info.

You can use that tool to find the location of the logon input box relative to its parent window

then you can send controlclick to that parentwindow at a fixed x/y.

If the logon box itself shows up on the au3info tool you can even use controlsend directly to that box without even having to activate the screen. however sometimes for some specific controls it fails. I try to keep windows active as much as possible even with controlsend.

 

Share this post


Link to post
Share on other sites
Combo

Hi i removed text1 and text2 and i logged in successfully. The only problem now since the program has same window name between login window and main window, i need to figure out another way to differentiate them since text inside windows doesnt work.

Otherwise it wont be able to tell whether the program is already logged on or not.

I read process handle can be used. But i cant find any clear example, can anyone give me some examples?

I could upload the program but it requires supplied username and password which i cannot share publicly.

 

Share this post


Link to post
Share on other sites
careca
Posted (edited)

WinGetHandle can give you a handle, check help file.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
ternal

get handle's to both windows and then look at the information in the handle's windows,

something like using $array_of_handles = winlist("title of your program")

looping through the array, you can use wingettext or other identification methods(wingetclasslist) to identify the correct window and send the credentials there.

 

look in the helpfile on winlist , wingettext and the for - to loop.

Share this post


Link to post
Share on other sites
Combo
On 23/7/2018 at 2:02 AM, ternal said:

get handle's to both windows and then look at the information in the handle's windows,

something like using $array_of_handles = winlist("title of your program")

looping through the array, you can use wingettext or other identification methods(wingetclasslist) to identify the correct window and send the credentials there.

 

look in the helpfile on winlist , wingettext and the for - to loop.

On 22/7/2018 at 12:59 AM, careca said:

WinGetHandle can give you a handle, check help file.

Ok so i tried modifying the notepad example in wingethandle help page.

#RequireAdmin
#include <MsgBoxConstants.au3>
$smartbilling = "C:\Program Files (x86)\Smartbilling_Counter\SmartLauncher.exe"
$hWnd = "SmartBilling"
Example()
Func Example()
    ; Run Notepad
    Run($smartbilling)

    WinWaitActive($hWnd)
    ; Retrieve the handle of the Notepad window using the classname of Notepad.
    Local $hWnd = WinGetHandle("SmartBilling")
       If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Smartbilling.")
        Exit
    EndIf
    ; Display the handle of the Notepad window.
    MsgBox($MB_SYSTEMMODAL, "", $hWnd)

    ; Close the Notepad window using the handle returned by WinGetHandle.
    WinClose($hWnd)
EndFunc   ;==>Example

It seems to work, it returns a hex values i think,

but the problem is whenever i run this i get different value.

Am i missing something here?

Share this post


Link to post
Share on other sites
careca

You just want to differentiate one window from the other, so, you just have to code it in a way that

when the second window shows up with the same title but different handle, you act on it.

Does this make sense for you?


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Combo
On 23/7/2018 at 11:26 PM, careca said:

You just want to differentiate one window from the other, so, you just have to code it in a way that

when the second window shows up with the same title but different handle, you act on it.

Does this make sense for you?

yea kind of, but coding it might be difficult for beginners like me. 

Any examples ?

Share this post


Link to post
Share on other sites
Juvigy

Change this:

Run($smartbilling)

To this:

$yourhandle = Run($smartbilling)

So now $yourhandle will contain the pointer/handle to the window that you started. It will be different every time you run your code. But you will have it , so you can compare it to the handles of the other windows and determine which one is the one you want!

Share this post


Link to post
Share on other sites
ternal
Posted (edited)

I think you need this from what you said. Now I couldn't test this out .There might still be a bug.

$hSmart_Billing =  Run($smartbilling) ; run  $smartbilling 
If WinWaitActive( $hSmart_Billing, "",  30) = 0 Then MsgBox(0, "Error", "Timeout occurred while waiting on the program to appear"); wait till the program is active if it does not become active within 30 sec display timeout error
$tSmart_Billing = WinGetTitle($hSmart_Billing); get the title of the window you ran
If $tSmart_Billing == "" Then MsgBox(0, "Error", "Failed to retrieve the title of your program")
    
    
;when you need to check for a window with the same title but different handle
$aList_Of_Windows = WinList($tSmart_Billing); get an array of  window title's and handle's 
For $i = 1 to UBound($aList_Of_Windows, 1) - 1 ; run through the array completly
    If $aList_Of_Windows[$i][1] = $hSmart_Billing Then ; $aList_Of_Windows[$i][1] contains the handle of the window winlist found. every pass through $i gets +1 in value so it loops through all windows found with the same title as your original program
        ; this window is the same as the one you ran.
    Else
        ; this window has the title you entered in the winlist function () but a different handle
    EndIf
Next

edit: If you use arrays in the future beware that arrays start at index 0 (for $i = 0 to.... is the correct syntax for most arrays) however the index[0][0] on our array now contains the number of windows found matching your criteria so that one should not be included. you can work with that number as well.

I have learned that in programming creativity is the limiting factor.

Edited by ternal

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×