Click here to Skip to main content
15,885,767 members
Articles / Programming Languages / C#
Article

JumpTo RegEdit

Rate me:
Please Sign up or sign in to vote.
4.56/5 (8 votes)
30 Aug 2007CPOL2 min read 35K   865   27   2
A Sysinternals JumpTo clone
Screenshot - RegEdit_JumpTo_Dlg.png

Introduction

Did you ever wonder how RegJump from Sysinternals works? I was quite amazed when I first saw that functionality and was wondering how this could be done in C#.

The library presented here uses Windows messages to automate Regedit. The content of the tree is read by TVM_GETITEM messages and the tree is navigated by issuing WM_Keyxx messages appropriately. The only tricky part is handling memory allocation for TVM_GETITEM. Because the message is sent to another process, the memory used by the message has to be allocated in the target process. Fortunately, this can be done by using VirtualAllocEx and providing a handle to the remote process.

Jeffrey Richter has an article on MSJ that describes in detail how it's done, Cory Nelson wrote an excellent article which is using the same technique and Chris Taylor had some interop code on his blog that I could use.

Using the Code

The following code fragment shows how the code from the sample project is used:

C#
RegEditLocator.Locate(@"HKCU\SOFTWARE\Microsoft\.NETFramework");

Points of Interest

According to MSDN, the function OpenProcess requires SeDebugPrivilege to work. I tried to verify this by running the sample program on a normal user account in XP and was quite surprised that it worked. Repeating the same test in Vista gave me the expected result: the program will not work with a limited account.

Another issue I don't feel quite comfortable with is that the implementation is basically a hack that relies on internals of Regedit.exe. This means that any hotfix or security update from Microsoft can potentially break the code.

The code is meant to be more of a guide/example on how to automate an application using messages in C# than a library ready to be used in production code.

History

  • 30th August, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSweet - nicely done Pin
Michael B. Hansen30-Aug-07 22:59
Michael B. Hansen30-Aug-07 22:59 
Hi!

Just tried it - and it seems to be working without a glitch Big Grin | :-D

FYI: I have converted the project to VS2005 - and compiled it in .NET2.0 - and tested it on Windows 2003 x64. It worked flawlesly here too (navigating correctly to the x64-version of the registry - and not the Wow6432Node (x86-version))


Have to do some last checks to ensure that no memory issues exists - but then it may very well find its way into my support-tools-collection.


May I assume that the license is "use it for whatever you want - even commercially?"


Best regards,

Michael
GeneralRe: Sweet - nicely done Pin
Reto Ravasio31-Aug-07 12:42
Reto Ravasio31-Aug-07 12:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.