Dim sRegVal As String Set oShell = CreateObject("WScript.Shell") call oShell.RegWrite( "HKEY_CURRENT_USER\ScriptEngine\Test", "1" ,"REG_SZ" )
Dim sRegVal As String Set oShell = CreateObject("WScript.Shell") call oShell.RegWrite( "HKEY_CURRENT_USER\ScriptEngine\C:\\Programme\\Lotus\\Notes\\nlnotes.exe", "1" ,"REG_SZ" )
| HKEY_CURRENT_USER\ +--+ ScriptEngine\ +--+ C:\ +--+ Programme\ +--+ Lotus +--+ Notes Hier liegt die Zeichenfolge nlnotes.exe mit dem Wert "1"
| HKEY_CURRENT_USER\ +--+ ScriptEngine\ Hier liegt die Zeichenfolge "C:\Programme\Lotus\Notes\nlnotes.exe" mit dem Wert "1"
Ein ist das Schreiben (Backslash) aufgrund der Einschränkungen der RegWrite Methode von Windows Script Host in einem Schlüsselname oder einem Wertname nicht möglich.
'ClassRegistry: Option PublicOption Explicit'// API ConstantsConst REG_SZ = 1 Const REG_DWORD = 4 Const HKEY_CLASSES_ROOT = &H80000000Const HKEY_CURRENT_USER = &H80000001Const HKEY_LOCAL_MACHINE = &H80000002Const HKEY_USERS = &H80000003Const ERROR_NONE = 0Const ERROR_BADDB = 1Const ERROR_BADKEY = 2Const ERROR_CANTOPEN = 3Const ERROR_CANTREAD = 4Const ERROR_CANTWRITE = 5Const ERROR_OUTOFMEMORY = 6Const ERROR_INVALID_PARAMETER = 7Const ERROR_ACCESS_DENIED = 8Const ERROR_INVALID_PARAMETERS = 87Const ERROR_NO_MORE_ITEMS = 259Const KEY_ALL_ACCESS = &H3FConst REG_OPTION_NON_VOLATILE = 0Const REG_PARAMETER_IS_RESERVED = 0Const REG_DEFAULT_VALUE = ""Const cMAXLEN_BUFFER = 255'// API DeclarationsDeclare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As LongDeclare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (Byval hKey As Long, Byval lpSubKey As String, Byval ulOptions As Long, Byval samDesired As Long, phkResult As Long) As LongDeclare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval lpReserved As Long, lpType As Long, Byval lpData As String, lpcbData As Long) As LongDeclare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As LongDeclare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval lpReserved As Long, lpType As Long, Byval lpData As Long, lpcbData As Long) As LongDeclare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval dwType As Long, Byval lpValue As String, Byval cbData As Long) As LongDeclare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval dwType As Long, lpValue As Long, Byval cbData As Long) As LongConst cREG_COMPONENTS_PATH = "Software\Lotus\Lotus Components\1.0"Const cREG_COMPONENTS_KEYNAME = "LoaderPath"Class Registry'// Declare Member VaraiblesPrivate hkey As Long'// Declare Member CodeDeclare Public Function GetValue( ItemName$ ) As StringDeclare Public Function SetValue( ValueName As String, lType As Long, vValue As Variant) As Long'// ConstructorSub New( Section, KeyName$ )Call RegOpenKeyEx(Section, KeyName$, REG_PARAMETER_IS_RESERVED, KEY_ALL_ACCESS, Me.hKey) End Sub'// DestructorSub Delete()Call RegCloseKey (Me.hKey)End SubPublic Function GetValue( ItemName$ ) As StringDim sData As StringDim lpcbData As LongDim lpType As Long'// First we initialize the buffersData = String(cMAXLEN_BUFFER, 0)lpcbData = Len(sData)'// Get itCall RegQueryValueExString( Me.hKey, ItemName$, REG_PARAMETER_IS_RESERVED, lpType, sData, lpcbData)'// ReturnGetValue = Left( sData, Instr( 1, sData, Chr$(0) )-1)End FunctionPublic Function SetValue( ValueName As String, lType As Long, vValue As Variant) As LongDim lValue As LongDim sValue As StringSelect Case lType Case REG_SZ '//sValue gets assigned the value vValuesValue = vValue '// Set value to Windows registry using a string typeSetValue = RegSetValueExString( Me.hKey, ValueName, 0&, lType, sValue, Len(sValue))Case REG_DWORD '// IVlale gets assigned the value in vValuelValue = vValue '// Set value to Windows registy using a Long variable typeSetValue = RegSetValueExLong( Me.hKey, ValueName, 0&, lType, lValue, 4)End Select End FunctionEnd ClassSub InitializeEnd SubSub TerminateEnd Sub