News:

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

General question about accessing the system registry

Started by Shooter, December 19, 2010, 10:44:34 PM

Previous topic - Next topic

dedndave


Shooter

Quote from: dedndave on December 20, 2010, 12:03:15 AM
well - you are not following the steps   :P

step 1) open the key and subkey (HKEY_LOCAL_MACHINE and "SOFTWARE\Microsoft\Windows\CurrentVersion" in my example)
step 2) read the registry value under that key

which step is failing ?
are you getting a valid handle from RegOpenKeyEx ???
if not, use GetLastError to retrieve an error code

post your updated code

Here it is. And nope, I'm not getting a valid handle from RegOpenKeyEx. My error occurs right after this:

.if eax==WM_INITDIALOG
;initialization here
   invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE,addr lpszSubKey,0,KEY_QUERY_VALUE,addr hKey
   cmp eax,ERROR_SUCCESS


With these variables:
   lpszSubKey DB  "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0
   lpszValueName   DB  "ComputerName",0
.data?
   lpbData DD 256 Dup (?)
   lpcbData    DD  ?
   hKey        DD  ?
   lpdwType    DD  ?
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

sinsi

Try this
   lpszSubKey DB "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0
Light travels faster than sound, that's why some people seem bright until you hear them.

Shooter

Quote from: sinsi on December 20, 2010, 12:23:32 AM
Try this
   lpszSubKey DB "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0

That took care of the RegOpenKeyEx, and RegQueryValueEx is returning with eax=EA (ERROR_MORE_DATA), so I'm now just needing to do that buffer thing that was discussed.  :U :bg :green

Thanks, Sinsi.

And Dave,
I tried your suggestion and it returned the same as above. WOO-HOO, we be makin' tracks now. lol

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Gunner

 lpszSubKey   DB  "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0

This is incorrect... you can't copy and paste from regedit... You ALREADY open HKLM, so get rid of that...

should be:
lpszSubKey   DB  "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Shooter

Quote from: Gunner on December 20, 2010, 12:32:20 AM
lpszSubKey   DB  "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0

This is incorrect... you can't copy and paste from regedit... You ALREADY open HKLM, so get rid of that...

should be:
lpszSubKey   DB  "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0


Now you see, how hard is it to include that in the stupid manual??? lol.

Thanks, Gunner!

Now it's just time to move on and move up, right?

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Gunner

Um, it is in the manual  :toothy

QuotehKey
[in] Handle to an open key. 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
Windows 95/98/Me: HKEY_DYN_DATA

lpSubKey
[in] Pointer to a null-terminated string containing the name of the subkey to open. If this parameter is NULL or a pointer to an empty string, the function will open a new handle to the key identified by the hKey parameter. In this case, the function will not close the handles previously opened.
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

see attached
i also left out RegCloseKey   :P
not bad from memory, though

Gunner

Quote from: Shooter on December 20, 2010, 12:35:58 AM
Thanks, Gunner!

Now it's just time to move on and move up, right?

-Shooter

Your welcome...  Move on?  don't get discouraged with the registry... it is a different beast, but once you get the basics down, it is not all that bad... I have done much with the registry... but a lot of knowledge was gained...
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

Quote"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName",0
that's where you were going wrong
the HKEY_LOCAL_MACHINE is actually an EQUate in windows.inc
the registry keys have pre-defined handle values
so that part is not included in the subkey string text

Shooter

The problem that I, as a beginner, ran into was not knowing how the registry is broken down. (Still don't know.  :red)

HKxx
   SYSTEM
       (Key or SubKey??)
             (SubKey)
                   |
                   |
                 (Value)
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Gunner

Think of it like this...  The root keys:
HKCR
HKCU
HKLM
HKU
HKCC
They are like houses, each on is a house...

each key/subkey in the "house" is like a book in a room
and each value is like a page in the book....

Enter the house (Root Key)
Goto a room (key/subkey)
open the book and read the page  :toothy


as you say you are a beginner, BE VERY CAREFUL!  you can screw up your machine if a subkey/value/rootkey is misnamed
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave


Shooter

Just to give you an idea of what I'm trying to get accomplished, here's what I'm looking at:

I work for a contracting company that installs basically a telephone PBX that interfaces with two-way radios and a computer at an operators station. Some of the work I do is replace the existing touchscreen and the pc with an all-in-one touchscreen/pc. When we do this we have to make the new computer's name and settings match the old one. Part of the problem is that since these are touch screens a keyboard and mouse aren't available.

My thinking was that I could make a program that would launch (autorun.exe) upon inserting a usb drive on the old computer, grab all the goodies, and put them into the new computer (again with autorun.exe), all without a keyboard or mouse. That's the goal anyway.

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Shooter

Quote from: dedndave on December 20, 2010, 01:04:47 AM
did you download my attachement ???

http://www.masm32.com/board/index.php?topic=15695.msg129183#msg129183

it worked for me - spits out my computer name

Yep, and that's exactly what I was looking for.

Thanks, Dave.  :dance:

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.