Solved

RegSetValueEx

Posted on 1997-11-18
2
974 Views
Last Modified: 2012-11-30
Eeeehm,I last time asked how to use Regqueryvalueex. Now I know and it works just great. Now I want to use RegSetValueEx and can't work that one out. Could someone explain to me the datatypes used and give a little example?
(I'm afraid my 4GL background lacks this sort of knowledge.)
0
Comment
Question by:lizzzard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1350840
Hi

The most common types of data are strings (REG_SZ), Numbers (REG_DWORD) and Binary Data (REG_BINARY).  Here is an example using those 3 types:

procedure TForm1.Button1Click(Sender: TObject);
var
  hReg, TestInt: Integer;
  TestStr: string;
  TestBin: array[0..100] of Byte;
begin
  // Open or Create the registry key.
  if (RegOpenKey(HKEY_CURRENT_USER, 'Software\TestComp\TestApp', hReg) <> ERROR_SUCCESS) then
    RegCreateKey(HKEY_CURRENT_USER, 'Software\TestComp\TestApp', hReg);

  // Write a string value.
  TestStr := 'This is a test value.';
  RegSetValueEx(hReg, PChar('Test String'), 0, REG_SZ, PChar(TestStr), Length(TestStr));

  // Write an integer value.
  TestInt := 100;
  RegSetValueEx(hReg, PChar('Test Int'), 0, REG_DWORD, @TestInt, SizeOf(DWORD));

  // Write some binary data.
  FillChar(TestBin, SizeOf(TestBin), 0);
  RegSetValueEx(hReg, PChar('Test Binary'), 0, REG_BINARY, @TestBin, SizeOf(TestBin));

  // Close the registry key.
  RegCloseKey(hReg);
end;

Note that often numbers are stored as strings using Delphi's IntToStr and StrToInt functions.

Regards,
JB
0
 

Expert Comment

by:dkep
ID: 38648432
Also I believe it is the best practice to call the RegFlushKey() function prior to closing the registry key (I.E. RegCloseKey())
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question