Встроенная перезапись Autohotkeys, как вы сказали, не поддерживает пустой ключ.
Я провел небольшое тестирование, и вот что вы можете попробовать
Если вы оставите ValueName пустым, будет использоваться значение подраздела по умолчанию, если sValue опущено, используется пустое / нулевое значение.
#SingleInstance force
RegWrite("REG_SZ","HKCU","Environment\testkey","","")
return
RegWrite(Type, RKey, SKey, ValueName="",sValue="")
{
HKCR := HKEY_CLASSES_ROOT := 0x80000000 ; http://msdn.microsoft.com/en-us/library/aa393286.aspx
HKCU := HKEY_CURRENT_USER := 0x80000001
HKLM := HKEY_LOCAL_MACHINE := 0x80000002
HKU := HKEY_USERS := 0x80000003
HKCC := HKEY_CURRENT_CONFIG := 0x80000005
HKDD := HKEY_DYN_DATA := 0x80000006
REG_NONE := 0 ; http://msdn.microsoft.com/en-us/library/ms724884.aspx
REG_SZ := 1
REG_EXPAND_SZ := 2
REG_BINARY := 3
REG_DW := REG_DWORD := 4
REG_DWORD_BIG_ENDIAN := 5
REG_LINK := 6
REG_MULTI_SZ := 7
REG_RESOURCE_LIST := 8
if !(RKey := %RKey%) ; Dynamicaly assign the RootKey
Return false ; A invalid rootkey was givven
if !(Type := %Type%) ; Dynamicaly assign the DataType
Return false ; A invalid Type was givven
if DllCall("Advapi32.dll\RegCreateKeyEx","uint", RKey, "Str", SKey, "uint", 0 , "uint", 0 , "uint", 0, "uint",0xF003F, "uint", 0 , "uint *", hKey) { ; create the key
Return false ; Error creating or opening the key
}
If (Type == REG_SZ or Type == REG_EXPAND_SZ)
DllCall("Advapi32.dll\RegSetValueEx", "uint", hKey, "str", ValueName, "uint", 0, "uint", Type, "str", sValue, "uint", DataSize := (StrLen(sValue) + 1)*2) ; write string
else If (Type == REG_BINARY) {
size:=StrLen(sValue)//2 ; set the data to half, one byte=2 hex digits
VarSetCapacity(Rbin, size,0) ; set the capacity
loop,% size {
StringLeft, bin, sValue,2 ; get the left 2digits at the time
NumPut("0x" Bin,Rbin,A_Index-1,"Char") ; Store the data
StringTrimLeft, sValue, sValue, 2 ; remove the to digits
}
DllCall("Advapi32.dll\RegSetValueEx","uint",hKey,"str",ValueName,"uint",0,"uint",Type,Uint,&Rbin,"uint",size) ; write string
} Else If (Type == REG_DWORD) {
VarSetCapacity(RDW, 4,0) ; setthe capacity to 4 bytes
NumPut(sValue,RDW,0) ; Store the data in itData
DllCall("Advapi32.dll\RegSetValueEx","uint",hKey,"str",ValueName,"uint",0,"uint",Type,"uint",&RDW,"uint",4) ; write dword ; a DWORD is a 32-bit (4 byte) number
; RDW := "" ; clear the variable
}
DllCall("Advapi32.dll\RegCloseKey", "uint", hKey) ; Release the handle of the key
return, true
}
Я использую 64-битную версию win 7, используя 32-битный Unicode ahk 1.1.16.05 из http://ahkscript.org
Это сработало в моих тестах, по крайней мере, для того, что, я думаю, вы пытаетесь сделать.
person
blackholyman
schedule
18.11.2014