Previous Topic: RegDeleteValue - Delete a Value in the RegistryNext Topic: RegEnumKey - Enumerate the Subkeys of a Registry Key


RegDeleteVariable - Remove a Variable

Valid on Windows

The RegDeleteVariable function removes the specified variable.

This registry manipulation function has the format:

RegDeleteVariable(hKey as integer, name as string) as Boolean
hKey

Indicates a currently opened key or a predefined key. The hKey parameter can have one of the following predefined values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
name

Identifies the name of the variable that is to be removed.

On successful completion, the function returns TRUE; otherwise, it returns FALSE.

Example: RegDeleteVariable function

Test structure:

HKLM\

\ Software

\ CA

\ 4 test only

\ var_6

\ dummy

Dim hkey1 as integer

ClrScr()


hkey1 = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\CA\4 test only")
if hkey1 = 0 then
	Print("RegOpenKey failed.")
	exit
endif

if RegDeleteValue(hKey1) then
	Print("RegDeleteValue succeeded.")
else
	Print("RegDeleteValue failed.")
endif

if RegDeleteVariable(hKey1, "var_6") then
	Print("RegDeleteVariable for var_6 succeeded.")
else
	Print("RegDeleteVariable for var_6 failed.")
endif

RegCloseKey(hkey1)

hkey1 = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\CA")

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

if RegDeleteKey(hkey1, "dummy") then
	Print("Key dummy successfully deleted")
else
	Print("Key dummy deletion failed.")
endif

RegCloseKey(hkey1)

Messagebox("Check registry!", "desktop management scripting test")

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

if RegDeleteKey(hkey1, "CA\4 test only") then
	Print("Key ""CA\4 test only"" successfully deleted")

else
	Print("Key" "CA\4 test only" "deletion failed.")
endif

if RegDeleteKey(hkey1, "CA") then
	Print("Key CA successfully deleted")
else
	Print("Key CA deletion failed.")
endif

RegCloseKey(hkey1)