Sign in to follow this  
Followers 0
grimmlock

If Winexists

16 posts in this topic

Good Morning,

I have a wierd question, that I have not been able to solve. If anyone has used Team Viewer before you know that when you are done accessing a PC (using the Personal Free Version) that the TeamViewer window pop up. So I have created a small little script that runs and closes the window if it exists.

 
If winexists('TeamViewer', '') Then
winclose('Teamviewer', '')
Endif
 

 

However I just ran into a snag where if I open a browser and try to login to my Team Viewer account it closes the browser, because I have told the script to close any and all windows that have TeamViewer at the title to close. Is there a way to have the script know the difference between a browser tab and the app? That way I can access my TeamViewer account using a browser but still have the TeamViewer App windows close.

Thanks in advance.

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites



The app's popup window has more than just TeamViewer in the title, try looking for that instead. Or use the class name of the window.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Unfortunately the title only has TeamViewer in the title for the app. I am trying to locate the Class name but finding it difficult. I have used the Autoit tool as well as WinGetHandle, both with no luck.

Thanks,


Thanks

Grimm

Share this post


Link to post
Share on other sites

You'd have to post the output of autoitwindow info tool.  You have to give us something to go off of.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

*Updated* My apologizes what output would you like to see, meaning what tabs or information? I took a screenshot and attached it.

Thanks,

post-76479-0-53881200-1390847265_thumb.p

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

That class is an 'enabled popup'.

If you have the handle of the parent window, you can use this;

$hpopup = _WinAPI_GetWindow($hParent,6)

That's a really helpful function to dynamically grab any message from the application.  Then use the title and text of the window to know what actions to perform.

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I've done this.  I do kinda forget how exactly though.  I suggest an array of block strings.

$a_block[0] = "Google Chrome"

$a_block[1] = "Internet Explorer"

$a_block[2] = "Some Other String to Block"

When you find one of the block strings in the window title, don't close the window.

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

Data from Summary Tab :)

>>>> Window <<<<
Title:    TeamViewer
Class:    #32770
Position:    687, 281
Size:    546, 478
Style:    0x96CA08CC
ExStyle:    0x00050101
Handle:    0x00010178

>>>> Control <<<<
Class:    
Instance:    
ClassnameNN:    
Name:    
Advanced (Class):    
ID:    
Text:    
Position:    
Size:    
ControlClick Coords:    
Style:    
ExStyle:    
Handle:    

>>>> Mouse <<<<
Position:    830, 288
Cursor ID:    0
Color:    0xBBD0F0

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Control Remote Computer
Please enter your partner's ID in order to control the remote computer.
Partner ID
772020948
772020948
Remote control
File transfer
Connect to partner
Allow Remote Control
534 671 829
Please tell your partner the following ID and password if you would like to allow remote control.
v442du
Use your personal password to access this computer from anywhere.


>>>> Hidden Text <<<<
Initializing security settings...
Statisch
VPN
Abort connection
Personal
Password
Host Meeting
Schedule meetings
Schedule a meeting
My meetings
Start instant meeting
Abort meeting
Join Meeting
Please enter the ID of the Meeting you would like to participate in.
Meeting ID
m
Your name

Join meeting
Abort connection
Start a spontaneous meeting and invite participants to it.
Presentation mode
Video mode

Thanks,


Thanks

Grimm

Share this post


Link to post
Share on other sites

When I end a TV session I get this pop up dialog.

>>>>> Window <<<<

Title: Sponsored session

Class: #32770

Position: 434, 280

Size: 491, 168

Style: 0x94C000CE

ExStyle: 0x00010109

Handle: 0x00080460

>>>> Control <<<<

Class: Static

Instance: 2

ClassnameNN: Static2

Name:

Advanced (Class): [CLASS:Static; INSTANCE:2]

ID: 20097

Text: This was a free session sponsored by www.teamviewer.com.

TeamViewer sessions are free of charge for personal use.

We thank you for playing fair!

Position: 81, 11

Size: 386, 75

ControlClick Coords: 126, 41

Style: 0x50020000

ExStyle: 0x00000024

Handle: 0x000404B8

>>>> Mouse <<<<

Position: 644, 357

Cursor ID: 0

Color: 0x000000

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Like!

Buy License

OK

This was a free session sponsored by www.teamviewer.com.

TeamViewer sessions are free of charge for personal use.

We thank you for playing fair!

>>>> Hidden Text <<<<

4

Show my desktop

Don't show this dialog again

What you're showing is the main window for TV.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I got it, it took me forever but this seems to work,

 
$tview = ""
$thandle = WinGetTitle("[ACTIVE]")

If $thandle = "TeamViewer Management Console - Mozilla Firefox" Then
    $tview = "Console"
        If $tview = "Console" Then
        EndIf
ElseIf $thandle = "TeamViewer" Then
    $tview = "App"
        If $tview = "App" Then
            WinClose("TeamViewer")
        EndIf
EndIf
 

Thanks for everyone's help

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I disagree with that being the best answer.

Also, you should be using the handle of the window, or the first instance of 'TeamViewer' will close, and possibly not the one you expect to close.

Or, winclose("[ACTIVE]")

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I didn't realize you were starting a session from the web browser and not the application. 

You should look for the text of the window to match, as well as the title, this way you know you're closing the right window.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#14 ·  Posted

I also use the WinGetText("text here") funct. to grab infos I need for my windows. But sometimes it unfortunately doesn't find the text I need. It really depends on the type of windows (Visual Studio, SQL Server, Chrome.. etc.)

Share this post


Link to post
Share on other sites

#15 ·  Posted

I also use the WinGetText("text here") funct. to grab infos I need for my windows. But sometimes it unfortunately doesn't find the text I need. It really depends on the type of windows (Visual Studio, SQL Server, Chrome.. etc.)

Share this post


Link to post
Share on other sites

#16 ·  Posted

I also use the WinGetText("text here") funct. to grab infos I need for my windows. But sometimes it unfortunately doesn't find the text I need. It really depends on the type of windows (Visual Studio, SQL Server, Chrome.. etc.)

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
Sign in to follow this  
Followers 0

  • Similar Content

    • afallenhope
      By afallenhope
      Hello all I am trying to use this function to detect if a specific window is running. Then for it to activate it and send an ALT+F command to close the window. But I cannot seem to get it to detect the window and subsequently the rest of the code does not work. 
      #include <MsgBoxConstants.au3> Handleit() Func Handleit() If WinExists("[CLASS:MsiDialogCloseClass]","InstallShield") Then WinActivate("[CLASS:MsiDialogCloseClass]","Installshield") Send("!f") Else MsgBox($MB_SYSTEMMODAL, "", "Uhhh... something didn't work. Fix it!") EndIf EndFunc Is there anything that I can substitute for the CLASS? 
      Thank you for taking the time to read my question! 
      -Richard
    • NiceBoy1234
      By NiceBoy1234
      I want to check if the cmd.exe + window of it is running, if it is running I want to put the window to the foreground, but somehow this does not work:
       
      Local $sCommandlinePath = "C:\Windows\system32\cmd.exe" RunCm() Func RunCm() If FileExists($sCommandlinePath) Then If ProcessExists("cmd.exe") Then If WinExists("[CLASS:ConsoleWindowClass]") And WinActive("[CLASS:ConsoleWindowClass]") Then Local $hCmdWindow = WinGetHandle("[CLASS:ConsoleWindowClass]") WinSetOnTop($hCmdWindow, "", $WINDOWS_ONTOP) EndIf Else Local $iCmMax = Run($sCommandlinePath, "", @SW_SHOWMAXIMIZED) EndIf EndIf EndFunc I started the command line and put another window above it then I started my script and it did not put the command line window to the foreground.
    • kcvinu
      By kcvinu
      Hi all,
      I did some experiments with FileOpenDialog function. I did this from a GUI's button click. Then i wrote another function to the same script to find the file open dialog window with WinExists function. But i can't detect the presence of the open dialog with "WinExists" function. I think when the FileOpenDialog is came, then the main script is not focused. Then i tested it with another script. That is - I run the first function (the one which contains the gui code and the fileOpenDialog code) from another IDE. And i run th window detecting function (the WinExists function) from SciTE. Then it worked. So my qustion is- Is it possible to do this task from the same script ?
      This is the code that not working
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> $hGUI = GUICreate("Window", 500, 400, -1, -1) Global $hButton = GUICtrlCreateButton("Button", 144, 179, 202, 60) GUISetState() While 1 Sleep(30) $hMsg = GUIGetMsg() Switch $hMsg Case $GUI_EVENT_CLOSE Exit Case $hButton BtnClick() EndSwitch Checker() WEnd Func BtnClick() Local $sPath = FileOpenDialog("TestWindow","D:\AutoIt Works\EXEs","(*.*)") ConsoleWrite($sPath & @LF) EndFunc Func Checker() if WinExists("TestWindow") = 1 Then ConsoleWrite("Yes, it is there" & @CRLF) EndIf EndFunc After first failure, i ran the Checker function from SciTE and this gui function from another IDE. Then it worked. 
    • grimmlock
      By grimmlock
      I am looking for some help with my code. I want to be able to have this script always run, and append a file each time a program is opened adding a new line. Here is my code, and help would be greatly appreciated.
      #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <File.au3> Local $aLines, $iCount = 0 local $hDate = @YEAR & '-' & @MON & '-' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC local $hfile=FileOpen("C:\Users\public\Desktop\new1.txt", $FO_APPEND) Local $hComputername = @ComputerName ; Computer Name Local $hUsername = @UserName ; User Name While 1     If $hfile = -1 Then         SplashTextOn("Error", "Unable to open and append the log file.", 300, 50)         Sleep(2000)         SplashOff()     EndIf         _FileReadToArray("C:\Users\public\Desktop\new1.txt", $aLines)         If Not @error Then             ; if the file exists look for the ID starting on the last line             For $i = $aLines[0] To 1 Step -1                 If StringLeft($aLines[$i], 2) == "id" Then             ; get the ID number                     $iCount = Int(StringRegExpReplace($aLines[$i], "id(\d*):.*", "$1"))                     ExitLoop                 EndIf             Next             ; Check we found an ID             If $i = 0 Then                 MsgBox(0, "Error", "No line id found")                 Exit             EndIf         EndIf     If WinExists("[Class:Notepad]", "") Then             FileWrite($hfile, _LineID() & '|' & $hDate & '|' & $hComputername & '|' & "Notepad was opened by " & $hUsername & @CRLF)             Sleep(10)             FileClose($hfile)             Sleep(1000)     EndIf WEnd Func _LineID()     $iCount += 1     Return "id" & StringFormat("%04i", $iCount) & ": " EndFunc ;==> LineID Thanks!
    • atnextc
      By atnextc
      I have been trying to write a script to silently install CRM Outlook client for about the past 6 days. No matter what I have tried this doesn't seem to be doing anything.

      Code is below. Any help is appreciated.


      Opt("TrayIconDebug",1) ShellExecute("R:\IT\SoftLib\CRM2011\CRM2011-Client-ENU-i386\SetupClient.exe") winwait("Microsoft Dynamics CRM 2011 for Outlook Setup") WinActivate("Microsoft Dynamics CRM 2011 for Outlook Setup") WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","I &accept the license agreement") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","I &accept the license agreement",1007) WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","&Next") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","&Next",1008) WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","Install Now") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","&Install Now",1019) WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","The installation completed successfully.") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","&Close",1038)