Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing the registery with Qbasic?

Status
Not open for further replies.

quebasic2

Programmer
Dec 17, 2002
174
IN
Can you access and edit the registery with qbasic?
 
Should be able to access it. Probably able to edit it by reading it from one channel and writing it out on another then renaming.
Almost guaranteed to mangle it because of the content type.
Well, even stronger than almost. Ed Fair
unixstuff@juno.com
Any advice I give is my best judgement based on my interpretation of the facts you supply. Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.
 
Can you give me some code examples? What you said does not quite made sense.
 
I think Ed means that you will probably corrupt your registry and end up with a "mangled" mess. This is almost a certainty.

You can access the registry but you will have a hard time editing it directly with QB (Microsoft has not and will probably never release the details of the registry record structure).

Probably the only practical way to add/remove/alter registry entries with QB is to write an import file and load it with REGEDIT.EXE. Something like....
[tt]
QbCrlf$ = CHR$(13) + CHR$(10)
Reg$="REGEDIT4" + QbCrlf$ + QbCrlf$
Reg$ = Reg$ + "[HKEY_LOCAL_MACHINE\"
Reg$ = Reg$ + "SOFTWARE\Microsoft\Windows\"
Reg$ = Reg$ + "CurrentVersion\explorer\SmallIcons]" + QbCrlf$
Reg$ = Reg$ + CHR$(34) + "SmallIcons" + CHR$(34)
Reg$ = Reg$ + "="
Reg$ = Reg$ + CHR$(34) + "YES" + CHR$(34) + QbCrlf$
Reg$ = Reg$ + QbCrlf$
RegFile$ = ENVIRON$("windir") + "\Smallico.reg"
EditorFile$ = ENVIRON$("windir") + "\REGEDIT.EXE"
ff = FREEFILE
OPEN RegFile$ FOR BINARY AS #ff
PUT #ff, 1, Reg$
CLOSE #ff
SHELL EditorFile$ + " " + RegFile$
[/tt]

....This just sets the icons in Explorer to a smaller size (substitute "NO" for "YES" if you don't want small icons)... and makes certain assumptions:

1) REGEDIT.EXE is located in the Windows folder ([tt]ENVIRON$("windir")[/tt])
2) The user has permission to modify the registry.
3) The user has nads of steel to run code like this (a typo in the value of Reg$ could add unwanted keys to the registry or possibly corrupt existing values).

User beware.
vcn.gif

Do no harm.​
 
Thanks alt. I know that you can really screw up the registery. I know how to use regedit. Could you put some rem lines in your code. I got confused with all the adding stuff to a string.
 
Sorry, I know this is a little off beat... but I just noticed it in the code on this page...

ALT255,
you used:
Code:
QbCrlf$ = CHR$(13) + CHR$(10)
to declare an end of line character set... used for the following:
Code:
Reg$="REGEDIT4" + QbCrlf$ + QbCrlf$
Reg$ = Reg$ + "[HKEY_LOCAL_MACHINE\"
Reg$ = Reg$ + "SOFTWARE\Microsoft\Windows\"
Reg$ = Reg$ + "CurrentVersion\explorer\SmallIcons]" + QbCrlf$
Reg$ = Reg$ + CHR$(34) + "SmallIcons" + CHR$(34)
Reg$ = Reg$ + "="
Reg$ = Reg$ + CHR$(34) + "YES" + CHR$(34) + QbCrlf$
Reg$ = Reg$ + QbCrlf$

this is just a suggestion but it might make things a little more simple for you (or anyone who reads this) in the future.

you can make a function EOL for End Of Line and have it return N carriage returns:

Code:
Function EOL$(N as integer)
  Temp$ = ""
  For i = 1 to N
    Temp$ = Temp$ + chr$(13) + chr$(10)
  Next
  EOL$ = Temp$
End Function

this way your code would look like this...

Code:
Reg$="REGEDIT4" + EOL$(2)
Reg$ = Reg$ + "[HKEY_LOCAL_MACHINE\"
Reg$ = Reg$ + "SOFTWARE\Microsoft\Windows\"
Reg$ = Reg$ + "CurrentVersion\explorer\SmallIcons]" + EOL$(1)
Reg$ = Reg$ + CHR$(34) + "SmallIcons" + CHR$(34)
Reg$ = Reg$ + "="
Reg$ = Reg$ + CHR$(34) + "YES" + CHR$(34) + EOL$(1)
Reg$ = Reg$ + EOL$(1)

Like I said, this is just a suggestion.
I just though it might help someone out there. Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
I was thinking... (Yes, I know, mark it down in the history book :) )

Would it not be possible to us qb to write an inf file, and have that write to the registery.
 
Chr$(13) + Chr$(10) is the end of a line
Chr$(34) (I believe) is a double quote(")

he is adding all of this to the same string...
then when you write the string to a file it looks like
--- Start File ---
Code:
REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\SmallIcons]
"SmallIcons"="YES"
--- End File ---
ENVIRON$("windir") returns the environment variable "windir" (Windows Directory)
which is "C:\Windows" or "C:\WinNT" depending on your OS...
Code:
RegFile$ = ENVIRON$("windir") + "\Smallico.reg"
EditorFile$ = ENVIRON$("windir") + "\REGEDIT.EXE"
ff = FREEFILE
OPEN RegFile$ FOR BINARY AS #ff
PUT #ff, 1, Reg$
CLOSE #ff
SHELL EditorFile$ + " " + RegFile$
Translates to:
Code:
RegFile$ = "C:\Windows\Smallico.reg"
EditorFile$ = "C:\Windows\REGEDIT.EXE"
OPEN RegFile$ FOR BINARY AS #1
PUT #1, 1, Reg$
CLOSE
SHELL EditorFile$ + " " + RegFile$
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Alt,
Is it possible to use this same method to delete keys from the registry?...

Say if you wanted to delete "\SmallIcons" from:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\SmallIcons
or even go further back and delete "\CurrentVerision" from the same path...

Not that I intend to delete THESE keys...
And, I Suggest no one else delete them either...

let's say, for the sake of argument... you had this key...
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\SpyWare\MoreSpyWare
Which I think is a pretty safe Fake (yet Would-be hated) key
if this key kept getting generated by a hidden program running somewhere on your pc.. could you write a Registry Script file like the one above to delete this key ("\SpyWare") and all keys below it ("\MoreSpyWare"...) Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Wow this post is really getting some attention. Thanks alt for the origenal post. Thanks for making it easier for me CubeE101. So as I see it, you guys write a key with qbasic, and you upload it using regedit. Do windows xp, windows me and windows 2002 use regedit?
 
I don't believe you can use a registry import to delete a key. You might try the regedit /D switch, as in [tt]REGEDIT /D KeyToDelete[/tt].

Regedit comes with all modern flavors of Windows. But you won't find it installed on all Windows systems.
vcn.gif

Do no harm.​
 
I have Regedit...
I just never tried "scripting" to it...

I did everything manually... Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Win ME does have REGEDIT, however, I would recommend that you use the update mode so that the user has the option of canceling.
 
CubeE101:

In regard to deleting keys using a registry file, it can be done. Using your example from above:

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\SpyWare\MoreSpyWare"

To delete "SpyWare" and all within:

---Start---
REGEDIT4

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\SpyWare]

---End---

Note the minus sign in front of HKEY....

Cheers.


Be good. If you can't, don't get caught!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top