Please help me how to create String Value Data in the registry

Started by stanley, October 14, 2009, 12:52:44 AM

Previous topic - Next topic

stanley

I have created up to string value name in the registry and code is below

.386
.model flat,stdcall
option casemap: none
include \masm32\include\windows.inc
include \masm32\include\advapi32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\kernel32.lib
.data
szTestKey db "SOFTWARE\stanely",0
szStringValueName db "help",0
.code
start:
SetRegString proto :dword,:dword,:dword,:dword
SetRegString proc hkey:dword,lpszkeyname:dword,lpszvaluename:dword,lpszstringname:dword
local disp:dword
local pkey:dword
local dwsize:dword
invoke RegCreateKeyEx,HKEY_CURRENT_USER,addr szTestKey,NULL,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,addr pkey,addr disp
.if eax== ERROR_SUCCESS
invoke lstrlen,lpszstringname
mov dwsize,eax
invoke RegSetValueEx,pkey,addr szStringValueName,NULL,REG_SZ,NULL,dwsize
push eax
invoke RegCloseKey,pkey
pop eax
.endif
ret
SetRegString endp
end start

Help me how to add String Value Data in the registry or above code and Kindly  explain  me with an simple example.

Please help me out with this post as soon as possible

dedndave

it isn't that hard - and you have a good start, Stanley
doesn't that code work for you ?
one thing you may be bumping into is permissions
if you are running vista or newer, i think you have to have administrator privileges to write into the registry
you can right-click on the program - then, Run As

oh - lol

.code
start:
SetRegString proto :dword,:dword,:dword,:dword
SetRegString proc hkey:dword,lpszkeyname:dword,lpszvaluename:dword,lpszstringname:dword

you have no program - lol
as a minimum...

.code
start:
invoke SetRegString,hkey,lpszkeyname,lpszvaluename,lpszstringname
invoke ExitProcess,0

also, i suggest you place the PROTO near the beginning (i usually place mine after the INCLUDEs, but before .DATA)
they need to appear in the file before they are INVOKED, or you will get "Symbol not defined"

stanley

Quote from: dedndave on October 14, 2009, 01:10:45 AM
it isn't that hard - and you have a good start, Stanley
doesn't that code work for you ?
one thing you may be bumping into is permissions
if you are running vista or newer, i think you have to have administrator privileges to write into the registry
you can right-click on the program - then, Run As

oh - lol

.code
start:
SetRegString proto :dword,:dword,:dword,:dword
SetRegString proc hkey:dword,lpszkeyname:dword,lpszvaluename:dword,lpszstringname:dword

you have no program - lol
as a minimum...

.code
start:
invoke SetRegString,hkey,lpszkeyname,lpszvaluename,lpszstringname
invoke ExitProcess,0

also, i suggest you place the PROTO near the beginning (i usually place mine after the INCLUDEs, but before .DATA)
they need to appear in the file before they are INVOKED, or you will get "Symbol not defined"



Thank you for your kind reply

The Code works good for me and i want to no where i should pass the string value data in the code?

The output of the code i got is below:
HKEY_CURRENT_USER\SOFTWARE\stanely\help:" ? "

I want to store data in the registry value data field(" ? ").so please give me a sample program or template  which will help me to understand better

thank you Dedndave

dedndave

ohhhhhhhhhhhh
you want to write to the key's default value
for that, use a null string:
valueName db 0
lpszstringname is where you pass the data (string) that you want to set it to (terminated with a null)

stanley

Quote from: dedndave on October 14, 2009, 04:06:35 AM
ohhhhhhhhhhhh
you want to write to the key's default value
for that, use a null string:
valueName db 0
lpszstringname is where you pass the data (string) that you want to set it to (terminated with a null)

Thank You Dedndave  It works now.