flat assembler
Message board for the users of flat assembler.

Index > Windows > Need Registry Access Example

Author
Thread Post new topic Reply to topic
robink



Joined: 17 Sep 2003
Posts: 14
robink 12 Mar 2004, 19:17
If this has been answered before please point me to the message(s). I really need a small example in FASM of how to access the Registry in Windows 2000/XP. Any help would be really appreciated. Thanks for the bandwidth.

_________________
Thanks,

Robin
Post 12 Mar 2004, 19:17
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 15 Mar 2004, 18:56
Why don't you use commands declared in advapi32.dll, or are you aiming to some 2k/Xp specific code in assembly Confused
There are RegCloseKey
RegCreateKey
RegCreateKeyEx
...etc...
Post 15 Mar 2004, 18:56
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Rookie



Joined: 21 Aug 2003
Posts: 44
Location: Planet Romania
Rookie 16 Mar 2004, 21:16
This will create "HKEY_LOCAL_MACHINE\Software\Registry\Example" and store the exe path in the ExePath key:
Code:
format PE GUI 4.0

include '%fasminc%\win32a.inc'

  Start:
        invoke  GetProcessHeap
        mov     [lpHeap],eax
        invoke  HeapAlloc,[lpHeap],HEAP_ZERO_MEMORY,8000h
        mov     [lpModName],eax

        invoke  GetModuleFileName,NULL,[lpModName],8000h
        mov     [lpModSize],eax
        mov     eax,[lpModName]
        invoke  CharLower,[lpModName]
        add     eax,[lpModSize]
  @@:
        cmp     byte [eax],5Ch
        je      @f
        dec     eax
        dec     [lpModSize]
        jmp     @b
  @@:
        inc     [lpModSize]
        mov     byte [eax],0

        invoke  RegCreateKeyEx,HKEY_LOCAL_MACHINE,lpSubKey,0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,phkResult,lpdwDisp
        cmp     eax,0
        jne     IsNOk
        invoke  RegSetValueEx,[phkResult],lpExePth,0,REG_SZ,[lpModName],[lpModSize]
        cmp     eax,0
        jne     IsNOk

        invoke  MessageBox,0,msgOk,caption,MB_ICONINFORMATION+MB_OK
        jmp     exit

  IsNOk:
        invoke  MessageBox,0,msgNOk,caption,MB_ICONERROR+MB_OK

  exit:
        invoke  RegCloseKey,phkResult
        invoke  HeapFree,[lpHeap],0,[lpModName]
        invoke  ExitProcess,0

caption   db 'Registry Example',0
msgOk     db 'I may have been able to succesfully update the registry.',0
msgNOk    db 'I''m sorry, but I have failed you. The registry was not set up correctly.',0

lpSubKey  db 'Software\Registry\Example',0
lpExePth  db 'ExePath',0

lpHeap    dd ?
lpModName dd ?
lpModSize dd ?
phkResult dd ?
lpdwDisp  dd ?

data import

 library kernel32,'kernel32.dll',\
         user32,'user32.dll',\
         advapi32,'advapi32.dll'

 import kernel32,\
        GetProcessHeap,'GetProcessHeap',\
        HeapAlloc,'HeapAlloc',\
        HeapFree,'HeapFree',\
        GetModuleFileName,'GetModuleFileNameA',\
        ExitProcess,'ExitProcess'

 import user32,\
        CharLower,'CharLowerA',\
        MessageBox,'MessageBoxA'

 import advapi32,\
        RegCreateKeyEx,'RegCreateKeyExA',\
        RegSetValueEx,'RegSetValueExA',\
        RegCloseKey,'RegCloseKey'

end data
    

Hope you find it useful.

_________________
This is who I choose to be.
Post 16 Mar 2004, 21:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.