[CMake] How to read a registry key?
Anton Deguet
anton.deguet at jhu.edu
Thu Sep 7 14:31:22 EDT 2006
I looks like this has something to do with the nature of the key/value.
For values listed as REG_SZ (within regedit.exe), CMake can retrieve the
content but for values stored as REG_EXPAND_SZ I systematically get
"/registry". I don't know much about the Windows registry but I did a
quick survey of different computers/users in the lab and the user path
can be either one which makes it difficult to implement a robust
solution. Am I the first one to run into this issue?
Anton
On Thu, 2006-09-07 at 12:13 -0400, Anton Deguet wrote:
> Bill,
>
> I had some success with the key expansion but I haven't been able to do
> what I need. Basically, I would like to get the un-expanded content of
> the user path, i.e. not the expanded path (user and system) which can be
> found using $ENV{PATH}.
>
> I tried the following code, i.e. adding two variables, one using the
> other:
>
> SET(CISST_PATH ${EXECUTABLE_OUTPUT_PATH} ${LIBRARY_OUTPUT_PATH})
> SET(CISST_PATH_REG_KEY "HKEY_CURRENT_USER\\Environment;CISST_PATH")
> EXEC_PROGRAM(${CMAKE_COMMAND}
> ARGS "-E write_regv \"${CISST_PATH_REG_KEY}\"
> \"${CISST_PATH}\"")
>
> SET(OTHER_PATH_REG_KEY "HKEY_CURRENT_USER\\Environment;OTHER_PATH")
> SET(OTHER_PATH "c:/prg;%CISST_PATH%")
> EXEC_PROGRAM(${CMAKE_COMMAND}
> ARGS "-E write_regv \"${OTHER_PATH_REG_KEY}\"
> \"${OTHER_PATH}\"")
>
> GET_FILENAME_COMPONENT(TMP "[HKEY_CURRENT_USER\
> \Environment;OTHER_PATH]/dummy.dum" PATH)
>
> MESSAGE("${TMP}")
>
> At that point, everything looks great and I can check the results with
> "reg.exe", the expansion works ...
>
> Now, if I try to retrieve the user path using
> GET_FILENAME_COMPONENT(TMP "[HKEY_CURRENT_USER\
> \Environment;PATH]/dummy.dum" PATH)
>
> TMP is set to "/registry" ... Any explanation or better solution to
> just retrieve the value as a string?
>
>
> On Wed, 2006-09-06 at 20:55 -0400, William A. Hoffman wrote:
> > At 05:36 PM 9/6/2006, Anton Deguet wrote:
> > >Hello,
> > >
> > >I have found that using EXEC_PROGRAM with ${CMAKE_COMMAND} -E I can
> > >write/remove a key in the Windows registry but I haven't figured out how
> > >to read a key. Is there a simple solution for that?
> >
> > Sure, but it seems not to be documented....
> > Several commands including GET_FILENAME_COMPONENT will expand things
> > like this:
> >
> > "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\2.0;JavaHome]/bin"
> >
> > You can use this to read registry values. I will add some docs in
> > the morning.
> >
> > -Bill
> >
> > _______________________________________________
> > CMake mailing list
> > CMake at cmake.org
> > http://www.cmake.org/mailman/listinfo/cmake
--
Anton Deguet <anton.deguet at jhu.edu>
ERC CISST Johns Hopkins University
More information about the CMake
mailing list