Link to home
Start Free TrialLog in
Avatar of Mark_FreeSoftware
Mark_FreeSoftwareFlag for Netherlands

asked on

small registry function


hello experts,

i am developing an application that has to be as small as possible,
but now i discover i need to write to the registry

what would be the smallest and most portable way?
Avatar of EDDYKT
EDDYKT
Flag of Canada image

what do you mean by small?

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\MyRegKey\", "Top level key"


from

https://www.experts-exchange.com/questions/11153287/VBScript-how-to-access-the-registry.html
Avatar of kaliyugkaarjun
kaliyugkaarjun


SaveSetting, GetSetting: are 2 functions used in vb6 mostly

SaveSetting= write to registry

GetSetting = read fro mregistry

SaveSetting "MyCompany\MyAppName", "Printers", "Pr1", "def printer"
....or...
SaveSetting "MyCompany", "MyAppName\Printers", "Pr1", "def printer"

Just be sure the args do ~not~ include leading or trailing delimiters.
VB does not filter them and the underlying registry Api chokes on
them.

If you need to go beyond "HKEY_CURRENT_USER\Software\VB and VBA
Program Settings", then you'll need to use the registry Api. There are
a number of free reg classes and code, including one of the more popular at

http://vbaccelerator.com/home/index.asp

This depends, do you want to rely on scripting? Do you want to use API?

What exactly do you need? Do you need to write to a part of the registry that already exists or do you need to create your own key? Are you only saving values or are you going to need to query the values as well?

If you only need to write values than it can be done in 4-5 lines using API
SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark_FreeSoftware

ASKER


ok some more explanation:


by small i do mean as less bits as possible
(so i don't care about 100 lines code, i do care about the compiled size)

i only have to write to it (now)

most of the times i have to create new keys,
sometimes delete them


i want as few refereces as possible

i do now have references to:
kernel32 (copymem)
comdlg32l (getopenfilename)
user32 (region stuff,and sendmessage)
gdi32 (ExtCreateRegion)




@ EDDYKT :
do i have to include some dll for wscript?


@kaliyugkaarjun :
i have to go beyond the vb/vba key

and the vbaccelerator examples are great, but they are not really "small"
>>do i have to include some dll for wscript?

no, it's already come with the system

maybey i am doing somthing wrong, but when i use the wscript example,
vb states that "WScript" is an unknow variable
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

thank you!

that is indeed really small, but i don't understand it very good.

please see this question for exaplaining it a bit:
https://www.experts-exchange.com/questions/21892807/WScript-registry-function.html




i am thinking about a split between eddykt (350)
and egl1044 (150)


is that ok for both of you?
there both the same size in bytes

not really:

the wscript exe:
16.384 bytes

the api exe:
20.480 bytes

what i did to test it:

open a new default project
now doubleclick on the form to go to the Form_Load
for the wscript i pasted all the code in the form_load (3 lines)

for the api i pasted all code above the form load, exept for the last lines
(Dim Success As Long
    Success = WriteValue(HKEY_CURRENT_USER, _
        "Software\NEWKEY", _
        "name", _
        "data to write"))

compiled the first as wscript.exe
and the second as api.exe

and the filesize is different
not if you put the code in a module

20.480 bytes when i put that code in a module


what are your compiler options?

i have it set to compile for small exe
i get 16K for both but this is without using a form

weird,


then it's a even split between you and eddykt