Previous Topic: RegCloseKey - Close the Registry KeyNext Topic: RegDeleteKey - Delete a Registry Key


RegCreateKey - Create a Registry key

Valid on Windows

The RegCreateKey function creates a specific registry key. If the key already exists in the registry, it is opened.

This registry manipulation function has the format:

RegCreateKey(hKey as Integer, subkey as String) as Integer
hKey

Identifies a currently open key or a predefined key. The hKey parameter can be any of the following predefined values available on all Windows platforms:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
subkey

Specifies a string that indicates the name of the key to open. Subkey must be a subkey of the key identified by hKey. If the subkey parameter is an empty string, the function returns the same key as that specified in the hKey parameter.

On successful completion, the function returns a handle to the newly created registry key; otherwise, it returns 0.

Example: RegCreateKey function

Dim hkey1, hkey2, hkey3 as integer
Dim cBuf as string
Dim ccBuf[47] as char
Dim bBuf[100] as byte
Dim i as integer

ClrScr()
for i = 0 to 99
	bBuf[i] = i
next i
cBuf = "1234567890ßqwertzuiopü+asdfghjklöä#<yxcvbnm,.-"
ccBuf = cBuf

hkey1 = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE")

if hkey1 = 0 then
	Print("RegOpenKey failed.")
	exit
endif

hkey2 = RegCreateKey(hkey1, "CA Technology")
if hkey2 = 0 then
	Print("RegCreateKey 1 failed.")
	exit
endif

if Not(RegSetValue(hkey1, "CA", "International")) then
	Print("RegSetValue failed")
endif

hkey3 = RegCreateKey(hkey2, "4 test only")
if hkey3 = 0 then
	Print("RegCreateKey 2 failed.")
	exit
endif

if Not(RegSetVariable(hkey3, "var_1", 123)) then
	Print("RegSetVar 1 failed.")
endif
if Not(RegSetVariable(hkey3, "var_2", "i'm a string")) then
	Print("RegSetVar 2 failed.")
endif
if Not(RegSetVariable(hkey3, "var_3", cBuf, 46)) then
	Print("RegSetVar 3 failed.")
endif
if Not(RegSetVariable(hkey3, "var_4", bBuf, 100)) then
	Print("RegSetVar 4 failed.")
endif
if Not(RegSetVariable(hkey3, "var_5", cBuf, 46, REG_SZ)) then
	Print("RegSetVar 5 failed.")
endif
if Not(RegSetVariable(hkey3, "var_6", ccBuf, 46, REG_SZ)) then
	Print("RegSetVar 5 failed.")
endif

if Not(RegCloseKey(hkey3)) then
	Print("RegCloseKey for hkey3 failed.")
endif
if Not(RegCloseKey(hkey2)) then
	Print("RegCloseKey for hkey2 failed.")
endif
if Not(RegCloseKey(hkey1)) then
	Print("RegCloseKey for hkey1 failed.")

endif