runner-ralf
Goto Top

Registrierung durchsuchen mit VB.NET

Hallo alle zusammen,

habe ein VBScript das ich in VB.Net(VBExpress2010) nutzen will.

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Const BASE = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

machine = "." ' use "." for local computer

swList = InstalledApplications(machine)
CreateObject("Wscript.Shell").Popup swList,10,"Installierte Software"

Function InstalledApplications(nod)
Dim tmp, Val
Set oReg = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" _
& nod & "/root/default:StdRegProv")
If oReg.EnumKey(HKLM, BASE, Keys)<> 0 Then
InstalledApplications = "Fehler beim Zugriff auf Uninstall-Key!"
Exit Function
End If
For Each Key in Keys
rc = oReg.GetStringValue( _
HKLM, BASE & Key, "DisplayName", val)
If rc <> 0 Then oReg.GetStringValue _
HKLM, BASE & Key, "QuietDisplayName", val
If Val <> "" Then tmp = tmp & val & vbCrLf
Next
InstalledApplications = tmp
End Function


Anpassungsversuch in VB.NET(VB2010 Express)

Function installierte_Software(ByVal StrServer)
installierte_Software = 0
Dim Maschine
Maschine = "."
Dim RC
Const BASE = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Dim tmp, Val
tmp = 0
Val = 0
Dim oReg
oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrServer & "/root/default:StdRegProv")
If oReg.EnumKey(HKLM, BASE, werte) <> 0 Then
MsgBox("Fehler beim Zugriff auf Uninstall-Key!")
Exit Function
End If
For Each Key In werte
TEXT = oReg.GetStringValue(HKLM, BASE & Key, "QuietDisplayName", Val)
RC = oReg.GetStringValue(HKLM, werte, "DisplayName", Val)
If RC <> 0 Then oReg.GetStringValue(HKLM, BASE & Key, "QuietDisplayName", Val) '<<<<<<<<<Hier bleibt das Programm hängen mit dem Hinweis "Falscher Typ"
If Val <> "" Then tmp = tmp & Val & vbCrLf
Next
MsgBox(tmp)
End Function

Bin einfach noch nicht so fit in VB.Net. Weiß nicht welchen Typ er will. Einen Array?

Gruß

Ralf

Content-Key: 160387

Url: https://administrator.de/contentid/160387

Printed on: April 25, 2024 at 09:04 o'clock

Member: bastla
bastla Feb 08, 2011 at 16:16:10 (UTC)
Goto Top
Hallo runner-ralf!

Da VB.NET eigene Objekte / Methoden für den Registry-Zugriff hat, eher so:
Const BASE = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"  
Dim DispName As String, Val As String
Dim tmp As String = ""  

Dim Key As Microsoft.Win32.RegistryKey
Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(BASE)
Dim SubKeyNames() As String
SubKeyNames = Key.GetSubKeyNames()
For Each SubKeyName In SubKeyNames
    Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(BASE & "\" & SubKeyName)  
    DispName = Key.GetValue("DisplayName")  
    'If DispName <> "" Then Val = Key.GetValue("QuietDisplayName")  
    If DispName <> "" Then tmp = tmp & DispName & vbTab  
Next
MsgBox(tmp)
Grüße
bastla

P.S.: Bei mir sieht's mit "vbTab" lustiger aus als mit "vbCrLf" ... face-wink
Member: runner-ralf
runner-ralf Feb 08, 2011 at 17:53:50 (UTC)
Goto Top
Servus Bastla,

das schaut gut aus. Wie sieht es aus wenn ich die Reg von einem Remote Rechner auslesen will?

Danke dir schon mal für dein Code oben

Gruß

Ralf
Member: bastla
bastla Feb 08, 2011 at 21:26:21 (UTC)
Goto Top
Hallo runner-ralf!

Als Stichwort: "Microsoft.Win32.RegistryKey.OpenRemoteBaseKey"

Grüße
bastla
Member: runner-ralf
runner-ralf Feb 09, 2011 at 07:29:27 (UTC)
Goto Top
Servus Bastla,

haut hi.

merce

Ralf