|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WMI - Executing a method to read registry - Going Crazy!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 BMack,
Andy reason that you don't use the registry class for this? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfmicrosoftwin32registryclasstopic.asp I hope this helps, Cor Show quoteHide quote "Bmack500" <brett.m***@gmail.com> schreef in bericht news:1146165802.615235.238020@y43g2000cwc.googlegroups.com... > 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 >
DLL does not load Dynamically
Stepping between .Net IDE into a VB6 dll call simple combo question ImageList - Memory-Issue in vs2005 is this possible... Format Function Redirect question FileSystemWatcher any experts here? General Design Question - Class Name Upgrading to VS 2005 compatibility with 2003 |
|||||||||||||||||||||||