SharpShooter Posted September 3, 2010 Share Posted September 3, 2010 hellooo i want to know that how can i get the name of file by it's Window name? File name like this: Explorer.exe Window name like this: New Folder by this we can get Process ID, but i want to get Process or file name. $x = WinGetProcess("test") MsgBox(4096, "PID is", $x) how can i do this? Link to comment Share on other sites More sharing options...
SharpShooter Posted September 3, 2010 Author Share Posted September 3, 2010 i just got the solution but now i have another problem. #include <Process.au3> Opt("WinTitleMatchMode", 2) $title = WinGetTitle("Super", "") $pid = WinGetProcess($title) $name = _ProcessGetName($pid) MsgBox(64, "Process Name is: ", $name) but the problem is that if i change "Super" to "super" then it gives nothing. i want it to work on all words even like this "SuPeR" help me please Link to comment Share on other sites More sharing options...
bo8ster Posted September 3, 2010 Share Posted September 3, 2010 You could use the output of WinList with StringCompare. WinList will also have the handle. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
Varian Posted September 3, 2010 Share Posted September 3, 2010 Change corresponding lines to thisOpt('WinTitleMatchMode', 4) $Title = WinGetTitle("[REGEXPTITLE:(?i)super]", "")This is a case insensitive search for the word "super" anywhere in the Title. Just be careful for multiple matches. You can refine the regular expression to narrow down your results and also add class components to narrow down the window search returns Link to comment Share on other sites More sharing options...
SharpShooter Posted September 3, 2010 Author Share Posted September 3, 2010 (edited) i was trying to close a Window but excluding Browsers. i did this: #include <Process.au3> Func _Close($win) Opt("WinTitleMatchMode", 4) $title = WinGetTitle("[REGEXPTITLE:(?i)"&$win&"]", "") $pid = WinGetProcess($title) $name = _ProcessGetName($pid) If Not $name = "Firefox.exe" Or "iexplorer.exe" or "chrome.exe" Then WinClose($win) EndIf ;MsgBox(64, "Process Name is: ", $name) EndFunc _Close("super") but i Failed to do so. what is my mistake in this script? what i am doing wrong? Edited September 3, 2010 by SprinterGuru Link to comment Share on other sites More sharing options...
SharpShooter Posted September 4, 2010 Author Share Posted September 4, 2010 can anybody tell how to get that work? i want to close a window by it's name, but i don't want that it effect browser windows. Link to comment Share on other sites More sharing options...
wakillon Posted September 4, 2010 Share Posted September 4, 2010 (edited) It's not iexplorer.exe, but iexplore.exe Try this#include <Process.au3> _Close("super") Func _Close($win) Opt("WinTitleMatchMode", 4) $title = WinGetTitle("[REGEXPTITLE:(?i)"&$win&"]", "") $pid = WinGetProcess($title) $name = _ProcessGetName($pid) If $name <> "Firefox.exe" And $name <> "iexplore.exe" And $name <> "chrome.exe" Then WinClose($win) EndIf ;MsgBox(64, "Process Name is : ", $name) EndFunc Edited September 4, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
maqleod Posted September 4, 2010 Share Posted September 4, 2010 (edited) can anybody tell how to get that work?i want to close a window by it's name, but i don't want that it effect browser windows.Process Manager SourceOne of my projects is a process manager, it displays all the processes running on the system, windows associated with those processes and will also provide the file on disk associated with that process. It contains all you need to do what you need to do. Look at the source, if you have any questions about any portion of it, ask. Edited September 4, 2010 by maqleod [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
SharpShooter Posted September 4, 2010 Author Share Posted September 4, 2010 can anybody tell how to get that work? i want to close a window by it's name, but i don't want that it effect browser windows. Link to comment Share on other sites More sharing options...
wakillon Posted September 4, 2010 Share Posted September 4, 2010 can anybody tell how to get that work?i want to close a window by it's name, but i don't want that it effect browser windows.Have you tried my modified script ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
SharpShooter Posted September 4, 2010 Author Share Posted September 4, 2010 i got an error when trying to run your script. >"D:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\Documents and Settings\Oley\My Documents\Downloads\Compressed\PM_1.0_Source\Process Manager.au3" D:\Documents and Settings\Oley\My Documents\Downloads\Compressed\PM_1.0_Source\Process Manager.au3 (17) : ==> Error opening the file.: #include <CompInfo.au3> >Exit code: 1 Time: 2.916 Also, i don't know which part of your script i can use to make my script work! Link to comment Share on other sites More sharing options...
SharpShooter Posted September 4, 2010 Author Share Posted September 4, 2010 @ wakillon Yes it worked. Thanks man nowi need to collected other browser exe names to make it work with all. Link to comment Share on other sites More sharing options...
wakillon Posted September 4, 2010 Share Posted September 4, 2010 (edited) Another way #include <Process.au3> #include <Array.au3> $_Title = "explorer" GuiCreate ( $_Title ) GUISetState ( ) Sleep ( 2000 ) _CloseWindowWithString ( $_Title ) Func _CloseWindowWithString ( $_String ) $_BrowserList = 'Firefox.exe,iexplore.exe,chrome.exe,opera.exe,safari.exe' $_BrowserList = StringSplit ( $_BrowserList, ',' ) ; _ArrayDisplay ( $_BrowserList ) $_WinList = WinList ( ) For $_I = 1 To $_WinList[0][0] If StringInStr ( $_WinList[$_I][0], $_String ) <> 0 And Not _ _AlreadyInArray ( $_BrowserList, _ProcessGetName ( WinGetProcess ( $_WinList[$_I][0], "" ) ) ) Then WinClose ( $_WinList[$_I][1] ) Next EndFunc ;==> _CloseWindowWithString ( ) Func _AlreadyInArray ( $_SearchArray, $_Item ) $_Index = _ArraySearch ( $_SearchArray, $_Item ) If @error Then Return False Else If $_Index <> 0 Then Return True Else Return False EndIf EndIf EndFunc ;==> _AlreadyInArray ( ) Edited September 4, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
SharpShooter Posted September 5, 2010 Author Share Posted September 5, 2010 (edited) Thanks a lot wakillon, but i got a couple of questions. Which script is faster and takes less cpu usage? in other words which one is better? 'll it work to match a word in whole sentence like in the script posted before? what if i use it for too many Windows and Keywords? i mean easily use for more then one keyword? like "super" , "dvd" , "volume" , etc (check and close at the same timewithout effecting browsers. And thanks once again for the help... it's really great. Edited September 5, 2010 by SprinterGuru Link to comment Share on other sites More sharing options...
wakillon Posted September 5, 2010 Share Posted September 5, 2010 I don't know which is better The first script close only one window with the stringinstead of second that close all windows containing string in their title !Try and see AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
bo8ster Posted September 6, 2010 Share Posted September 6, 2010 (edited) @SprinterGuru - I recommend you use wakillon's second script. It does what I was thinking of well. It does not matter which is faster, it matters which script is simpler to use and has more functionality. Good script wakillon! Edited September 6, 2010 by bo8ster Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
SharpShooter Posted September 6, 2010 Author Share Posted September 6, 2010 (edited) #include <Process.au3> #include <Array.au3> Func _CloseWindowWithString ( $_String ) $_BrowserList = 'Firefox.exe,iexplore.exe,chrome.exe,opera.exe,safari.exe' $_BrowserList = StringSplit ( $_BrowserList, ',' ) ; _ArrayDisplay ( $_BrowserList ) $_WinList = WinList ( ) For $_I = 1 To $_WinList[0][0] If StringInStr ( $_WinList[$_I][0], $_String ) <> 0 And Not _ _AlreadyInArray ( $_BrowserList, _ProcessGetName ( WinGetProcess ( $_WinList[$_I][0], "" ) ) ) Then WinClose ( $_WinList[$_I][1] ) Next EndFunc ;==> _CloseWindowWithString ( ) Func _AlreadyInArray ( $_SearchArray, $_Item ) $_Index = _ArraySearch ( $_SearchArray, $_Item ) If @error Then Return False Else If $_Index <> 0 Then Return True Else Return False EndIf EndIf EndFunc ;==> _AlreadyInArray ( ) _CloseWindowWithString ( $_Title1 ) _CloseWindowWithString ( $_Title2 ) _CloseWindowWithString ( $_Title3 ) _CloseWindowWithString ( $_Title4 ) _CloseWindowWithString ( $_Title5 ) _CloseWindowWithString ( $_Title6 ) _CloseWindowWithString ( $_Title7 ) _CloseWindowWithString ( $_Title8 ) _CloseWindowWithString ( $_Title9 ) from the script posted above ^, can we modify this part _CloseWindowWithString ( $_Title1 ) _CloseWindowWithString ( $_Title2 ) _CloseWindowWithString ( $_Title3 ) _CloseWindowWithString ( $_Title4 ) _CloseWindowWithString ( $_Title5 ) _CloseWindowWithString ( $_Title6 ) _CloseWindowWithString ( $_Title7 ) _CloseWindowWithString ( $_Title8 ) _CloseWindowWithString ( $_Title9 ) to be like this: _CloseWindowWithString ($Title1, $Title2, $Title3, $Title4, $Title5, $Title6) Edited September 6, 2010 by SprinterGuru Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 (edited) @SprinterGuru - I recommend you use wakillon's second script. It does what I was thinking of well. It does not matter which is faster, it matters which script is simpler to use and has more functionality. Good script wakillon! @Bo8ster Thanks ! #include <Process.au3> #include <Array.au3> Func _CloseWindowWithString ( $_String ) $_BrowserList = 'Firefox.exe,iexplore.exe,chrome.exe,opera.exe,safari.exe' $_BrowserList = StringSplit ( $_BrowserList, ',' ) ; _ArrayDisplay ( $_BrowserList ) $_WinList = WinList ( ) For $_I = 1 To $_WinList[0][0] If StringInStr ( $_WinList[$_I][0], $_String ) <> 0 And Not _ _AlreadyInArray ( $_BrowserList, _ProcessGetName ( WinGetProcess ( $_WinList[$_I][0], "" ) ) ) Then WinClose ( $_WinList[$_I][1] ) Next EndFunc ;==> _CloseWindowWithString ( ) Func _AlreadyInArray ( $_SearchArray, $_Item ) $_Index = _ArraySearch ( $_SearchArray, $_Item ) If @error Then Return False Else If $_Index <> 0 Then Return True Else Return False EndIf EndIf EndFunc ;==> _AlreadyInArray ( ) _CloseWindowWithString ( $_Title1 ) _CloseWindowWithString ( $_Title2 ) _CloseWindowWithString ( $_Title3 ) _CloseWindowWithString ( $_Title4 ) _CloseWindowWithString ( $_Title5 ) _CloseWindowWithString ( $_Title6 ) _CloseWindowWithString ( $_Title7 ) _CloseWindowWithString ( $_Title8 ) _CloseWindowWithString ( $_Title9 ) from the script posted above ^, can we modify this part _CloseWindowWithString ( $_Title1 ) _CloseWindowWithString ( $_Title2 ) _CloseWindowWithString ( $_Title3 ) _CloseWindowWithString ( $_Title4 ) _CloseWindowWithString ( $_Title5 ) _CloseWindowWithString ( $_Title6 ) _CloseWindowWithString ( $_Title7 ) _CloseWindowWithString ( $_Title8 ) _CloseWindowWithString ( $_Title9 )[/size] [size="2"] to be like this: _CloseWindowWithString ($Title1, $Title2, $Title3, $Title4, $Title5, $Title6) @Sprinterguru Try this... [/size] [size=2] #include <Process.au3> #include <Array.au3> Dim $_StringArray[10] = [ 10, 'string1', 'string2', 'string3', 'string4', 'string5', 'string6', 'string7', 'string8', 'string9' ] _ArrayDisplay ( $_StringArray ) _CloseWindowWithStringArray ( $_StringArray ) Exit Func _CloseWindowWithStringArray ( $_StringArray ) $_BrowserList = 'Firefox.exe,iexplore.exe,chrome.exe,opera.exe,safari.exe' $_BrowserList = StringSplit ( $_BrowserList, ',' ) ; _ArrayDisplay ( $_BrowserList ) For $_H = 1 To UBound ( $_StringArray ) -1 $_WinList = WinList ( ) For $_I = 1 To $_WinList[0][0] If StringInStr ( $_WinList[$_I][0], $_StringArray[$_H] ) <> 0 And Not _ _AlreadyInArray ( $_BrowserList, _ProcessGetName ( WinGetProcess ( $_WinList[$_I][0], "" ) ) ) Then WinClose ( $_WinList[$_I][1] ) Next Next EndFunc ;==> _CloseWindowWithStringArray ( ) Func _AlreadyInArray ( $_SearchArray, $_Item ) $_Index = _ArraySearch ( $_SearchArray, $_Item ) If @error Then Return False Else If $_Index <> 0 Then Return True Else Return False EndIf EndIf EndFunc ;==> _AlreadyInArray ( )[/size] [size=2] Or this... #include <Process.au3> #include <Array.au3> _CloseWindowWithStringList ( 'string1,string2,string3,string4,string5,string6,string7,string8,string9' ) Exit Func _CloseWindowWithStringList ( $_StringList ) $_BrowserList = 'Firefox.exe,iexplore.exe,chrome.exe,opera.exe,safari.exe' $_BrowserList = StringSplit ( $_BrowserList, ',' ) ; _ArrayDisplay ( $_BrowserList ) $_StringArray = StringSplit ( $_StringList, ',' ) For $_H = 1 To UBound ( $_StringArray ) -1 $_WinList = WinList ( ) For $_I = 1 To $_WinList[0][0] If StringInStr ( $_WinList[$_I][0], $_StringArray[$_H] ) <> 0 And Not _ _AlreadyInArray ( $_BrowserList, _ProcessGetName ( WinGetProcess ( $_WinList[$_I][0], "" ) ) ) Then WinClose ( $_WinList[$_I][1] ) Next Next EndFunc ;==> _CloseWindowWithStringList ( ) Func _AlreadyInArray ( $_SearchArray, $_Item ) $_Index = _ArraySearch ( $_SearchArray, $_Item ) If @error Then Return False Else If $_Index <> 0 Then Return True Else Return False EndIf EndIf EndFunc ;==> _AlreadyInArray ( ) Edited September 6, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now