本帖最后由 pusofalse 于 2010-3-22 15:47 编辑
搜索了一下,关于更改注册表项名称的问题,以往并没有提出来。恰巧,这问题我以往也没有遇到过,刚刚google一下,找到一个API函数,调用如下。有什么理由不让我回答这个标题及描述都如此清晰并且便于搜索、以及没有错别字的帖子~?#include <LocalSecurityAuthority.au3>
$fResult = _RegRenameKey("HKLM\Software\TEST", "NewKeyName")
Msgbox(0, $fResult, @error)
Func _RegRenameKey($sRegKey, $sNewName)
Local $hRegKey, $pBuffer, $sSubKey, $hMainKey, $aRegKey, $iResult
While StringRight($sRegKey, 1) = ""
$sRegKey = StringTrimRight($sRegKey, 1)
WEnd
$aRegKey = StringSplit($sRegKey, "")
Switch $aRegKey[1]
Case "HKCR", "HKEY_CLASSES_ROOT"
$hMainKey = 0x80000000
Case "HKCU", "HKEY_CURRENT_USER"
$hMainKey = 0x80000001
Case "HKLM", "HKEY_LOCAL_MACHINE"
$hMainKey = 0x80000002
Case "HKU", "HKEY_USERS"
$hMainKey = 0x80000003
Case "HKCC", "HKEY_CURRENT_CONFIG"
$hMainKey = 0x80000005
Case Else
Return SetError($ERROR_INVALID_PARAMETER, 0, 0)
EndSwitch
$sSubKey = StringTrimLeft($sRegKey, StringLen($aRegKey[1]) + 1)
$hRegKey = _RegOpenKeyEx($hMainKey, $sSubKey, $GENERIC_WRITE)
If ($hRegKey < 1) Then Return SetError(@error, 0, 0)
$pBuffer = _LsaInitializeBufferW($sNewName)
$iResult = DllCall("Ntdll.dll", "dword", "NtRenameKey", "hWnd", $hRegKey, "ptr", $pBuffer)
_FreeVariable($pBuffer, 0, _HeapFree($pBuffer), _LsaNtStatusToWinError($iResult[0]))
Return SetError(@error, _RegCloseKey($hRegKey), $iResult[0] = 0)
EndFunc ;==>_RegRenameKey
|