Unit
Windows.PasSyntax
RegOpenKeyEx(
hKey: HKEY; {handle of the parent key to open}
lpSubKey: PChar; {the sub key name}
ulOptions: DWORD; {reserved}
samDesired: REGSAM; {key security requested}
var phkResult: HKEY {handle of new open key}
): Longint; {returns an error code}Description
This function is used to open an existing sub key in the registry or to open another handle to an open key.Parameters
hKey: This can be any open key or one of the following root key values.HKEY_CLASSES_ROOTHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_USERSlpSubKey: A pointer to a null terminated string that contains the name of the sub key to open. If this parameter points to an empty string, the function will open another handle to the key identified by the hKey parameter.ulOptions: Reserved for future use. Set this parameter to zero.samDesired: Specifies the security access option requested.phkResult: A variable that will receive the new handle to the opened key.Return Value
If the function succeeds, it returns ERROR_SUCCESS. If the function fails, it returns an error code that can be used with the FormatMessage function to retrieve an error message.The Tomes of Delphi 3: Win32 Core API Help File by Larry DiehlE:
function OpenNodeKey(sNode: TTreeNode; var KeyName: string): hKey;
var
iNode: TTreeNode; // a tree node pointer
RootKey: hKey; // a handle to the root key of the specific node
begin
{initialize the temporary pointer to the specified treenode}
iNode := sNode; {initialize the root key handle}
RootKey := 0; {begin working our way up the tree until we hit the root, building a comprehensive registry key name from the treenode strings.}
if sNode.Level > 1 then
begin
KeyName := sNode.Text;
iNode := sNode.Parent;
while iNode.Level > 1 do
begin
KeyName := iNode.Text+'\'+KeyName;
iNode := iNode.Parent;
end;
end; {retrieve the root key for the specified node}
case iNode.Index of 0: RootKey := HKEY_CLASSES_ROOT;
1: RootKey := HKEY_CURRENT_USER;
2: RootKey := HKEY_LOCAL_MACHINE;
3: RootKey := HKEY_USERS;
4: RootKey := HKEY_PERFORMANCE_DATA;
5: RootKey := HKEY_CURRENT_CONFIG;
6: RootKey := HKEY_DYN_DATA;
end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
Windows.PasSyntax
RegOpenKeyEx(
hKey: HKEY; {handle of the parent key to open}
lpSubKey: PChar; {the sub key name}
ulOptions: DWORD; {reserved}
samDesired: REGSAM; {key security requested}
var phkResult: HKEY {handle of new open key}
): Longint; {returns an error code}Description
This function is used to open an existing sub key in the registry or to open another handle to an open key.Parameters
hKey: This can be any open key or one of the following root key values.HKEY_CLASSES_ROOTHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_USERSlpSubKey: A pointer to a null terminated string that contains the name of the sub key to open. If this parameter points to an empty string, the function will open another handle to the key identified by the hKey parameter.ulOptions: Reserved for future use. Set this parameter to zero.samDesired: Specifies the security access option requested.phkResult: A variable that will receive the new handle to the opened key.Return Value
If the function succeeds, it returns ERROR_SUCCESS. If the function fails, it returns an error code that can be used with the FormatMessage function to retrieve an error message.The Tomes of Delphi 3: Win32 Core API Help File by Larry DiehlE:
function OpenNodeKey(sNode: TTreeNode; var KeyName: string): hKey;
var
iNode: TTreeNode; // a tree node pointer
RootKey: hKey; // a handle to the root key of the specific node
begin
{initialize the temporary pointer to the specified treenode}
iNode := sNode; {initialize the root key handle}
RootKey := 0; {begin working our way up the tree until we hit the root, building a comprehensive registry key name from the treenode strings.}
if sNode.Level > 1 then
begin
KeyName := sNode.Text;
iNode := sNode.Parent;
while iNode.Level > 1 do
begin
KeyName := iNode.Text+'\'+KeyName;
iNode := iNode.Parent;
end;
end; {retrieve the root key for the specified node}
case iNode.Index of 0: RootKey := HKEY_CLASSES_ROOT;
1: RootKey := HKEY_CURRENT_USER;
2: RootKey := HKEY_LOCAL_MACHINE;
3: RootKey := HKEY_USERS;
4: RootKey := HKEY_PERFORMANCE_DATA;
5: RootKey := HKEY_CURRENT_CONFIG;
6: RootKey := HKEY_DYN_DATA;
end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
解决方案 »
- 执行存储过程出错
- 关于WebBrowser的使用
- 讨论:用netmeeting的做服务的问题!!
- 起床了,发现裤衩多了一个,高兴。。。。。散分!!!
- 各位大哥,哪有FreeQQ下载?推荐一种免费的局域网QQ也可!!!
- 我能在DELPHI 程序中 拦截 不是指向本程序窗体 WINDOWS消息吗?
- 急!报表里怎么画斜线?在线等。
- 请问:怎样判断一个ip是否在一个ip的范围内呢?
- 求最大值的语句怎么错了,请进来看看,谢谢!
- Delphi中如何消除屏幕中的窗体呢?,请高手指教???(程序如下,在线等待)
- 数据库存为1999,怎么显示为一九九九??
- 自从装了SQL SERVER之后,tadoquery.close不能用了
Windows.PasSyntax
RegCloseKey(
hKey: HKEY {handle of the key to close}
): Longint; {returns an error code}Description
This function releases the open registry key handle retrieved from a prior call to the RegCreateKeyEx or RegOpenKeyEx functions. Calling RegClose key does not guarantee that a new value is written to the registry. The system can take up to a several seconds to write the new values. To guarantee that all values are written to the registry, call the RegFlushKey function.Parameters
hKey: Specifies the handle of the registry key to close.Return Value
If the function succeeds, it returns ERROR_SUCCESS. If the function fails, it returns an error code that can be used with the FormatMessage function to retrieve an error message.The Tomes of Delphi 3: Win32 Core API Help File by Larry DiehlE:
procedure TForm1.Key1Click(Sender: TObject);
var
KeyName: string; // holds a registry key name
NewName: string; // holds the new registry key name
nKey, // holds handles the opened and new keys
pKey: hKey;
KeyResult: DWORD; // holds the disposition value
begin
{retrieve the name for the new key}
NewName := InputBox('Enter new Key ','Enter New Key Name',''); {if a name was specified, open the parent key from the selected treenode}
pKey:=0;
if NewName <> '' then
pKey := OpenNodeKey(TreeView1.Selected, KeyName); {if the parent key was opened...}
if pKey = 0 then
ShowMessage('Error opening parent key')
else
begin
{...create a new child key with the specified name}
RegCreateKeyEx(pKey, PChar(NewName), 0, nil, 0, Key_All_Access, nil, nKey, @KeyResult); {if the key did not already exist, add it to the treeview}
if KeyResult = REG_OPENED_EXISTING_KEY then
ShowMessage('Key Already Exists')
else
begin
TreeView1.Selected:=TreeView1.Items.AddChild(TreeView1.Selected,NewName);
TreeView1.Selected.ImageIndex := 0;
TreeView1.Selected.SelectedIndex := 1;
end; {close both the parent key and the child key} RegCloseKey(nKey);
RegCloseKey(pKey);
end;
end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
Windows.PasSyntax
RegDeleteKey(
hKey: HKEY; {handle to the parent key of the sub key to delete}
lpSubKey: PChar {specifies the name of the key to delete}
): Longint; {returns an error code}Description
This function is used to delete a sub key from inside of a parent key. The function deletes the sub key and all of its associated values from the registry.ParametershKey: Specifies the handle of the parent key of the sub key to delete. This can be any open key or one of the following root key values.HKEY_CLASSES_ROOTHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_USERSlpSubKey: A pointer to a null terminated string that contains the name of the sub key to delete.Return Value
If the function succeeds, it returns ERROR_SUCCESS. If the function fails, it returns an error code that can be used with the FormatMessage function to retrieve an error message.The Tomes of Delphi 3: Win32 Core API Help File by Larry DiehlE:
procedure TForm1.DeleteKey2Click(Sender: TObject);
var
KeyName: string; // holds the name of the key to be deleted
pValueName: array[0..100] of char; // holds the value name
pKey: hKey; // the handle of the key to be deleted
begin
{insure that the user has not elected to delete a base key}
if TreeView1.Selected.Level <= 1 then ShowMessage('Cannot Delete base Keys')
else
{confirm that the selected key is to be deleted}
if MessageBox(Form1.Handle, 'Are you sure you want to delete this registry'+
' key?', 'Confirmation Box', MB_OKCANCEL) = IDOK then
begin
{open the selected key's parent}
pKey := OpenNodeKey(TreeView1.Selected.Parent, KeyName); if pKey = 0 then ShowMessage('Cannot open parent key')
else
begin
StrPCopy(pValueName, TreeView1.Selected.Text);
{if the parent key was opened, delete the selected key}
if RegDeleteKey(pKey, pValueName)= 0 then
TreeView1.Items.Delete(TreeView1.Selected)
else
ShowMessage('Could not delete key');
end;
end;
end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
..........
var
Reg:TRegIniFile;
S:String;
..........
Reg:=TRegIniFile.Create;
Reg.WriteString('Key','Title','Value');
S:=Reg.ReadString('Key','Title','');TRegIniFile的其他方法都与此非常类似,可以照此模仿呀!
说实在的,我觉得这样操作已经很方便了,为什么偏要用 API 呢???