News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Write a section to the registry

Started by skywalker, March 10, 2006, 06:39:37 PM

Previous topic - Next topic

evlncrn8

simple, you create another key (regcreatekey) again, except in the part where you pass HKEY_BLAH_BLAH etc, you pass the HANDLE of the key you have already opened inwhich you want to create the subkey... try msdn, theres a lot of information there, registry is simple once you read all the information

LONG RegCreateKey(

    HKEY hKey,   // handle of an open key
    LPCTSTR lpSubKey,   // address of name of subkey to open
    PHKEY phkResult    // address of buffer for opened handle
   );   
Parameters

hKey

Identifies a currently open key or any of the following predefined reserved handle values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
The key opened or created by this function is a subkey of the key identified by hKey.

lpSubKey

Points to a null-terminated string specifying the name of a key that this function opens or creates. This key must be a subkey of the key identified by the hKey parameter.

If hKey is one of the predefined keys, lpSubKey may be NULL. In that case, the handle returned by using phkResult is the same hKey handle passed in to the function.

phkResult

Points to a variable that receives the handle of the opened or created key.

AsmER

[FOR PBrennick]
Yes... PBrennick you are right. after begin shouldn't be colon sign.
I know that I didn't define sample, I just copied skywalker's code & corrected only the most important thing for him (so now it deleting the registry key).

AsmER

skywalker,

To add sub-key to your registry key you must do following things:
- open reg. key ( in your program marzipan key ) by RegOpenKey with parameters: HKEY_CURRENT_USER, ADDR SubKey, RegH
(where SubKey is varaible containing "Marzipan" bytes string and RegH is definied as PHKEY),
- In RegCreateKeyEx first parameter must be value returned by RegOpenKey (RegH).
And it will work.

Good luck, AsmER :8)
;If you do not know how to do it, tell me -I will try to find a minute and write correct source code for you. :wink

PBrennick

AsmER,
Your example is very nice, though.  You seem to have this registry thing figured out.  :U

Paul
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: AsmER on March 12, 2006, 05:32:52 PM
skywalker,

To add sub-key to your registry key you must do following things:
- open reg. key ( in your program marzipan key ) by RegOpenKey with parameters: HKEY_CURRENT_USER, ADDR SubKey, RegH
(where SubKey is varaible containing "Marzipan" bytes string and RegH is definied as PHKEY),
- In RegCreateKeyEx first parameter must be value returned by RegOpenKey (RegH).
And it will work.

Good luck, AsmER :8)
;If you do not know how to do it, tell me -I will try to find a minute and write correct source code for you. :wink


I think I understand what your saying. I was putting HKEY_CURRENT_USER\marzipan\ and the compiler didn't like
that.
I'll post what I come up with.

Thanks.

skywalker

Quote from: AsmER on March 12, 2006, 05:32:52 PM
skywalker,

To add sub-key to your registry key you must do following things:
- open reg. key ( in your program marzipan key ) by RegOpenKey with parameters: [

This is what I came up for the first 3 parameters, couldn't figure out the last 5. I think I need a structure setup
and some other items in the data section.

When a subkey is put in the registry, can it be determined when it was put in ?

SubKey       BYTE "Marzipan",0                 ; name of sub key in HKEY_CURRENT_USER
NewLevel     BYTE "basement",0

RegH PHKEY ? ; Handle for registry key

;LONG RegCreateKeyEx(  HKEY hKey,   // handle of an open key
;    LPCTSTR lpSubKey,   // address of subkey name
;    DWORD Reserved,   // reserved
;    LPTSTR lpClass,   // address of class string
;    DWORD dwOptions,   // special options flag
;    REGSAM samDesired,   // desired security access
;    LPSECURITY_ATTRIBUTES lpSecurityAttributes,   // address of key security structure
;    PHKEY phkResult,   // address of buffer for opened handle 
;    LPDWORD lpdwDisposition    // address of disposition value buffer

invoke RegOpenKey, HKEY_CURRENT_USER, ADDR SubKey,RegH
invoke RegCreateKeyEx,RegH,ADDR NewLevel,0,

AsmER

Hi again, Skywalker!

This time quick answer (Sorry but I have a Hardware & Software assignment to do... College is college :toothy):

.data
...
APPKey     BYTE "Marzipan", 0
SubKey     BYTE "basement", 0

.data?
...
SubRegKey    PHKEY   ?
RegH        PHKEY   ?

.code
...
invoke RegOpenKey, HKEY_CURRENT_USER, ADDR APPKey, ADDR RegH         ;to get handle of already created reg. key. (marzipan)
invoke RegCreateKey, RegH, ADDR SubKey, SubRegKey                    ;to create (>>or open if already exist<<) sub reg. key


I used RegCreateKey because it is more easy than RegCreateKeyEx (And I don't have to explain it :8) - yes sometimes I'm lazy but at the end it is enought to create sub key in reg.)

Regards, AsmER
;I wonder if I could see my nick in your program's about... 
;joking  :lol, but if you haven't anything against...  anyway good luck :U

AsmER

Skywalker,

... Do not forget to close SubRegKey & RegH handles by RegCloseKey before ExitProccess procedure.

skywalker

Quote from: AsmER on March 13, 2006, 09:09:33 PM
Skywalker,

... Do not forget to close SubRegKey & RegH handles by RegCloseKey before ExitProccess procedure.

Assembles OK, but regedit doesn't want to start after running this. Says regedit fails to initialize.

; creatsub.asm  Create a subkey of an existing registry key
;               Help from AsmER,
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\advapi32.inc

    include \masm32\macros\macros.asm

    includelib  \masm32\lib\kernel32.lib
    includelib  \masm32\lib\user32.lib
    includelib  \masm32\lib\advapi32.lib

.DATA



APPKey        BYTE "Marzipan", 0
SecondKey     BYTE "basement", 0

.DATA?

RegH         PHKEY      ? ; Handle for registry key
SubRegKey    PHKEY      ?

.CODE

Start:

invoke RegOpenKey, HKEY_CURRENT_USER, ADDR APPKey, ADDR RegH   ;to get handle of already created
                                                               ;reg. key. (marzipan)

invoke RegCreateKey, RegH, ADDR SecondKey, SubRegKey  ;to create (>>or open    
                                                   ;already exist<<) sub reg. key

invoke RegCloseKey, ADDR RegH      ; close handle for reg. key
invoke RegCloseKey, ADDR SubRegKey ; close handle for reg. key


invoke ExitProcess, 0

END Start

PBrennick

skywalker,
I sure hope you have set a restore point on that machine (if it is XP).  You really need to have a backup of the registry.

You really need to have a backup of the registry. :red

Paul
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: PBrennick on March 13, 2006, 11:04:42 PM
skywalker,
I sure hope you have set a restore point on that machine (if it is XP).  You really need to have a backup of the registry.

You really need to have a backup of the registry. :red

Paul


Doesn't XP sets a restore point whenever major changes are done such as software installation ?

Does that mean you don't see any problems with my code ? :-)




PBrennick

skywalker,
I do not believe that a restore point is set everytime a piece of software is installed unless you request one each time; but this has absolutely NOTHING to do with what you are doing here, today.  You are running experimental software, not installing software.

So you are running experimental software that is manipulating a key part of the OS without taking some steps to protect your machine.  I am really concerned, here.  I think you should stop what you are doing and check your machine.  Once you are sure that your machine is running properly, create a restore point and then go back to developing this application.

Be sure to set a new restore point if you install any software no matter how your testing is going.  It is all about being careful.  If you are forgetful, print yourself a memo about this and tape it to your monitor.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

AsmER

Skywalker,

Very well done but...
As you can see you (we :lol) defined 2 little variables like follows:
RegH         PHKEY      ? ; Handle for registry key
SubRegKey    PHKEY      ?

After all operations with registry, we try to close them, and that is normal...
-Only one thing is wrong (but don't worry, nothing horrible to fix)
To close these keys we using RegCloseKey with parameter of HKEY type. - HKEY = Handle KEY = key handle
Our variables unfortunately aren't HKEY type, they are PHKEY = Pointer Handle KEY = pointer to handle of the key
So your code simply don't sending HKEY to RegCloseKey procedure it sending address of pointer to handle of the key (I know it can confuse you a bit)
TIP: always check if you sending to a function thing which it except from you and your life will be easier (as well as your computer's life :toothy)

Paul (aka AsmER)

P.S
If you do not understand what I tried to tell you - basically you do not need use ADDR operator when calling RegCloseKey procedure

AsmER

As a lot of people says: It is recommended to learn some HLL. It giving you good foundation to write programs in programming language like assembler.
Or just simply download Win32HELP from the internet - then you will not have any problems like you just have. :wink

skywalker

Quote from: AsmER on March 14, 2006, 05:53:17 PM
As a lot of people says: It is recommended to learn some HLL. It giving you good foundation to write programs in programming language like assembler.
Or just simply download Win32HELP from the internet - then you will not have any problems like you just have. :wink

Thanks for your help and patience. I started writing C and C++, but after working with assembly, I decided
it was worth the extra effort.

I have the Win32.hlp, both the small version and the large. I just dled the SDK and will be looking at it's newer
API help as per Donkey's recommendation.

Whenever I hear something from someone, I keep in mind what a good friend once told me.

Why are they telling me this.

I help anyone who needs help and I do it cheerfully.

Later gater. :-)