I am having an issue using WMI StdRegProv in a class that I'm creating to
make it easer to access remote registries. It works great the first time I
create and access it, but if I create a second instance of the class I get
the following error.
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in microsoft.visualbasic.dll
Additional information: Unspecified error
Here's what I have for my class file.
Public Enum HKey
CLASSES_ROOT = &H80000000
CURRENT_USER = &H80000001
LOCAL_MACHINE = &H80000002
USERS = &H80000003
CURRENT_CONFIG = &H80000005
DYN_DATA = &H80000006
End Enum
Public Class RemoteRegistry
Dim _Server As String
Dim _User As String
Dim _Password As String
Dim oWMIServer As New WbemScripting.SWbemLocator
Dim oReg As WbemScripting.SWbemObject
Dim oServer As WbemScripting.SWbemServices
Dim _Connected As Boolean = False
Property Server() As String
Get
Server = _Server
End Get
Set(ByVal Value As String)
_Server = Value
_Connected = False
End Set
End Property
Property UserName() As String
Get
UserName = _User
End Get
Set(ByVal Value As String)
If _User <> Nothing Then
If _User.ToLower <> Value.ToLower Then
_User = Value
_Password = Nothing
End If
Else
_User = Value
_Password = Nothing
End If
End Set
End Property
WriteOnly Property Password() As String
Set(ByVal Value As String)
_Password = Value
End Set
End Property
Public Function LookupValue(ByVal HKey As HKey, ByVal Path As String,
ByVal Value As String) As String
Dim sResult As String
Dim sResult2 As String
If Not _Connected Then Connect()
oReg.GetStringValue(HKey, Path, Value, sResult)
LookupValue = sResult
End Function
Private Sub Connect()
'On Error Resume Next
If _User = Nothing Or _User = "" Then
oServer = oWMIServer.ConnectServer(_Server, "root\default")
Else
oServer = oWMIServer.ConnectServer(_Server, "root\default",
_User, _Password)
If Err.Number <> 0 Then
Err.Clear()
oServer = oWMIServer.ConnectServer(_Server, "root\default")
End If
End If
oReg = oServer.Get("StdRegProv")
_Connected = True
End Sub
End Class
And here's what I'm using to test it with.
Private Sub ExecuteScript_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExecuteScript.Click
Dim y As New RemoteRegistry
Dim Key As String = "SYSTEM\CurrentControlSet\Services\SNMP"
y.Server = "srvr-istest6"
y.UserName = UserName.Text
y.Password = Password.Text
label1.Text = y.LookupValue(HKey.LOCAL_MACHINE, Key, "DisplayName")
y = Nothing
End Sub
I'm wondering if anyone has any ideas as to why I can't run the
ExecuteScript twice without getting an error on the oReg.GetStringValue, I'm
all ears(well I don't look like dumbo, but do feel like one sometimes)...
Thanks,
kmurphy
roughlyat nexusinfosys and that's in the com domain. 2 4466
Hi,
I would use the registrykey.openremotebasekey instead http://msdn.microsoft.com/library/de...sekeytopic.asp
Ken
-----------------------
"Brx" <To.News.Group@plz> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl... I am having an issue using WMI StdRegProv in a class that I'm creating to make it easer to access remote registries. It works great the first time I create and access it, but if I create a second instance of the class I get the following error.
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll
Additional information: Unspecified error
Here's what I have for my class file.
Public Enum HKey CLASSES_ROOT = &H80000000 CURRENT_USER = &H80000001 LOCAL_MACHINE = &H80000002 USERS = &H80000003 CURRENT_CONFIG = &H80000005 DYN_DATA = &H80000006 End Enum Public Class RemoteRegistry Dim _Server As String Dim _User As String Dim _Password As String Dim oWMIServer As New WbemScripting.SWbemLocator Dim oReg As WbemScripting.SWbemObject Dim oServer As WbemScripting.SWbemServices Dim _Connected As Boolean = False Property Server() As String Get Server = _Server End Get Set(ByVal Value As String) _Server = Value _Connected = False End Set End Property Property UserName() As String Get UserName = _User End Get Set(ByVal Value As String) If _User <> Nothing Then If _User.ToLower <> Value.ToLower Then _User = Value _Password = Nothing End If Else _User = Value _Password = Nothing End If End Set End Property WriteOnly Property Password() As String Set(ByVal Value As String) _Password = Value End Set End Property Public Function LookupValue(ByVal HKey As HKey, ByVal Path As String, ByVal Value As String) As String Dim sResult As String Dim sResult2 As String
If Not _Connected Then Connect() oReg.GetStringValue(HKey, Path, Value, sResult) LookupValue = sResult End Function Private Sub Connect() 'On Error Resume Next If _User = Nothing Or _User = "" Then oServer = oWMIServer.ConnectServer(_Server, "root\default") Else oServer = oWMIServer.ConnectServer(_Server, "root\default", _User, _Password) If Err.Number <> 0 Then Err.Clear() oServer = oWMIServer.ConnectServer(_Server, "root\default") End If End If oReg = oServer.Get("StdRegProv") _Connected = True End Sub End Class
And here's what I'm using to test it with.
Private Sub ExecuteScript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExecuteScript.Click Dim y As New RemoteRegistry Dim Key As String = "SYSTEM\CurrentControlSet\Services\SNMP"
y.Server = "srvr-istest6" y.UserName = UserName.Text y.Password = Password.Text
label1.Text = y.LookupValue(HKey.LOCAL_MACHINE, Key, "DisplayName") y = Nothing End Sub
I'm wondering if anyone has any ideas as to why I can't run the ExecuteScript twice without getting an error on the oReg.GetStringValue, I'm all ears(well I don't look like dumbo, but do feel like one sometimes)...
Thanks, kmurphy roughlyat nexusinfosys and that's in the com domain.
I had thought about that, but it doesn't look like it supports supplying
authentication credentials, some of the machines we need to manipulate are
not in the same domain so we need to provide a username and password.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uA**************@TK2MSFTNGP14.phx.gbl... Hi,
I would use the registrykey.openremotebasekey instead
http://msdn.microsoft.com/library/de...sekeytopic.asp
Ken ----------------------- "Brx" <To.News.Group@plz> wrote in message news:%2******************@TK2MSFTNGP14.phx.gbl...I am having an issue using WMI StdRegProv in a class that I'm creating to make it easer to access remote registries. It works great the first time I create and access it, but if I create a second instance of the class I get the following error.
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll
Additional information: Unspecified error
Here's what I have for my class file.
Public Enum HKey CLASSES_ROOT = &H80000000 CURRENT_USER = &H80000001 LOCAL_MACHINE = &H80000002 USERS = &H80000003 CURRENT_CONFIG = &H80000005 DYN_DATA = &H80000006 End Enum Public Class RemoteRegistry Dim _Server As String Dim _User As String Dim _Password As String Dim oWMIServer As New WbemScripting.SWbemLocator Dim oReg As WbemScripting.SWbemObject Dim oServer As WbemScripting.SWbemServices Dim _Connected As Boolean = False Property Server() As String Get Server = _Server End Get Set(ByVal Value As String) _Server = Value _Connected = False End Set End Property Property UserName() As String Get UserName = _User End Get Set(ByVal Value As String) If _User <> Nothing Then If _User.ToLower <> Value.ToLower Then _User = Value _Password = Nothing End If Else _User = Value _Password = Nothing End If End Set End Property WriteOnly Property Password() As String Set(ByVal Value As String) _Password = Value End Set End Property Public Function LookupValue(ByVal HKey As HKey, ByVal Path As String, ByVal Value As String) As String Dim sResult As String Dim sResult2 As String
If Not _Connected Then Connect() oReg.GetStringValue(HKey, Path, Value, sResult) LookupValue = sResult End Function Private Sub Connect() 'On Error Resume Next If _User = Nothing Or _User = "" Then oServer = oWMIServer.ConnectServer(_Server, "root\default") Else oServer = oWMIServer.ConnectServer(_Server, "root\default", _User, _Password) If Err.Number <> 0 Then Err.Clear() oServer = oWMIServer.ConnectServer(_Server, "root\default") End If End If oReg = oServer.Get("StdRegProv") _Connected = True End Sub End Class
And here's what I'm using to test it with.
Private Sub ExecuteScript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExecuteScript.Click Dim y As New RemoteRegistry Dim Key As String = "SYSTEM\CurrentControlSet\Services\SNMP"
y.Server = "srvr-istest6" y.UserName = UserName.Text y.Password = Password.Text
label1.Text = y.LookupValue(HKey.LOCAL_MACHINE, Key, "DisplayName") y = Nothing End Sub
I'm wondering if anyone has any ideas as to why I can't run the ExecuteScript twice without getting an error on the oReg.GetStringValue, I'm all ears(well I don't look like dumbo, but do feel like one sometimes)...
Thanks, kmurphy roughlyat nexusinfosys and that's in the com domain.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Murat Tasan |
last post by:
hi, i am having a small problem with constructing an inner class.
i am using an inner class (and not a static nested class) because the
methods of the inner class need access to the enclosing...
|
by: Fernando Rodriguez |
last post by:
Hi,
I need to traverse the methods defined in a class and its superclasses. This
is the code I'm using:
# An instance of class B should be able to check all the methods defined in B
#and A,...
|
by: Oplec |
last post by:
Hi,
I'm learning C++ as a hobby using The C++ Programming Language : Special
Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that
deal with templates. Exercise 13.9 asks for me...
|
by: Text |
last post by:
I'm trying to invoke the createkey method under StdRegProv but I can't seem
to get the first
imparam correct
it says that "Value was either too large or too small for a UInt32 when it...
|
by: Banaticus Bart |
last post by:
I wrote an abstract base class from which I've derived a few other
classes. I'd like to create a base class array where each element is
an instance of a derived object. I can create a base class...
|
by: scheru |
last post by:
I am trying to access the stdregprov using the COM interface using C++. I am
unsuccessful in invoking the Put method that initializes the variables before
calling the Exec method of...
|
by: Andy |
last post by:
Hi all,
I have a site with the following architecture:
Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits...
|
by: Hamilton Woods |
last post by:
Diehards,
I developed a template matrix class back around 1992 using Borland C++ 4.5
(ancestor of C++ Builder) and haven't touched it until a few days ago. I
pulled it from the freezer and...
|
by: emin.shopper |
last post by:
I had a need recently to check if my subclasses properly implemented
the desired interface and wished that I could use something like an
abstract base class in python. After reading up on metaclass...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |