AutoHotkey Community

It is currently May 26th, 2012, 9:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: June 30th, 2009, 3:16 pm 
Offline

Joined: November 16th, 2004, 6:38 am
Posts: 153
Location: New York
Can somebody offer the basic technique one would use in AHK (assuming it's possible) to navigate a TreeView in a (non-AHK) application? For example, launch Regedit.exe and navigate to a given key (much like SysInternals' RegJump.exe does).

Thanks,

Jacques.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2009, 8:50 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
i think it's app specific. many "treeview apps" have command line options (usually found in their help file) that let you jump directly to a given value. not sure if that's true with regedit, but if not, I'm 99% there are free extensions that let you do it, or you can just use another editor.

if that's not an option, you could try AHK's ControlGet command to try to read the application's treeview controls for each leg in the path. i.e. get the list, find if and where the value you want is on that list, then jump down that many steps, repeat...

if ControlGet doesn't work, you can try going down the tree branches one step at a time and use StatusBarGetText or some other command to find what value you are currently at. StatusBarGetText works with registry keys, for example, but not with registry values. for value names I had to send F2 (rename) each step to get the value's name, but that's a crap solution... I've meant to update that particular code, my plan is to use regread to get the list of values and use that to pick the number of steps to take, but i haven't tried it yet)...

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 12:10 am 
Offline

Joined: November 16th, 2004, 6:38 am
Posts: 153
Location: New York
Thanks for the reply. I'm thinking that extracting the control's entries to count the necessary steps to get where I want to go might be too flaky, and using the status bar to ascertain my current position wouldn't work consistently since Regedit truncates long key paths. I was think more along the lines of navigating to the top of the tree (via left-arrow until the status bar tells me I'm at the top entry), then sending the letters of the next key name to navigate, then use right-arrow to expand the key and start sending the next subkey name, etc. Maybe I'd use RegReads first to find out how far I should try to get before hitting a non-existent key. To get to a particular value, I could then send F6 to switch panes and again send the letters of the value name (if it exists).

I asked the question to see if there might be a more elegant solution that doesn't involve sending keystrokes (e.g. Explicitly set the focus of the control to each key and subkey in sequence, either via built-in AHK commands or via window messages. I once had the source code to RegJump that described the technique it uses, but MS has pretty much removed all the SysInternals source code since they acquired the site and hired its principal founder.

Thanks again,

Jacques.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 6:10 am 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 355
Location: Germany
Hi Jacques,

have a look at TreeCtrl-support via DLLCall
http://www.autohotkey.com/forum/topic7380.html.

I use it with AHKTreeSupportVC7.dll for TreeGetItemText

and I have one line changed:
Code:
;      VarSetCapacity(szValue, 300)   
      VarSetCapacity(szItemText, 300)   


Hubert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 12:07 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
if you end up writing a script to jump to a reg value, then this example may be of some help. i wrote it to grab (copy) reg paths from text files (from RegShot logs mainly) and open to the value, or as close as possible in case the value doesn't exist anymore. It for use with Registry Workshop (my reg editor of choice), but parts of it could be used with any other editor.

Registry Workshop offers command line options to jump directly to a specified key, but the script uses RegRead to first check if the subkey or value exists, and if not, to trim it to the closest existing subkey. i also just added a loop that reads the value names, sorts them, and sends the right number of key strokes based on that - it was a bit more convoluted than I had hoped because AHK retrieves them in some type of non-alphabetical reverse order.

the script works for the most part, but I haven't cleaned it up and there are parts I'm hoping to improve. the DllCall method mentioned by hd0202 may be the way to go (haven't tried it yet).

Code:
#NoEnv
#SingleInstance, Force
SetBatchLines, -1
DetectHiddenWindows, On
SetTitleMatchMode, 2
SendMode, Input


;the longer #q is pressed the more lines are selected

#q::
KeyWait, q, T0.5
Gosub, % oCB:= Errorlevel ? "OpenWithRegWkshp" : "RunRegWkshp"
loop % regPath0
   regPath%A_Index%=
regPath0=
regPath=
exists=
rPath=
rPath1=
rPath2=
rPath3=
rPath4=
rPath5=
SelectedPath=
rNames=
Return

OpenWithRegWkshp:
   FlashWin()
   lines:=0
   loop,
   {
      KeyWait, q, T0.3
      If Errorlevel
      {
         FlashWin() ;select number of lines
         lines++
      }
      Else Break
   }
   oCB:= ClipboardAll
   Send, {Home}{ShiftDown}{Down %lines%}{End}{ShiftUp}^c
   ClipWait, 2
   StringSplit, regPath, Clipboard,`n,`r][%A_Space%
   Clipboard:= oCB
   RegExMatch(regPath1,"i)(HKLM|HKCR|HKCU|HKU|HKCC|HKEY_LOCAL_MACHINE|HKEY_USERS|HKEY_CURRENT_USER|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG)\\(?:((.*)\\(.*?)(?::\s)(.*)|.*))", rPath)
   If (rPath1 = "") ;if no rootkey present, run editor without path
      Goto, RunRegWkshp   
   If (rPath3 != "") ;If reg values available, check with AHK
   {
      rSteps:=0      
      RegRead, exists, %rPath1%, %rPath3%, %rPath4%   
      If !Errorlevel
      {
         SelectedPath:= rPath1 . "\" . rPath3
         Loop %rPath1%,%rPath3%,2
            rSteps++    
         If (rPath4 = "(Default)") || (rPath4 = "")
            rPath4:= SelectedPath ;this is specific to regWksp
         Else
         {
            Loop %rPath1%,%rPath3%
               rNames.= A_LoopRegName . "`n"
            StringTrimRight,rNames,rNames,1
            Sort,rNames
            Loop,Parse,rNames,`n
            {
               rSteps++               
               If (A_LoopField = rPath4)
                  Break
            }
         }
      }
      Else rPath4=
   }
   Else rPath3:= rPath2  ;update variable names to match
   If SelectedPath =
   {
      loop,
      {
         values:=0
         Loop %rPath1%, %rPath3%, 1  ; checks if key exists
            values++
         If (values > 0)
         {
            SelectedPath:= rPath1 . "\" . rPath3
            Break
         }
         RegExMatch(rPath3,".*(?=\\)",rPath3)   
      }
   }
   IfWinExist, Registry Workshop
   {
      hRegWksp:= WinWaitFull("Registry Workshop")
      ControlSetText,Edit1,%SelectedPath%, ahk_id %hRegWksp%
      ControlFocus,Edit1,ahk_id %hRegWksp%
      ControlSend,Edit1,{Enter},ahk_id %hRegWksp%
      Sleep, 300
   }
   Else
   {
      Run, "%A_ProgramFiles%\Registry Workshop\RegWorkshop.exe" /g "%SelectedPath%"
      hRegWksp:= WinWaitFull("Registry Workshop")
   }
   If rPath4
   {
      ControlFocus, ATL:0050C4901, ahk_id %hRegWksp%
      Send {Left}{Down %rSteps%}
   }
Return

RunRegWkshp:
   IfWinExist, Registry Workshop
      WinActivate
   Else Run %A_ProgramFiles%\Registry Workshop\RegWorkshop.exe
Return

FlashWin(speed=10)
{
   If speed < 2
      speed:= 2
   Gui, Color, FFFFFF
   WinGet, thisID, ID, A
   Loop, %speed%
   {
      tran:= 10*Abs( 25-(50/speed)*A_Index )+5
      WinSet, Transparent, %tran%, ahk_id %thisID%
   }
   ;WinSet, Transparent, Off, ahk_id %thisID%
}

WinWaitFull(win)
{
  WinWait, %win%
  If hWin:= WinExist( win )
  {
    IfWinNotActive, ahk_id %hWin%
      WinActivate, ahk_id %hWin%
    WinWaitActive, ahk_id %hWin%
    Return hWin
  }
  Else    Return 0
}

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 3:04 pm 
Offline

Joined: November 16th, 2004, 6:38 am
Posts: 153
Location: New York
Thank you, hd0202. I will check out the post you mention when I'm not reading this on a BlackBerry.

Thank you also, pajenn. I will look at your code carefully to see what I can glean. Funny you should mention the reason you wrote the script: I also use a similar script to jump to both Registry entries and files/folders when studying InCtrl5 reports of changes made to a system by a setup program (exactly the same idea as RegShot). My current script uses RegJump.exe to open the right key, but one of reasons for asking the original question was to try to do it without an external program, though I am interested in the more general technique for other TreeViews. I did figure one way to do it extremely fast with Regedit, and that is to close Regedit if it's open, then set the LastKey entry in the Registry (where Regedit keeps track of the key it was on when last closed), then re-open Regedit (which opens immediately in the right spot). It's much quicker than any "navigation" approach in this particular case. When the key in question is missing, Regedit displays the nearest valid parent key at the top of the on-screen tree display, but remains focused on the root of the tree (Computer).

One thing I should mention: Registry entries, as opposed to keys, are displayed alphabetically by Regedit but are in fact stored (and retrieved by programs such as Reg.exe, AutoHotkey and even Regedit itself when exporting a key) in the order in which they were created.

Thanks again,

Jacques.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 6:38 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
JBensimon wrote:
I did figure one way to do it extremely fast with Regedit, and that is to close Regedit if it's open, then set the LastKey entry in the Registry (where Regedit keeps track of the key it was on when last closed), then re-open Regedit (which opens immediately in the right spot). It's much quicker than any "navigation" approach in this particular case.


Damn, that's clever. I wish I had thought of that since it works with Registry Workshop too...

I actually wrote other scripts to analyze RegShot logs. The problem I had (in addition to jumping to registry and file entries), was that there was too much noise in the logs - I wanted to use them after regular uninstalls to check for leftover values as I've had problems in the past with softwares leaving trial period stamps, processes or unnecessary drivers behind to run in the background, which in several cases have resulted in problems with later software updates or just general system slowdown.

To that end I wrote a one script that simply removes all general noise. For example, the ever present entries such as:
C:\Documents and Settings\%A_UserName%\Local Settings\desktop.ini
C:\Documents and Settings\%A_UserName%\Local Settings\History\desktop.ini
C:\Documents and Settings\%A_UserName%\Local Settings\History\History.IE5
... i.e. I run the data through an Ignore List filter.

I wrote a second script to check the remaining values and drop those that didn't exist anymore. And then a third script to display the remaining entries in an AHK treeview gui, that also displays the time created for files or last write time for registry entries, and opens them up in windows explorer or registry workshop upon a right-click.

I had other plans too - a script to search for files and reg values created at the same time the parent application's main program folders or registry keys were created, etc. And of course I meant to combine all these scripts into one big script. But it's still a work in progress... I guess I reached a point where the scripts worked fine for my purposes, but would now require a lot more effort to expand for general use by other people so now I just update them here and there when I run into a bug or other problem.

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2009, 7:46 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
JBensimon wrote:
Funny you should mention the reason you wrote the script: I also use a similar script to jump to both Registry entries and files/folders when studying InCtrl5 reports of changes made to a system by a setup program (exactly the same idea as RegShot).


Still around Jacques?

I'm switching over to InCtrl5. Consequently wrote several scripts to to use it with my pre-existing regshot scripts. Here's a link to those scripts - the treeview uses your regedit trick to jump to the selected key:

http://www.autohotkey.com/forum/viewtop ... sc&start=0

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], Google Feedfetcher, krajan, oldbrother, Yahoo [Bot] and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group