;SteelKix Function: DelKey()
;
;Author: Boforce
;
;Contributors: None
;
;Action: Deletes the specified subkey from the registry
;
;Syntax: DelKey("key")
;
;Version: 1.0
;
;Date: 2009-09-25
;
;Date Revised: 2009-09-25
;
;Parameters Key
; Required. A string that specifies the name of the subkey you want to delete
;
;Remarks: None
;
;Returns: Returns nothing if the key is deleted else an error message
;
;Dependencies:
; SteelKix version: 0.2
; Tested with Dot Net 3.5.30729.01
;
;Example(s): Delete some key:
; $DeleteKey = DelKey('HKEY_CURRENT_USER\Test\Some\New\Key')
; ? 'Deleted key : ' + $DeleteKey
;
;Comments : This has been successfully tested on Windows XP SP3 with DOT NET 3.5.30729.01.
;
;Source:
Function DelKey($Key)
Dim $Win32,$Hive,$Action
Imports $Win32 = Microsoft.Win32
$Hive = $Key.ToString.Split("\".ToCharArray())[0]
$Key = $Key.Remove($Hive+'\',$Hive.Length+1)
Select
Case $Hive = 'HKEY_CLASSES_ROOT' Or $Hive = 'HKCR'
$Hive = $Win32.Registry.ClassesRoot
Case $Hive = 'HKEY_CURRENT_USER' Or $Hive = 'HKCU'
$Hive = $Win32.Registry.CurrentUser
Case $Hive = 'HKEY_LOCAL_MACHINE' Or $Hive = 'HKLM'
$Hive = $Win32.Registry.LocalMachine
Case $Hive = 'HKEY_USERS' Or $Hive = 'HKU'
$Hive = $Win32.Registry.Users
Case 1
$atHive = 'Error'
EndSelect
If $atHive = 'Error'
$AddKey = 'Unknown hive'
Else
Try
$Action = $Hive.DeleteSubKey($Key,1)
EndTry
Catch
$e
EndCatch
If $e
$DelKey = $e.Message
Else
$DelKey = $Action
EndIf
EndIf
EndFunction