Author Topic: registry keys  (Read 4521 times)

0 Members and 1 Guest are viewing this topic.

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
registry keys
« on: October 26, 2018, 12:08:49 am »
does anyone know how to read a couple of registry keys that had my program place there using a .bat file shell.  but now how do I have it read them back. I want to be able to input the values I placed there into my qb64 program as a variable.  Any ideas would be greatly appreciated

FellippeHeitor

  • Guest
Re: registry keys
« Reply #1 on: October 26, 2018, 12:19:07 am »

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
Re: registry keys
« Reply #2 on: October 26, 2018, 08:25:27 am »
Thanks for the reply but i'm not trying to do all that.  What I did was added a hklm\software key with the type REG_BINARY using a shell to cmd /c.  I was then able to go to the command prompt from windows and do a reg query and find it.  now I just want to know if there is a way using either a shell or creating a .bat file to pass my one data field in the registry as a variable to a qb64 program?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: registry keys
« Reply #3 on: October 26, 2018, 10:11:35 am »
REGEDIT's /E switch can be used to export a registry key:

REGEDIT /E d:\path\filename.REG "HKEY_XXXX\Whatever Key"

This will write the registry key "HKEY_XXXX\Whatever Key" and its subkeys to a file named d:\path\filename.REG

The resulting file will contain the entries in the format "key"="value", which can be stripped and parsed.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
Re: registry keys
« Reply #4 on: October 26, 2018, 09:07:32 pm »
ok thanks i'll give that a shot.  i'm assuming I would have to use notepad and save those lines as a .bat file and have my qb program shell to it. regedit isn't a qb  function is  it?  Thanks for your help!!!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: registry keys
« Reply #5 on: October 26, 2018, 09:24:14 pm »
You should be able to just shell to it from QB64 itself.

SHELL "REGEDIT /E .\temp.REG " + CHR$(34) + "HKEY_....whatever" + CHR$(34)
OPEN "temp.REG" FOR INPUT AS #1
... and parse from there.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
Re: registry keys
« Reply #6 on: October 26, 2018, 09:30:45 pm »
cool got it thanks!!!!

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
Re: registry keys
« Reply #7 on: October 31, 2018, 05:22:58 pm »
How goes it mcneil,
tried a few different ways of using your lines to no avail
i'll show you what I get when I reg query from the command prompt and one of the ways I tried and hopefully you can tell me what I am doing wrong

from the command prompt
Microsoft Windows [Version 10.0.17134.285]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>REG QUERY HKLM\Software\Dungeons /v data /t REG_BINARY

HKEY_LOCAL_MACHINE\Software\Dungeons
    data    REG_BINARY    FE340EAD

End of search: 1 match(es) found.

C:\WINDOWS\system32>

now it is that fe340ead that I want to be able to input into my program as a variable and work with it from there

one of the ways I tried

DIM dung AS STRING * 50
SHELL "REGEDIT /E \temp.REG " + CHR$(34) + "HKLM\Software\Dungeons /v data /t REG_BINARY" + CHR$(34)
OPEN "temp.reg" FOR INPUT AS #1
DO
    LINE INPUT #1, dung
LOOP UNTIL EOF(1)
CLOSE #1

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: registry keys
« Reply #8 on: October 31, 2018, 06:12:17 pm »
Try this version:

Code: QB64: [Select]
  1. DIM dung AS STRING * 50
  2.  
  3. IF _FILEEXISTS("temp.reg") THEN KILL "temp.reg" 'delete any old version so you can write a new one.
  4. SHELL _HIDE "REG EXPORT HKLM\Software\7-Zip\ temp.reg"
  5.  
  6.     _LIMIT 1
  7. LOOP UNTIL _FILEEXISTS("temp.reg") 'give it a few moments to create the file, if it needs to.
  8.  
  9. OPEN "temp.reg" FOR INPUT AS #1
  10.     LINE INPUT #1, dung
  11.     PRINT dung
  12.  

I'm sorry.  REGEDIT /E has apparently been depreciated in newer versions of windows, so it just doesn't work like it used to. 

Note:  I changed the key to point to a file that was actually in my registery.  Just change it as needed, and I think you can get the information you need easily enough in this manner.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
Re: registry keys
« Reply #9 on: October 31, 2018, 07:40:51 pm »
ok thanks i'll give that a shot. do I have to export the temp.reg to the registry like that or could I call it temp.dat and export it right to my qb64 folder. if I have to put it in the registry I will but was kind of hoping I didn't.  thanks I appreciate the help!!!!

Offline pinology

  • Newbie
  • Posts: 17
    • View Profile
Re: registry keys
« Reply #10 on: October 31, 2018, 08:14:34 pm »
umm I let that run for about 10mins didn't do anything and there is no file in the reg.  isn't there any way to have the program shell to the REG QUERY like I did from the command line and be able to assign a variable to the data I want which is the fe340dea without even creating another file ?  Have a happy Halloween and thanks again for the try!!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: registry keys
« Reply #11 on: October 31, 2018, 10:20:10 pm »
The temp.txt should be in your QB64 folder, where you ran it. 

If it's working from console, it should be working from SHELL as well.

At the very top of that test, add $CONSOLE to it and watch the output information: 
Code: QB64: [Select]
  1.  
  2.  
  3. DIM dung AS STRING * 50
  4.  
  5. IF _FILEEXISTS("temp.reg") THEN KILL "temp.reg" 'delete any old version so you can write a new one.
  6. SHELL _HIDE "REG EXPORT HKLM\Software\7-Zip\ temp.reg"
  7.  
  8.     _LIMIT 1
  9. LOOP UNTIL _FILEEXISTS("temp.reg") 'give it a few moments to create the file, if it needs to.
  10.  
  11. OPEN "temp.reg" FOR INPUT AS #1
  12.     LINE INPUT #1, dung
  13.     PRINT dung
  14.  
  15.  

It works like a charm for me, but there may be a Windows permission issue or something causing you problems.  10 minutes is definitely too long for it to run and do nothing; it'll give me a dump of the entire SOFTWARE section in about 15-20 seconds.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!