create empty registry key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

create empty registry key

29 Dec 2016, 06:25

Is this the best way currently to create an empty registry key?
If a lot of keys were created this way, would there be any disadvantages in the fact that a value is created and deleted each time?
Also it currently uses a REG_SZ, would it be better to say use a REG_BINARY or a REG_DWORD?

[EDIT: it seems that the standard way that AutoHotkey creates registry subkeys, via 'RegWrite, REG_SZ, %vRootKey%, %vSubKey%', also creates a default value with a blank string, rather than an empty default value or no default value.]

[based on]
Creating a Windows registry key with no default value (NOT blank) using AutoHotkey - Stack Overflow
http://stackoverflow.com/questions/2695 ... g-autohotk

Code: Select all

JEE_RegCreateKey(vRootKey, vSubKey)
{
RegWrite, REG_SZ, %vRootKey%, %vSubKey%
RegDelete, %vRootKey%, %vSubKey%, AHK_DEFAULT
Return
}
Last edited by jeeswg on 31 Dec 2016, 06:12, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9528
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: create empty registry key

29 Dec 2016, 06:38

What's so bad with an empty default value?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: create empty registry key

29 Dec 2016, 07:22

Yes to some extent it doesn't seem that big a deal,
then again, if someone else's software did that to my computer,
I wouldn't be happy, and I always want to do things properly and rarely if ever cut corners.
Anyway I'm working on sharing my collection of literally
over a thousand functions, and if I spend half my background mental power
on justifying questions on forums I am going to go crazy.
Fair question though, although I don't much care for 'why is it necessary' questions,
'why is it necessary to go to the moon', 'why is it necessary to live a fulfilled life'.
Anyhow I was more concerned with the 3 questions I posed,
than on how/why to actually create an empty key.
Anyhow don't take it that I'm cross with you, besides
I am very grateful to you for your ClipboardGetDropEffect function (identify whether files were cut/copied to the clipboard) and other contributions
of yours, it was a key spanner in the works when creating my custom shell.
Yes I'm a very verbal person, any thing someone says is going to trigger
an avalanche of ideas and words when I'm trying to stay focused.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9528
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: create empty registry key

29 Dec 2016, 08:07

jeeswg wrote:then again, if someone else's software did that to my computer,
I wouldn't be happy, and I always want to do things properly and rarely if ever cut corners.
Did you take a look at the HKCU branch of your registry? How many keys without a default value do you find?

But back to your questions:
IMO
  1. The 'best way' seems to be RegCreateKeyEx() as suggested by blackholyman
  2. At least it will need more time than necessary.
  3. I don't think so.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: create empty registry key

29 Dec 2016, 08:17

Thanks for the response.
In RegEdit, I *think* it shows:
(Default) REG_SZ (value not set)
whether there is or isn't a value there.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9528
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: create empty registry key

29 Dec 2016, 08:36

I just tested RegWrite and noticed the difference. Sorry!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: create empty registry key

29 Dec 2016, 08:44

Haha no worries, thanks so much though. Btw did you see my initial save as prompt GUI functions. I think the next thing I'll post is rough MsgBox/InputBox scripts with the core GUI creation functions.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9528
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: create empty registry key

29 Dec 2016, 09:18

OK, so this is my favourite:

Code: Select all

RegCreateKey(Root, Key) { ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms724844(v=vs.85).aspx
   Static ROOTKEY := {HKCR: 0x80000000, HKEY_CLASSES_ROOT:   0x80000000
                    , HKCU: 0x80000001, HKEY_CURRENT_USER:   0x80000001
                    , HKLM: 0x80000002, HKEY_LOCAL_MACHINE:  0x80000002
                    , HKU:  0x80000003, HKEY_USERS:          0x80000003
                    , HKCC: 0x80000005, HKEY_CURRENT_CONFIG: 0x80000005}
   If (Root := ROOTKEY[Root])
      If !DllCall("Advapi32.dll\RegCreateKeyEx", "Ptr", Root, "Str", Key, "UInt", 0, "Ptr", 0 , "UInt", 0, "UInt", 0x0F003F, "Ptr", 0, "PtrP", hKey, "Ptr", 0, "Int")
         Return !DllCall("Advapi32.dll\RegCloseKey", "Ptr", hKey, "Int")
   Return False
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: create empty registry key

29 Dec 2016, 09:43

Wow, that looks great, I haven't seen that before, that's a really nice use of objects for looking at a list, I hate to do it, but I think I might be reviewing some of the techniques I use when I write code. I usually loop through a text list. It saves on some lines needed for text splitting.
Many thanks.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 119 guests