To delete a key:
Call RegistryDelete("HKEY_LOCAL_MACHINE\Software\My Key", "")
To delete a value:
Call RegistryDelete("HKEY_LOCAL_MACHINE\Software\My Key", "My Value")
To delete the (Default) value in a key, we just set the value to nothing:
Call RegistryWrite("HKEY_LOCAL_MACHINE\Software\My Key", "", "", "")
You??™ll notice that, in the RegistryDelete subroutine, there??™s a RegWrite statement.
This is necessary to ensure that the key or value that you??™re trying to
delete actually exists. If you don??™t include this statement and you try to delete
a nonexistent key or value from the Registry, the Windows Script Host will
give an error to the effect that ???The system cannot find the file specified.???
(A helpful Microsoft error message, as always.) This way, the subroutine
will create the key or value entry to be deleted if it doesn??™t already exist.
526 | Chapter 9: Scripting and Automation
As part of a security/safety feature present in Windows
Vista (and XP, 2000, and 2003), you won??™t be able to delete
a key that contains subkeys (this is not true of Windows 9x/
Me) using the RegistryDelete routine. See ???Export and
Import Data with Registry Patches,??? in Chapter 3, for a
workaround.
See Chapter 3 for more information on Registry keys and values, tools, and
tricks.
How to Manipulate Files
One of the myths surrounding the Windows Script Host, and VBScript in
particular, is that there??™s no provision for accessing the filesystem (copying,
deleting, and writing to files).
Pages:
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732