Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Functions to read and write in the windows registry  (Read 15304 times)
ORGA-SOFT B.
Posts: 34


« on: June 16, 2017, 08:05:33 am »

Hello all,

is there a way to access the windows registry with the genero bdl language?



Thanks for your answers
Leo S.
Four Js
Posts: 126


« Reply #1 on: June 17, 2017, 12:06:00 am »

Hi , there is the possibility to call with winexecwait arbitrary client commands.
Furthermore there is the "reg" command line program which is able to read/write the registry.
So you can call this program with winexecwait , redirect the result into a file and can then file transfer the results with fgl_getfile() to your BDL machine.

HTH and Regards, Leo
ORGA-SOFT B.
Posts: 34


« Reply #2 on: June 17, 2017, 09:15:37 am »

Hello Leo,

this solution is the worst case scenario for me to implement it in my application. i also have been thinking about to paste the response of regquery
into the clipboard and read it from the clipboard.

Is there a possibility to get the output stream directoy from the frontcall command to a variable in genero?
This would by useful for some other cases.

Best solution for us would by direct calls from bdl like write_registry and read_registry functions what do you think good idea for a feature request ;-)

best regards and a sunny weekend
Martin Stigmond
Leo S.
Four Js
Posts: 126


« Reply #3 on: June 17, 2017, 02:41:07 pm »

Why is this scenario worst case for you ?
How many entries from the registry are you intending to read ?
If you have to read/write multiple entries you can write little batch files to do it in one rush and avoid the network roundtrips you would have in case of multiple calls.

>Is there a possibility to get the output stream directoy from the frontcall command to a variable in genero?
>This would by useful for some other cases.

No ,there is no such ability currently (and I doubt it will be ever added ).
You could write your own GDC extension front calls in C (see http://4js.com/online_documentation/fjs-fgl-manual-html/?path=fjs-fgl-manual#c_fgl_frontcalls_user_ext_gdc.html ) which then could query the registry directly and hand back the result without going via file transfer.

Regards, Leo
Reuben B.
Four Js
Posts: 1049


« Reply #4 on: June 18, 2017, 08:57:06 am »

When I migrated my first application to Genero back in the mid 2000's, I used a technique involving a frontCall executing the Windows command regedit with the /S option, to read and write registry settings in the GDC's user interface stored settings.  (we wanted all users to have the same column settings for an important table) This worked fine in XP at the time, but unfortunately when Vista was introduced, the UAC controls introduced a dialog box whenever this was executed.  You can see this forum post from me in 2009 http://4js.com/fjs_forum/index.php?topic=288.0.

You don't indicate what you are trying to read and write to the registry.  Is it information you have written and are reading back?  If so I would invite you to look at the new localStorage front-call being introduced in 3.10 as this would be the preferred cross-platform approach to do that sort of thing.  You can currently trial this in the Early Access Program.

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
David H.
Posts: 158


« Reply #5 on: June 19, 2017, 10:57:00 am »

Its not uncommon for Windows applications to interrogate the registry. We normally do this to check for the presence of 3rd party apps we interface with and to check their versions and get install locations etc. We ended up using some VBScript functions to do this. Of course a built in solution would be preferable. I wish that there was a .Net Framework interface equivalent to the Java one, as this would be perfect for this and useful for many other things!
Alessandro (Efisio) R.
Posts: 42


« Reply #6 on: June 19, 2017, 03:46:33 pm »

Hi , there is the possibility to call with winexecwait arbitrary client commands.
Furthermore there is the "reg" command line program which is able to read/write the registry.
So you can call this program with winexecwait , redirect the result into a file and can then file transfer the results with fgl_getfile() to your BDL machine.

HTH and Regards, Leo

I intrude in this discussion to ask why winexecwait doesn't work with the 'reg query HKEY_CLASSES_ROOT\Excel.Application\CurVer' command, that i need to execute for reading from the windows registry which excel version is installed on the windows client. The return value is always 0, even if i try to execute that command redirecting the output into a file for a subsequent upload to the server. If I try to call winexecwait for example like 'let success = winexecwait("notepad")' it works and it returns 1.
Where am I wrong?

Thanks in advance.
Reuben B.
Four Js
Posts: 1049


« Reply #7 on: June 20, 2017, 12:10:02 am »

...

I intrude in this discussion to ask why winexecwait doesn't work with the 'reg query HKEY_CLASSES_ROOT\Excel.Application\CurVer' command, that i need to execute for reading from the windows registry which excel version is installed on the windows client. The return value is always 0, even if i try to execute that command redirecting the output into a file for a subsequent upload to the server. If I try to call winexecwait for example like 'let success = winexecwait("notepad")' it works and it returns 1.
Where am I wrong?

Thanks in advance.

FYI, the source for winexecwait is in FGLDIR/src/fglwinexec.4gl.  You'll see that it is simply an execute front-call.  There is also a comment there about back slashes.  My money (assuming everything else is correct) is that you need to replace the single back slashes in the command string with four back slashes.

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Alessandro (Efisio) R.
Posts: 42


« Reply #8 on: June 22, 2017, 11:17:28 am »

FYI, the source for winexecwait is in FGLDIR/src/fglwinexec.4gl.  You'll see that it is simply an execute front-call.  There is also a comment there about back slashes.  My money (assuming everything else is correct) is that you need to replace the single back slashes in the command string with four back slashes.
I tried calling the winexecwait like this winexecwait("reg query HKEY_CLASSES_ROOT\\\\Excel.Application\\\\CurVer") and it works, but in this way I can't get the output generated by that command. If i extend that command with a redirect to a file (adding " > C:\\\\output.txt"), the winexecwait fails. I've tried with many path, considering even write permissions, but it continue failing. How can I do?
ORGA-SOFT B.
Posts: 34


« Reply #9 on: June 23, 2017, 09:04:44 am »

we do this job in this way:

LET command= "cmd /c \"reg query HKEY_CLASSES_ROOT\\\\Excel.Application\\\\CurVer >", "c:\\temp\\regoutput.txt", "\""

CALL ui.Interface.frontCall("standard", "execute", [command,TRUE], [result])

and this works fine for us.

Note that windows needs only one "\" at a lokal path.
Alessandro (Efisio) R.
Posts: 42


« Reply #10 on: June 23, 2017, 09:44:14 am »

we do this job in this way:

LET command= "cmd /c \"reg query HKEY_CLASSES_ROOT\\\\Excel.Application\\\\CurVer >", "c:\\temp\\regoutput.txt", "\""

CALL ui.Interface.frontCall("standard", "execute", [command,TRUE], [result])

and this works fine for us.

Note that windows needs only one "\" at a lokal path.


I tried with your advice, but the variable "result" get 0 and the file is created empty.
ORGA-SOFT B.
Posts: 34


« Reply #11 on: June 23, 2017, 10:01:59 am »

i think there a to many "\" in the reg query try this


LET command= "cmd /c \"reg query HKEY_CLASSES_ROOT\\Excel.Application\\CurVer >", " c:\\temp\\regoutput.txt", "\""
Alessandro (Efisio) R.
Posts: 42


« Reply #12 on: June 23, 2017, 12:13:09 pm »

i think there a to many "\" in the reg query try this


LET command= "cmd /c \"reg query HKEY_CLASSES_ROOT\\Excel.Application\\CurVer >", " c:\\temp\\regoutput.txt", "\""
The command with only 2 backslashes worked... Thanks a lot!!!
Reuben B.
Four Js
Posts: 1049


« Reply #13 on: June 26, 2017, 01:46:39 am »

Just to summarize a little ...

winexec, winexexwait have been deprecated for a while http://4js.com/online_documentation/fjs-fgl-manual-html/#r_fgl_utility_functions_fglwinexec.html and recommendation is to use the standard set of front-calls http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_frontcalls_standard.html.  Whilst the winexec will still work, you may find that you require extra back-slashes

With the front-calls, there is shellexec and execute.

Shellexec is equivalent of right-clicking on a file and selecting default action (typically open), (or double-clicking on file).  You can add alternate actions e.g. Print as second argument and that is equivalent of right-clicking and selecting that action.

Execute is equivalent of typing Windows-R and typing in the command.  It is not the equivalent of starting command shell and typing in that command.  You need to prefix with cmd /c for that.  So in this instance, type Windows-R and then experiment with  typing reg query [key] > [file] versus cmd /C "reg query [key] > [file]". 

I wonder if we should add a third front-call that adds the cmd /C automatically?  We'd have to make sure we cater for many front-ends, not just windows

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Alessandro (Efisio) R.
Posts: 42


« Reply #14 on: June 26, 2017, 09:03:13 am »

Just to summarize a little ...

winexec, winexexwait have been deprecated for a while http://4js.com/online_documentation/fjs-fgl-manual-html/#r_fgl_utility_functions_fglwinexec.html and recommendation is to use the standard set of front-calls http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_frontcalls_standard.html.  Whilst the winexec will still work, you may find that you require extra back-slashes

With the front-calls, there is shellexec and execute.

Shellexec is equivalent of right-clicking on a file and selecting default action (typically open), (or double-clicking on file).  You can add alternate actions e.g. Print as second argument and that is equivalent of right-clicking and selecting that action.

Execute is equivalent of typing Windows-R and typing in the command.  It is not the equivalent of starting command shell and typing in that command.  You need to prefix with cmd /c for that.  So in this instance, type Windows-R and then experiment with  typing reg query [key] > [file] versus cmd /C "reg query [key] > [file]". 

I wonder if we should add a third front-call that adds the cmd /C automatically?  We'd have to make sure we cater for many front-ends, not just windows

Thanks for the explanation. In the end I saw winexec calling the frontcall. Regarding adding a frontcall with the "cmd /c" command is unnecessary in my opinion.
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines