Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Path of an open/existing window


  • Please log in to reply
27 replies to this topic

#1 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 26 June 2006 - 04:21 PM

I think it would be a great thing to have a function, that returns the path of an existing window - especially an active window. I was looking for a function, something like - WinGetPath().

Path of active window

Edited by TheSaint, 26 June 2006 - 04:24 PM.

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox








#2 MHz

MHz

    Just simple

  • MVPs
  • 5,724 posts

Posted 26 June 2006 - 04:29 PM

Interesting. Wonder if even possible to get the path.

Edit:
Oh, as in a rightclick extension does. That is taken fron that instance then and passed to the registry, then onwards to your application. You can set the path to be sent to your application via the registry from the main branch of the rightclick menu. If you want a submenu, AutoIt would not be able to make a shell extension for that purpose. The registry can pass on the parameters just like the SendTo menu does.

Edited by MHz, 26 June 2006 - 04:38 PM.


#3 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 26 June 2006 - 04:49 PM

beta

$path = _WinGetPath() MsgBox(0,WinGetTitle(""),$path) Func _WinGetPath($Title="", $strComputer='localhost')     $win = WinGetTitle($Title)     $pid = WinGetProcess($win)    $wbemFlagReturnImmediately = 0x10    $wbemFlagForwardOnly = 0x20    $colItems = ""    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)    If IsObj($colItems) Then       For $objItem In $colItems          If $objItem.ExecutablePath Then Return $objItem.ExecutablePath       Next    EndIf EndFunc

Edited by gafrost, 26 June 2006 - 04:57 PM.

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#4 Skruge

Skruge

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 618 posts

Posted 26 June 2006 - 05:12 PM

Nice one, Gary.
I've been looking for this functionality since SAV Corporate started flagging cmdow.exe as a hacktool.

Thanks!
"Tougher than the toughies and smarter than the smarties"

#5 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 26 June 2006 - 05:33 PM

Interesting. Wonder if even possible to get the path.

Edit:
Oh, as in a rightclick extension does. That is taken fron that instance then and passed to the registry, then onwards to your application. You can set the path to be sent to your application via the registry from the main branch of the rightclick menu. If you want a submenu, AutoIt would not be able to make a shell extension for that purpose. The registry can pass on the parameters just like the SendTo menu does.


Thanks for your response MHz
I'm not quite sure how to apply what you seem to be saying - but I shall ponder upon it?

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#6 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 26 June 2006 - 05:38 PM

beta


Thanks gafrost
I will attempt to understand & apply what you have coded ... I think I saw this posted elsewhere (or part of it), but wasn't sure it was what I was looking for ... I guess I need to actually run it & see?

Actually, what I saw elsewhere didn't have a function called _WinGetPath, I think it was mainly dealing with PID's & processes.

Edited by TheSaint, 26 June 2006 - 05:42 PM.

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#7 MHz

MHz

    Just simple

  • MVPs
  • 5,724 posts

Posted 26 June 2006 - 05:45 PM

Thanks for your response MHz
I'm not quite sure how to apply what you seem to be saying - but I shall ponder upon it?

My reply was mainly to the path of a highlighted file, rather then a window. So may have been incorrect to your needs. As to get the info from a window on a rightclick would be a nice trick indeed to know with using Autoit. Gary has given some nice code to get it outright of the path from the active window.

#8 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 26 June 2006 - 05:46 PM

Yeah I cut it and changed it from something done along time ago

http://www.autoitscript.com/forum/index.ph...st&p=114302

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#9 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 26 June 2006 - 06:02 PM

Yeah I cut it and changed it from something done along time ago

http://www.autoitscript.com/forum/index.ph...st&p=114302


Yeah I reckon that's the one I had checked out!

Once again thanks gafrost ... now to work!

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#10 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 26 June 2006 - 06:34 PM

beta


Hi again gafrost

Well I ran your code with the beta v3.1.1.124
1) I ran it from Scite, and got the Scite path
2) I ran it from the folder I saved the script to, and got C:\Windows\Explorer.exe

However what I was really after, was the folder path of the script - because that was what was open & active - D:\Projects\AutoIt 3\Context Options.

Maybe I've got to change some of your code, or maybe you misunderstood me - what I want to get, is the path of the active window, that being a folder window, not a file one.

I'm not specifically after the script folder - that just happened to be the active one when I double-clicked on the script file. In reality any window could be open & active, if I used a hotkey or shortcut, etc. That's how I want to work with it!

Anyway I'll see if I can modify your code, but I'm quite a newb when it comes to understanding object related code - something that used to drive me nuts in VB.


Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#11 WTS

WTS

    Polymath

  • Active Members
  • PipPipPipPip
  • 247 posts

Posted 27 June 2006 - 05:00 AM

I know if you did stringreplace it will work unfortunetly it only removes .exe from the return value i'll have to look into stringregexpreplace()

MsgBox(0,'FilePath',_WinGetPath('Untitled - Notepad','localhost')) Func _WinGetPath($Title="", $strComputer='localhost')     $win = WinGetTitle($Title)     $pid = WinGetProcess($win)    $wbemFlagReturnImmediately = 0x10    $wbemFlagForwardOnly = 0x20    $colItems = ""    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)    If IsObj($colItems) Then       For $objItem In $colItems          If $objItem.ExecutablePath Then Return StringReplace($objItem.ExecutablePath,"\notepad.exe", "\",1);StringRegExpReplace ("*\.exe", "*\.exe", "\")       Next    EndIf EndFunc

Edited by WTS, 27 June 2006 - 05:02 AM.


#12 WTS

WTS

    Polymath

  • Active Members
  • PipPipPipPip
  • 247 posts

Posted 27 June 2006 - 05:12 AM

I think I got it!

MsgBox(0,'FilePath',StringRegExpReplace(_WinGetPath('Untitled - Notepad','localhost'), "\A*\.exe", "")) Func _WinGetPath($Title="",$strComputer='localhost')     $win = WinGetTitle($Title)     $pid = WinGetProcess($win)    $wbemFlagReturnImmediately = 0x10    $wbemFlagForwardOnly = 0x20    $colItems = ""    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)    If IsObj($colItems) Then       For $objItem In $colItems          If $objItem.ExecutablePath Then Return $objItem.ExecutablePath;StringRegExpReplace ($objItem.ExecutablePath, "\A*.exe", "")       Next    EndIf EndFunc

Edited by WTS, 27 June 2006 - 05:19 AM.


#13 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 27 June 2006 - 12:11 PM

AutoIt         
MsgBox(0,'FilePath',_WinGetPath('Untitled - Notepad','localhost')) Func _WinGetPath($Title="", $strComputer='localhost')     $win = WinGetTitle($Title)     $pid = WinGetProcess($win)    $wbemFlagReturnImmediately = 0x10    $wbemFlagForwardOnly = 0x20    $colItems = ""    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)    If IsObj($colItems) Then       For $objItem In $colItems          If $objItem.ExecutablePath Then                 $path = ""                 $tmp = StringSplit($objItem.ExecutablePath,"\")                 For $x = 1 To $tmp[0] - 1                     $path &= $tmp[$x] & '\'                 Next                 Return $path             EndIf       Next    EndIf EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#14 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 28 June 2006 - 12:32 AM

I think this would be more appropriate, returns more info

AutoIt         
$a_path = _WinGetPath('Untitled - Notepad','', 'localhost') If Not @error Then     For $x = 1 To $a_path[0]         MsgBox(0, 'Window File Path Info:', $a_path[$x])     Next EndIf ;********************************************************* ; if error returns empty string and sets error ; returns array containing ; 1 = Title ; 2 = PID ; 3 = Path ; 4 = Exe name ;********************************************************* Func _WinGetPath($Title = "",$Text="", $strComputer = 'localhost')     Local $path[5] = [5, "", -1, "", ""]     If StringLen($Text) > 0 Then         $path[1] = WinGetTitle($Title,$Text)     Else         $path[1] = WinGetTitle($Title)     EndIf     $path[2] = WinGetProcess($path[1])     $wbemFlagReturnImmediately = 0x10     $wbemFlagForwardOnly = 0x20     $colItems = ""     $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")     $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $path[2], "WQL", _             $wbemFlagReturnImmediately + $wbemFlagForwardOnly)     If IsObj($colItems) Then         For $objItem In $colItems             If $objItem.ExecutablePath Then                 $tmp = StringSplit($objItem.ExecutablePath, "\")                 For $x = 1 To $tmp[0] - 1                     $path[3] &= $tmp[$x] & '\'                 Next                 $path[4] = $tmp[UBound($tmp) - 1]                 Return $path             EndIf         Next     EndIf     SetError(1)     Return "" EndFunc   ;==>_WinGetPath

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#15 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 01 July 2006 - 06:07 PM

I think this would be more appropriate, returns more info

Sorry people, I've been away a few days. However I have now tried the above examples, but with very little success.

gafrost this is my first line
$a_path = _WinGetPath('Context Options','', 'localhost')

which has the path

D:\Projects\AutoIt 3\Context Options

what I want returned is

D:\Projects\AutoIt 3

Please note that I am not working with an executable ... unless you consider a folder is always opened by C:\Windows\Explorer.exe

I say again, that the window I have open is

D:\Projects\AutoIt 3\Context Options

Using your latest code I get 4 dialogs and an error!

Dialog 1 displays

Context Options

Dialog 2 displays

4084

Dialog 3 displays

C:\Windows\

Dialog 4 displays

Explorer.exe

Then I get an error message

Array variable has incorrect number of subscripts or subscript dimension range exceeded


Edited by TheSaint, 01 July 2006 - 06:09 PM.

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#16 evilertoaster

evilertoaster

  • Active Members
  • PipPipPipPipPipPip
  • 1,203 posts

Posted 01 July 2006 - 06:48 PM

so essentailly all you want is WinGetTitle("") and then use stringsplit or other string manamgement to strip it at the first '/' from the right?

Edited by evilertoaster, 01 July 2006 - 06:48 PM.


#17 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 01 July 2006 - 07:37 PM

so essentailly all you want is WinGetTitle("") and then use stringsplit or other string manamgement to strip it at the first '/' from the right?


Hi evilertoaster
No that is not always possible, it depends on what the user's folder settings are (as I explained in my first post)

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#18 WTS

WTS

    Polymath

  • Active Members
  • PipPipPipPip
  • 247 posts

Posted 01 July 2006 - 08:55 PM

This is not your answer but you dont get an error .. or extra value after the forth

Plain Text         
$a_path = _WinGetPath('Untitled - Notepad','', 'localhost') If Not @error Then     For $x = 1 To $a_path[0]         MsgBox(0, 'Window File Path Info:', $a_path[$x])     Next EndIf ;********************************************************* ; Function Name: _WinGetPath() ; Parameter(s): $Title = Window Title ;              $Text = Window Text ;              $strComputer = Computer Name ; Return Value(s): 1 = Title ;                 2 = PID ;                 3 = Path ;                 4 = Exe name ; Comment(s):  If error returns empty string and sets error ;             returns array containing ; Author(s): Gary Frost ;********************************************************* Func _WinGetPath($Title = "",$Text="", $strComputer = 'localhost')     Local $path[5] = [4, "", -1, "", ""]     If StringLen($Text) > 0 Then         $path[1] = WinGetTitle($Title,$Text)     Else         $path[1] = WinGetTitle($Title)     EndIf     $path[2] = WinGetProcess($path[1])     $wbemFlagReturnImmediately = 0x10     $wbemFlagForwardOnly = 0x20     $colItems = ""     $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")     $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $path[2], "WQL", _             $wbemFlagReturnImmediately + $wbemFlagForwardOnly)     If IsObj($colItems) Then         For $objItem In $colItems             If $objItem.ExecutablePath Then                 $tmp = StringSplit($objItem.ExecutablePath, "\")                 For $x = 1 To $tmp[0] - 1                     $path[3] &= $tmp[$x] & '\'                 Next                 $path[4] = $tmp[UBound($tmp) - 1]                 Return $path             EndIf         Next     EndIf     SetError(1)     Return "" EndFunc ;==>_WinGetPath


the least you can do is thank us for trying... 8)

Edited by WTS, 01 July 2006 - 09:02 PM.


#19 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 01 July 2006 - 09:20 PM

This is not your answer but you dont get an error .. or extra value after the forth

Thanks WTS
You are right on both accounts!

the least you can do is thank us for trying... 8)

Once again, Thanks WTS (sorry ... forgot to add your name in one of the last posts, but it was also meant for you ... your efforts & others are always appreciated!)

Edited by TheSaint, 01 July 2006 - 09:25 PM.

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#20 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 5,509 posts

Posted 03 July 2006 - 05:31 PM

Once again, Thanks WTS (sorry ... forgot to add your name in one of the last posts, but it was also meant for you ... your efforts & others are always appreciated!)


Actually, I just had a look again, and realised that I'd forgotten to put any thanks at all ... though I certainly meant to ... oops silly me!

Once again, thank you to everybody who's ever replied to any of my requests ... whether they were ultimately helpful or not ... just the fact that you read my post, and then said something, warrants a thanks in my book!

HAPPY CODING!

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users