The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: skywalker on March 10, 2006, 06:39:37 PM

Title: Write a section to the registry
Post by: skywalker on March 10, 2006, 06:39:37 PM
I appreciate all the help I have gotten. I looked around and pasted some of the help.

I would like to write my own section to the registry and then put some values in.

(I found a GetProfileInt API, but none with the A on the end.)

Thanks.


BOOL WritePrivateProfileString(

    LPCTSTR lpAppName,   // pointer to section name
    LPCTSTR lpKeyName,   // pointer to key name
    LPCTSTR lpString,   // pointer to string to add
    LPCTSTR lpFileName    // pointer to initialization filename
   );

;local   @szBuffer[512]:byte
;
;invoke  WritePrivateProfileString,addr szSec,addr szKey,addr @szBuffer,addr szProfileName

Code:
invoke GetProfileIntA,"MyApp","Counter",1
inc eax ; add 1 to the counter
mov [count],eax
invoke dw2a,offset counter,[count]
invoke WriteProfileStringA,"MyApp","Counter",offset counter
If the section and key do not exist they will be created.
Title: Re: Write a section to the registry
Post by: Tedd on March 10, 2006, 06:50:37 PM
QuoteThe WriteProfileString function copies a string into the specified section of the WIN.INI file.

This function is provided for compatibility with 16-bit Windows-based applications. Win32-based applications should store initialization information in the registry.

You'll want RegCreateKey instead :wink


most of the functions you use end with an 'A' (Ansi) - but it's only to distinguish them internally from the ones ending with 'W' (Wide - sort of not unicode) -- the number of parameters and use is the same for both versions, so the help file simply lists them without the A or W.
..meaning GetProfileInt is the same as GetProfileIntA :wink (and same for WriteProfileString)
Title: Re: Write a section to the registry
Post by: skywalker on March 11, 2006, 08:17:53 AM
Quote from: Tedd on March 10, 2006, 06:50:37 PM
QuoteThe WriteProfileString function copies a string into the specified section of the WIN.INI file.

This function is provided for compatibility with 16-bit Windows-based applications. Win32-based applications should store initialization information in the registry.

You'll want RegCreateKey instead :wink

Thanks. This is what I have been able to come up with so far. I am thinking I need the A ones.

most of the functions you use end with an 'A' (Ansi) - but it's only to distinguish them internally from the ones ending with 'W' (Wide - sort of not unicode) -- the number of parameters and use is the same for both versions, so the help file simply lists them without the A or W.
..meaning GetProfileInt is the same as GetProfileIntA :wink (and same for WriteProfileString)

: The best source of information is MSDN:
:
: From here:
:
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/functions_by_category.asp
:
: click on 'Registry'.
:
: To do it in ASM simply PUSH all parameters in opposite order and CALL the function. Keep in mind that this function has two names:
:
: RegCreateKeyExW - for UNICODE build
: RegCreateKeyExA - for ANSI build
:
:

Thanks.

I found this at their site, it is the same as is in the Win32.hlp file
that I referece first for API calls. The info MS provides assumes the reader has a lot more knowledge and a level of previous programming ability that I don't have yet. I am learning and practicing though.

I'd like to create a key in HKEY_CURRENT_USER.


LONG RegCreateKeyEx(
HKEY hKey,
LPCTSTR lpSubKey,
DWORD Reserved,
LPTSTR lpClass,
DWORD dwOptions,
REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult,
LPDWORD lpdwDisposition
);

Parameters

hKey
[in] Handle to an open key. The calling process must have KEY_CREATE_SUB_KEY access to the key. For more information, see Registry Key Security and Access Rights.

This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:

HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Title: Re: Write a section to the registry
Post by: Pawel Blaszczyk on March 11, 2006, 01:01:30 PM
Hi Everybody!

I wrote following code especially for you :wink:

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

Include windows.inc

Include user32.inc
includelib user32.lib

include kernel32.inc
includelib kernel32.lib

include advapi32.inc
includelib advapi32.lib

.DATA
SubKey BYTE "MyAppKey",0 ;name of sub key in HKEY_CURRENT_USER
CreateOK BYTE "Reg key creating OK",0 ; for report
ValueOK BYTE "Adding registry val. OK",0 ; -||-
Sample BYTE "Sample",0 ; -||-
NewRegValue BYTE "My App's Digit",0 ; Value name
Digit DWORD 1234 ; This variable will be put to the registry

.DATA?
RegH PHKEY ? ; Handle for reg. key

.CODE
Start:

invoke RegCreateKey, HKEY_CURRENT_USER, ADDR SubKey, ADDR RegH ;Create key
.IF EAX == ERROR_SUCCESS ; Error checking
; Code executed, if function succeeds
invoke MessageBox, 0, ADDR CreateOK, ADDR Sample, MB_ICONINFORMATION
invoke RegSetValueEx, RegH, ADDR NewRegValue, 0, REG_DWORD, ADDR Digit, 4
.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR ValueOK, ADDR Sample,MB_ICONINFORMATION
.ENDIF
.ELSE
; Code if create function fails
.ENDIF

invoke RegCloseKey, ADDR RegH

invoke ExitProcess, 0

END Start


I hope it is what you wanted to do. :U
Title: Re: Write a section to the registry
Post by: donkey on March 11, 2006, 01:41:08 PM
If you only want to write a value to the registry there are simple wrapper functions in SHLWAPI that make the job pretty easy...

Write key - SHSetValue (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/registry/shsetvalue.asp)

mov cbData, SIZEOF Data
invoke SHSetValue,HKEY_CURRENT_USER,OFFSET SubKey,offset value,REG_SZ,offset Data,cbData


Read key - SHGetValue (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/registry/shgetvalue.asp)

invoke SHGetValue,HKEY_CURRENT_USER,OFFSET SubKey,offset value,offset dwType,offset Data,offset cbData

For simple registry reads (ie one value) and writes these are more than adequate, however if you are reading multiple values from the same key then it is preferable to open a key and read the values.
Title: Re: Write a section to the registry
Post by: skywalker on March 11, 2006, 02:05:51 PM
Quote from: programmer1989 on March 11, 2006, 01:01:30 PM
Hi Everybody!

I wrote following code especially for you :wink:

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

Include windows.inc

Include user32.inc
includelib user32.lib

include kernel32.inc
includelib kernel32.lib

include advapi32.inc
includelib advapi32.lib

.DATA
SubKey BYTE "MyAppKey",0 ;name of sub key in HKEY_CURRENT_USER
CreateOK BYTE "Reg key creating OK",0 ; for report
ValueOK BYTE "Adding registry val. OK",0 ; -||-
Sample BYTE "Sample",0 ; -||-
NewRegValue BYTE "My App's Digit",0 ; Value name
Digit DWORD 1234 ; This variable will be put to the registry

.DATA?
RegH PHKEY ? ; Handle for reg. key

.CODE
Start:

invoke RegCreateKey, HKEY_CURRENT_USER, ADDR SubKey, ADDR RegH ;Create key
.IF EAX == ERROR_SUCCESS ; Error checking
; Code executed, if function succeeds
invoke MessageBox, 0, ADDR CreateOK, ADDR Sample, MB_ICONINFORMATION
invoke RegSetValueEx, RegH, ADDR NewRegValue, 0, REG_DWORD, ADDR Digit, 4
.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR ValueOK, ADDR Sample,MB_ICONINFORMATION
.ENDIF
.ELSE
; Code if create function fails
.ENDIF

invoke RegCloseKey, ADDR RegH

invoke ExitProcess, 0

END Start


I hope it is what you wanted to do. :U

Thanks, I'll compile it and let you know how it went.

Title: Re: Write a section to the registry
Post by: AsmER on March 11, 2006, 02:48:51 PM
Hi Everybody!

Pawel your code work correct, but you forgot tell Skywalker, about some things that are important (I think):

1.)   4th parameter of RegSetValueEx depends from what programmer want to store in registry.
For other data types this argument should be like follows:
REG_BINARY   Binary data in any form.

REG_DWORD   A 32-bit number.

REG_DWORD_LITTLE_ENDIAN   A 32-bit number in little-endian format (same as REG_DWORD). In little-endian format, the most significant byte of a word is the high-order byte. This is the most common format for computers running Windows NT and Windows 95.

REG_DWORD_BIG_ENDIAN   A 32-bit number in big-endian format. In big-endian format, the most significant byte of a word is the low-order byte.

REG_EXPAND_SZ   A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%"). It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.

REG_LINK   A Unicode symbolic link.

REG_MULTI_SZ   An array of null-terminated strings, terminated by two null characters.

REG_NONE   No defined value type.

REG_RESOURCE_LIST   A device-driver resource list.

REG_SZ   A null-terminated string. It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.

2.)   To read previously saved data from the registry we can use RegQueryValueEx:
LONG RegQueryValueEx(

    HKEY hKey,   // handle of key to query
    LPTSTR lpValueName,   // address of name of value to query
    LPDWORD lpReserved,   // reserved (must be zero )
    LPDWORD lpType,   // address of buffer for value type.
    LPBYTE lpData,   // address of data buffer, which will contain read data
    LPDWORD lpcbData    // address of data buffer size
   );

Regards, AsmER
Title: Re: Write a section to the registry
Post by: skywalker on March 11, 2006, 03:19:54 PM
Quote from: programmer1989 on March 11, 2006, 01:01:30 PM
Hi Everybody!

I wrote following code especially for you :wink:

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

Include windows.inc

Include user32.inc
includelib user32.lib

include kernel32.inc
includelib kernel32.lib

include advapi32.inc
includelib advapi32.lib

.DATA
SubKey BYTE "MyAppKey",0 ;name of sub key in HKEY_CURRENT_USER
CreateOK BYTE "Reg key creating OK",0 ; for report
ValueOK BYTE "Adding registry val. OK",0 ; -||-
Sample BYTE "Sample",0 ; -||-
NewRegValue BYTE "My App's Digit",0 ; Value name
Digit DWORD 1234 ; This variable will be put to the registry

.DATA?
RegH PHKEY ? ; Handle for reg. key

.CODE
Start:

invoke RegCreateKey, HKEY_CURRENT_USER, ADDR SubKey, ADDR RegH ;Create key
.IF EAX == ERROR_SUCCESS ; Error checking
; Code executed, if function succeeds
invoke MessageBox, 0, ADDR CreateOK, ADDR Sample, MB_ICONINFORMATION
invoke RegSetValueEx, RegH, ADDR NewRegValue, 0, REG_DWORD, ADDR Digit, 4
.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR ValueOK, ADDR Sample,MB_ICONINFORMATION
.ENDIF
.ELSE
; Code if create function fails
.ENDIF

invoke RegCloseKey, ADDR RegH

invoke ExitProcess, 0

END Start


I hope it is what you wanted to do. :U

Thanks.

Your code worked fine. Here is some code that is supposed to delete the key that I created from a modification
of your code. I am getting an error saying that some function is supposed to be in block 1 or something like that.



; delkey.asm Delete a registry key
;            Help from Programmer 1989,
.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

SubKey BYTE "Marzipan",0 ;name of sub key in HKEY_CURRENT_USER
Key_Deleted BYTE "Register key sucessfully deleted.",0

.DATA?

RegH PHKEY ? ; Handle for reg. key

.CODE

Start:

jmp begin ; temporary Cliff notes

invoke RegCreateKey, HKEY_CURRENT_USER, ADDR SubKey, ADDR RegH ;Create key
.IF EAX == ERROR_SUCCESS ; Error checking
; Code executed, if function succeeds
invoke MessageBox, 0, ADDR CreateOK, ADDR Sample, MB_ICONINFORMATION

invoke RegSetValueEx, RegH, ADDR NewRegValue, 0, REG_DWORD, ADDR Digit, 4
.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR ValueOK, ADDR Sample,MB_ICONINFORMATION
.ENDIF
.ELSE
; Code if create function fails
.ENDIF

begin:

; Open the key we want to delete

invoke RegOpenKey,RegH,ADDR SubKey,ADDR RegH

invoke RegDeleteKey,HKEY_CURRENT_USER, ADDR SubKey

; Sucess or failure section
;
.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR Key_Deleted, ADDR Sample,MB_ICONINFORMATION
.ENDIF
.ELSE
; Code if function fails
.ENDIF

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


invoke ExitProcess, 0

END Start

Title: Re: Write a section to the registry
Post by: skywalker on March 11, 2006, 03:26:59 PM
Quote from: AsmER on March 11, 2006, 02:48:51 PM
Hi Everybody!

Pawel your code work correct, but you forgot tell Skywalker, about some things that are important (I think):

1.)   4th parameter of RegSetValueEx depends from what programmer want to store in registry.
For other data types this argument should be like follows:
REG_BINARY   Binary data in any form.

REG_DWORD   A 32-bit number.

REG_DWORD_LITTLE_ENDIAN   A 32-bit number in little-endian format (same as REG_DWORD). In little-endian format, the most significant byte of a word is the high-order byte. This is the most common format for computers running Windows NT and Windows 95.

REG_DWORD_BIG_ENDIAN   A 32-bit number in big-endian format. In big-endian format, the most significant byte of a word is the low-order byte.

REG_EXPAND_SZ   A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%"). It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.

REG_LINK   A Unicode symbolic link.

REG_MULTI_SZ   An array of null-terminated strings, terminated by two null characters.

REG_NONE   No defined value type.

REG_RESOURCE_LIST   A device-driver resource list.

REG_SZ   A null-terminated string. It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.

2.)   To read previously saved data from the registry we can use RegQueryValueEx:
LONG RegQueryValueEx(

    HKEY hKey,   // handle of key to query
    LPTSTR lpValueName,   // address of name of value to query
    LPDWORD lpReserved,   // reserved (must be zero )
    LPDWORD lpType,   // address of buffer for value type.
    LPBYTE lpData,   // address of data buffer, which will contain read data
    LPDWORD lpcbData    // address of data buffer size
   );

Regards, AsmER


Thanks for all the extra info.

So if I understand part of what you've listed , I can also use RegSetValueEx to store strings as well in the registry?

Eventually I would like to learn to modify what's already in the created key.

Can the string contain all available characters? (i.e. control chars as well meaning all 256 characters that were
available under DOS)



Title: Re: Write a section to the registry
Post by: Mincho Georgiev on March 11, 2006, 04:00:15 PM
Hi!
I have write several examples in this forum related to the registry. skywalker, if you like, you can use my registry_access module. This is an updated version since i had last post it.



[attachment deleted by admin]
Title: Re: Write a section to the registry
Post by: AsmER on March 11, 2006, 04:30:29 PM
Hi!

Yes Skywalker, you can store text, binary and other data types and use all available characters.
There is anwser for question: 'How to delete reg. key':


; delkey.asm Delete a registry key
;            Help from Programmer 1989,
.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

SubKey BYTE "Marzipan",0 ;name of sub key in HKEY_CURRENT_USER
Key_Deleted BYTE "Register key sucessfully deleted.",0

.DATA?

RegH PHKEY ? ; Handle for reg. key

.CODE

Start:
jmp begin:
...
begin:
; Open the key we want to delete

;invoke RegOpenKey,HKEY_CURRENT_USER,ADDR SubKey,ADDR RegH          ; actually this instruction is NOT required
invoke RegDeleteKey,HKEY_CURRENT_USER, ADDR SubKey

; Sucess or failure section
;
.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR Key_Deleted, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed
.ENDIF

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


invoke ExitProcess, 0

END Start

That is it :dance: But you must remember that registry key which you deleting CAN NOT contain any subkeys. :wink

Regards, AsmER.
Title: Re: Write a section to the registry
Post by: Mark Jones on March 11, 2006, 07:51:08 PM
Skywalker, please don't quote everything a previous poster has said every time. It is very easy for all of us to just scroll up and re-read something if needed. We'll know what you're talking about without the quotes. And quoting entire posts is redundant and wasteful of system resources. :wink
Title: Re: Write a section to the registry
Post by: PBrennick on March 11, 2006, 11:14:52 PM
AsmER

Start:
jmp begin:     ; <===   The colon needs to be removed and there should be a semicolon at the start of the next line
...
begin:


Also, in the data section, Sample is no declared.

Paul
Title: Re: Write a section to the registry
Post by: skywalker on March 12, 2006, 10:43:13 AM
Quote from: Mark Jones on March 11, 2006, 07:51:08 PM
Skywalker, please don't quote everything a previous poster has said every time. It is very easy for all of us to just scroll up and re-read something if needed. We'll know what you're talking about without the quotes. And quoting entire posts is redundant and wasteful of system resources. :wink

Sorry.

Title: Re: Write a section to the registry
Post by: skywalker on March 12, 2006, 10:50:02 AM
Quote
That is it :dance: But you must remember that registry key which you deleting CAN NOT contain any subkeys. :wink

Regards, AsmER.

From what I understand, I can delete nested keys 3 or 4 levels deep as long as I delete them one at a time.
I can't figure out how to add another sub-directory  to my code.

Title: Re: Write a section to the registry
Post by: evlncrn8 on March 12, 2006, 01:58:30 PM
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.
Title: Re: Write a section to the registry
Post by: AsmER on March 12, 2006, 05:16:11 PM
[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).
Title: Re: Write a section to the registry
Post by: 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
Title: Re: Write a section to the registry
Post by: PBrennick on March 12, 2006, 07:11:04 PM
AsmER,
Your example is very nice, though.  You seem to have this registry thing figured out.  :U

Paul
Title: Re: Write a section to the registry
Post by: skywalker on March 12, 2006, 08:14:50 PM
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.
Title: Re: Write a section to the registry
Post by: skywalker on March 12, 2006, 08:58:33 PM
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,
Title: Re: Write a section to the registry
Post by: AsmER on March 13, 2006, 09:01:11 PM
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
Title: Re: Write a section to the registry
Post by: AsmER on March 13, 2006, 09:09:33 PM
Skywalker,

... Do not forget to close SubRegKey & RegH handles by RegCloseKey before ExitProccess procedure.
Title: Re: Write a section to the registry
Post by: skywalker on March 13, 2006, 10:24:06 PM
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
Title: Re: Write a section to the registry
Post by: 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
Title: Re: Write a section to the registry
Post by: skywalker on March 14, 2006, 03:45:38 AM
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 ? :-)



Title: Re: Write a section to the registry
Post by: PBrennick on March 14, 2006, 01:40:04 PM
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
Title: Re: Write a section to the registry
Post by: AsmER on March 14, 2006, 05:32:37 PM
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
Title: Re: Write a section to the registry
Post by: 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
Title: Re: Write a section to the registry
Post by: skywalker on March 14, 2006, 06:08:06 PM
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. :-)