Autor Thema: Registry eintrag auslesen  (Gelesen 2331 mal)

Offline Mandalor

  • Senior Mitglied
  • ****
  • Beiträge: 359
  • Geschlecht: Männlich
Registry eintrag auslesen
« am: 12.01.05 - 14:55:17 »
Hallo, sorry, das ich das Forum schon wieder mit einer frage belaste und eigentlich geht es ja immernoch um die NDL, aber mein Problem hat eher was mit der Registry zu tun: Ich suche eine Möglichkeit den (Standard) - wert auszulesen (im Verzeichnis: HKEY_LOKALE_MACHINE\Software\Classes\.ndl\Shell\Open\Command) und gegebenenfalls zu ändern. Ich habe gesucht und auch möglichkeiten gefunden in die Reg zu schreiben und auch zu lesen
z.B.:

Code
@RegQueryValue("HKEY_LOCAL_MACHINE"; "SOFTWARE\\Classes\\.ndl\\Shell\\Open\\Command"; "(Standard)");

oder auch
Code
'// API Constants 
Const REG_SZ = 1 
Const REG_DWORD = 4 
Const SYNCHRONIZE = &H100000
Const STANDARD_RIGHTS_READ = &H20000
Const STANDARD_RIGHTS_WRITE = &H20000
Const STANDARD_RIGHTS_EXECUTE = &H20000
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const STANDARD_RIGHTS_ALL = &H1F0000
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Const HKEY_CLASSES_ROOT = &H80000000 
Const HKEY_CURRENT_USER = &H80000001 
Const HKEY_LOCAL_MACHINE = &H80000002 
Const HKEY_USERS = &H80000003 
Const ERROR_SUCCESS = 0&
Const ERROR_NONE = 0 
Const ERROR_BADDB = 1 
Const ERROR_BADKEY = 2 
Const ERROR_CANTOPEN = 3 
Const ERROR_CANTREAD = 4 
Const ERROR_CANTWRITE = 5 
Const ERROR_OUTOFMEMORY = 6 
Const ERROR_INVALID_PARAMETER = 7 
Const ERROR_ACCESS_DENIED = 8 
Const ERROR_INVALID_PARAMETERS = 87 
Const ERROR_NO_MORE_ITEMS = 259 
Const KEY_ALL_ACCESS = &H3F 
Const REG_OPTION_NON_VOLATILE = 0 
Const REG_PARAMETER_IS_RESERVED = 0 
Const REG_DEFAULT_VALUE = "" 
Const cMAXLEN_BUFFER = 255 
'// API Declarations 
Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long 
Declare 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 Long 
Declare 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 Long 
Declare 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 Long 
Declare 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 Long 
Declare 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 Long 
Declare 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 Long 
Declare Function RegEnumValue Lib "advapi32.dll" _
Alias "RegEnumValueA" _
(Byval hKey As Long, _
Byval dwIndex As Long, _
Byval lpValueName As String, _
lpcbValueName As Long, _
Byval lpReserved As Long, _
lpType As Long, _
lpData As Any, _
lpcbData As Long) As Long
Const cREG_COMPONENTS_PATH = "Software\Lotus\Lotus Components\1.0" 
Const cREG_COMPONENTS_KEYNAME = "LoaderPath" 
Class Registry 
	
'// Declare Member Varaibles 
	Private hkey As Long 
	
'// Declare Member Code 
Declare Public Function GetValue( ItemName$ ) As String 
Declare Public Function SetValue( ValueName As String, lType As Long, vValue As Variant) As Long 
	
'// Constructor 
	Sub New( Section, KeyName$ ) 
		Call RegOpenKeyEx(Section, KeyName$, REG_PARAMETER_IS_RESERVED, KEY_ALL_ACCESS, Me.hKey) 
	End Sub 
	
'// Destructor 
	Sub Delete() 
		Call RegCloseKey (Me.hKey) 
	End Sub 
	
	Public Function GetValue( ItemName$ ) As String 
		Dim sData As String 
		Dim lpcbData As Long 
		Dim lpType As Long 
		
'// First we initialize the buffer 
		sData = String(cMAXLEN_BUFFER, 0) 
		lpcbData = Len(sData) 
		
'// Get it 																			  ' REG_PARAMETER_IS_RESERVED
		Call RegQueryValueExString( Me.hKey, ItemName$, REG_PARAMETER_IS_RESERVED, lpType, sData, lpcbData) 
		Print sData
'// Return 
		GetValue = Left( sData, Instr( 1, sData, Chr$(0) )-1) 
	End Function 
	
	Public Function getItemNames As Variant
		Dim lngValueLen&, lngDataLen&, lngResult&, lngData&, lngCurIdx&
		Dim strResult$, strValue$, retArray() As String, arCounter& 
		lngCurIdx = 0
		arCounter = 0
		Do
			lngValueLen = 2000
			strValue = String(lngValueLen, 0)
			lngDataLen = 2000			
			lngResult = RegEnumValue(Me.hKey, lngCurIdx, Byval strValue, lngValueLen, 0&, REG_DWORD, Byval lngData, lngDataLen)
			lngCurIdx = lngCurIdx + 1
			If lngResult = ERROR_SUCCESS Then
				strResult = Left(strValue, lngValueLen)
				Redim Preserve retArray(arCounter)
				retArray(arCounter) = strResult
				arCounter = arCounter + 1
			End If
		Loop While lngResult = ERROR_SUCCESS
		getItemNames = retArray
	End Function
	
	Public Function SetValue( ValueName As String, lType As Long, vValue As Variant) As Long 
		Dim lValue As Long 
		Dim sValue As String 
		
		Select Case lType 
		Case REG_SZ 
			
'//sValue gets assigned the value vValue 
			sValue = vValue 
			
'// Set value to Windows registry using a string type 
			SetValue = RegSetValueExString( Me.hKey, ValueName, 0&, lType, sValue, Len(sValue)) 
			
		Case REG_DWORD 
			
'// IVlale gets assigned the value in vValue 
			lValue = vValue 
			
'// Set value to Windows registy using a Long variable type 
			SetValue = RegSetValueExLong( Me.hKey, ValueName, 0&, lType, lValue, 4) 
		End Select 
		
	End Function 
	
End Class 


wobei man dies so aufrufen kann:
Code
 setzen einer Systemvariablen, beim setzen einer Zahl wird REG_DWORD benutzt
call reg.setValue("uhu",REG_SZ,"123ABC")
 
' Auslesen eines Registryeintrags
Msgbox "temp=" + reg.getValue("temp")
 
' Liste aller RegKeys auswerten
Dim ar As Variant
ar = reg.getItemNames
Forall x In ar
	Msgbox  x + " =" + reg.getValue(Cstr(x))
End Forall

es funktioniert auch alles, aber wenn ich versuche den wert des Bezeichners (Standard) zu beschreiben, dann legt er einen neuen Bezeichner mit dem selben namen an, den ich auch auslesen kann, aber an den vorgegebenen Standart - wert komme ich nicht ran.

alle anderen Bvezeichner kann ich super lesen und beschreiben

hat jemand ne idee?

« Letzte Änderung: 12.01.05 - 14:56:59 von Mandalor »
mit besten Grüßen

Markus Petzold

Offline TMC

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 3.660
  • Geschlecht: Männlich
  • meden agan
Re: Registry eintrag auslesen
« Antwort #1 am: 12.01.05 - 22:03:20 »
Ich hatte das mal so gemacht in VBA, sollte in LS aber auch so funktionieren:

Set myshell = CreateObject("Wscript.Shell")
myshell.regwrite .........

Teste das mal. Dokumentation findest Du sicherlich, wenn Du "Wscript.Shell" in Google eingibst...
Matthias

A good programmer is someone who looks both ways before crossing a one-way street.


Offline Mandalor

  • Senior Mitglied
  • ****
  • Beiträge: 359
  • Geschlecht: Männlich
Re: Registry eintrag auslesen
« Antwort #2 am: 13.01.05 - 09:51:39 »
Danke, werde es versuchen
mit besten Grüßen

Markus Petzold

Offline Mandalor

  • Senior Mitglied
  • ****
  • Beiträge: 359
  • Geschlecht: Männlich
Re: Registry eintrag auslesen
« Antwort #3 am: 13.01.05 - 10:24:44 »
Es war soooo einfach: Wenn man den (Standart) wert lesen und schreiben will, muss man einfach als Bezeichner einen leerString übergeben.
mit besten Grüßen

Markus Petzold

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz