BoForce
(Fresh Scripter)
2009-09-23 03:50 PM
SteelKix: WriteValue()

 Code:
;SteelKix Function: WriteValue()
;
;Author:		Boforce
;
;contributors:	None
;
;Action:		Creates a new key, adds another value-name to an existing key (and assigns it a value)
;		or changes the value of an existing value-name
;
;Syntax:		WriteValue("Key","Value","Data","Type")
;
;Version:		1.0
;
;Date:		2009-09-23
;
;Date Revised:	2009-09-23
;
;Parameters	Key
;		Required.	Identifies the key containing the value
;
;		Value
;		Optional.	Identifies the value whose data you want to discover
;			When omitted the (Default) value is used
;
;		Data
;		Required.	The data to store as the value of the entry
;
;		Type
;		Required.	Identifies the data type of the entry. The following data types are supported:
;			REG_SZ
;			REG_EXPAND_SZ
;			REG_BINARY
;			REG_DWORD
;			REG_MULTI_SZ
;
;Remarks:		None
;
;Returns:		Returns 'Command completed successfully' when successfull else an exception message
;
;Dependencies:
; SteelKix version: 0.2
; Tested with Dot Net 3.5.30729.01
; 
;Example(s):	Add string value:
;		$rc = WriteValue('HKEY_CURRENT_USER\Test','My Value','Data added','REG_SZ')
;		? 'Result  : ' + $rc
;
;Comments : This has been successfully tested on Windows XP SP3 with DOT NET 3.5.30729.01. 
;Source:
Function WriteValue($wvKey,$wvValue,$wvData,$wvType)
Dim $Win32,$DatType,$Action

Imports $Win32 = Microsoft.Win32

Select
   Case $wvType = 'REG_SZ'
	$DatType = $Win32.RegistryValueKind.String
   Case $wvType = 'REG_EXPAND_SZ'
	$DatType = $Win32.RegistryValueKind.ExpandString
   Case $wvType = 'REG_BINARY'
	$DatType = $Win32.RegistryValueKind.Binary
   Case $wvType = 'REG_DWORD'
	$DatType = $Win32.RegistryValueKind.DWord
   Case $wvType = 'REG_MULTI_SZ'
	$DatType = $Win32.RegistryValueKind.MultiString
   Case $wvType = 'REG_QWORD'
	$DatType = $Win32.RegistryValueKind.QWord
   Case $wvType = 'REG_UNKNOWN'
	$DatType = $Win32.RegistryValueKind.Unknown
EndSelect

Try
   $Action = $Win32.Registry.SetValue($wvKey,$wvValue,$wvData,$DatType)
EndTry
Catch
   $exc
EndCatch

If $exc
   $WriteValue = $exc.Message
Else
   $WriteValue = 'Command completed successfully'
EndIf
EndFunction


LonkeroAdministrator
(KiX Master Guru)
2009-09-26 01:57 PM
Re: SteelKix: WriteValue()

this udf is missing information in it's dependencies header section.
and as it's tested on development version, also summary/notes/comments section should provide with which version it was tested and proven working with.


BoForce
(Fresh Scripter)
2009-09-28 09:52 PM
Re: SteelKix: WriteValue()

Updated the UDF.
Changed the dependency of DOT NET to the DOT NET version the UDF was tested with and added comments regarding the Os used during the test. I diddn't find any guidelines on the summary/notes/comments sections within the GuideLines(), so I jsut added what seems most applicable.


BoForce
(Fresh Scripter)
2009-09-29 08:33 AM
Re: SteelKix: WriteValue()

Changed the dependencies section as suggested.