PC Review


Reply
Thread Tools Rate Thread

WMI - Executing a method to read registry - Going Crazy!

 
 
Bmack500
Guest
Posts: n/a
 
      27th Apr 2006
Hello, and thanks in advance. I have the below code which keeps
returning "1" as the result. It's never successful, and I don't know
what I'm doing wrong. I know that when I get to objManagementClass &
objManagmeentBaseObject, the VB debugger says "can't read value" on all
lines. Bu tI can read the objPath, and the scope just fine.


Dim strStringValue As String = ""

'Dim strValue As String
Dim objManagementScope As ManagementScope
Dim objManagementClass As ManagementClass
Dim objManagementBaseObject As ManagementBaseObject
Dim objPath As ManagementPath

sSubKey = sSubKey.Trim
strValue = strValue.Trim

If (sSubKey.Length > 0) Then
'Connect to the specified computer registry
objPath = New ManagementPath
objPath.Server = "SERVERNAME(WIN2003)"
objPath.NamespacePath = "root\default"
objPath.ClassName = "stdRegProv"

objManagementScope = New ManagementScope(objPath)
objManagementScope.Options.EnablePrivileges = True
objManagementScope.Options.Impersonation =
ImpersonationLevel.Impersonate
objManagementScope.Connect()


'Retrieve the required string value from the registry

If objManagementScope.IsConnected Then
objManagementClass = New ManagementClass(objPath)
objManagementClass.Scope = objManagementScope
objManagementBaseObject =
objManagementClass.GetMethodParameters("GetStringValue")
objManagementBaseObject.SetPropertyValue("sSubKeyName",
sSubKey)
objManagementBaseObject.SetPropertyValue("sValueName",
strValue)
objManagementBaseObject =
objManagementClass.InvokeMethod("GetStringValue",
objManagementBaseObject, Nothing)
strReturn =
objManagementBaseObject.Properties.Item("ReturnValue").Value.ToString()
If strReturn = "0" Then
strResult =
CType(objManagementBaseObject.Properties.Item("sValue").Value, String)
Else
strReturn =
objManagementBaseObject.Properties.Item("ReturnValue").Value.ToString
End If
'objManagementclass.
End If
End If

 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      28th Apr 2006
BMack,

Andy reason that you don't use the registry class for this?

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Bmack500" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hello, and thanks in advance. I have the below code which keeps
> returning "1" as the result. It's never successful, and I don't know
> what I'm doing wrong. I know that when I get to objManagementClass &
> objManagmeentBaseObject, the VB debugger says "can't read value" on all
> lines. Bu tI can read the objPath, and the scope just fine.
>
>
> Dim strStringValue As String = ""
>
> 'Dim strValue As String
> Dim objManagementScope As ManagementScope
> Dim objManagementClass As ManagementClass
> Dim objManagementBaseObject As ManagementBaseObject
> Dim objPath As ManagementPath
>
> sSubKey = sSubKey.Trim
> strValue = strValue.Trim
>
> If (sSubKey.Length > 0) Then
> 'Connect to the specified computer registry
> objPath = New ManagementPath
> objPath.Server = "SERVERNAME(WIN2003)"
> objPath.NamespacePath = "root\default"
> objPath.ClassName = "stdRegProv"
>
> objManagementScope = New ManagementScope(objPath)
> objManagementScope.Options.EnablePrivileges = True
> objManagementScope.Options.Impersonation =
> ImpersonationLevel.Impersonate
> objManagementScope.Connect()
>
>
> 'Retrieve the required string value from the registry
>
> If objManagementScope.IsConnected Then
> objManagementClass = New ManagementClass(objPath)
> objManagementClass.Scope = objManagementScope
> objManagementBaseObject =
> objManagementClass.GetMethodParameters("GetStringValue")
> objManagementBaseObject.SetPropertyValue("sSubKeyName",
> sSubKey)
> objManagementBaseObject.SetPropertyValue("sValueName",
> strValue)
> objManagementBaseObject =
> objManagementClass.InvokeMethod("GetStringValue",
> objManagementBaseObject, Nothing)
> strReturn =
> objManagementBaseObject.Properties.Item("ReturnValue").Value.ToString()
> If strReturn = "0" Then
> strResult =
> CType(objManagementBaseObject.Properties.Item("sValue").Value, String)
> Else
> strReturn =
> objManagementBaseObject.Properties.Item("ReturnValue").Value.ToString
> End If
> 'objManagementclass.
> End If
> End If
>



 
Reply With Quote
 
Bmack500
Guest
Posts: n/a
 
      19th May 2006
Thanks! Got it working.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a method or function using a String Nathan Sokalski Microsoft VB .NET 2 4th Sep 2009 06:53 PM
twice method executing Op Microsoft ASP .NET 1 23rd Nov 2008 02:43 AM
SelectedIndexChanged method executing twice? =?Utf-8?B?RGFiYmxlcg==?= Microsoft ASP .NET 0 20th Aug 2006 08:12 AM
Executing a method in one form from another =?Utf-8?B?QW50aG9ueSBOeXN0cm9t?= Microsoft VB .NET 2 8th May 2004 01:18 PM
Retrieving the Name of the Current Executing Method clr Microsoft VB .NET 7 1st Nov 2003 01:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:14 PM.