I have a simple class that I am trying to make visible to WMI (coupled
provider):
using System;
using System.Collecti ons;
using System.Diagnost ics;
using System.Manageme nt.Instrumentat ion;
[assembly: WmiConfiguratio n(
@"root\test" ,
HostingModel =
ManagementHosti ngModel.Network Service)]
namespace WmiTest
{
[System.Componen tModel.RunInsta ller(true)]
public class MyInstall : DefaultManageme ntInstaller
{
}
[ManagementEntit y(Name = "My_Process ")]
public class MyProcess
{
[ManagementBind]
public MyProcess (int processId)
{
this.processId =
Process.GetProc essById(process Id).Id;
}
[ManagementKey]
public int processId;
}
}
After using Installutil the class is shown in root\test namespace in the
repository as My_Process and I am able to query it with this VBScript code:
' VBScript source code
Set objWMI = GetObject _
("winmgmts:root \test")
Set objInstance = objWMI.Get _
("My_Process.Pr ocessId=172")
WScript.Echo objInstance.Pro cessId
' VBScript source code
Set objWMI = GetObject _
("winmgmts:root \test")
Set objInstance = objWMI.Get _
("My_Process.Pr ocessId=1844674 4073709551788")
WScript.Echo objInstance.Pro cessId
Both scripts echo 172. Why is this?
Also, if I use the following script:
' VBScript source code
Set objWMI = GetObject _
("winmgmts:root \test")
Set objInstance = objWMI.Get _
("My_Process.Pr ocessId='Blah!' ")
WScript.Echo objInstance.Pro cessId
the script hangs and I get this recorded in the Application Event Log:
Event Type: Error
Event Source: .NET Runtime
Event Category: None
Event ID: 1023
Date: 6/21/2008
Time: 7:59:00 PM
User: N/A
Computer: ANAME
Description:
..NET Runtime version 2.0.50727.1433 - System.FormatEx ception: Input string
was not in a correct format.
at System.Number.S tringToNumber(S tring str, NumberStyles options,
NumberBuffer& number, NumberFormatInf o info, Boolean parseDecimal)
at System.Number.P arseInt32(Strin g s, NumberStyles style,
NumberFormatInf o info)
at System.String.S ystem.IConverti ble.ToInt32(IFo rmatProvider provider)
at System.Convert. ChangeType(Obje ct value, Type conversionType,
IFormatProvider provider)
at
System.Manageme nt.Instrumentat ion.WbemMarshal .TypeHelper.Kno wnTypeHandler.C onvertFromStrin g(String s)
at
System.Manageme nt.Instrumentat ion.WbemMarshal .TypeHelper.Kno wnTypeHandler_S tring.ChangeTyp e(Object o, Type t)
at
System.Manageme nt.Instrumentat ion.WbemMarshal .TypeHelper.Cha ngeType(Object o,
Type t)
at
System.Manageme nt.Instrumentat ion.WbemMarshal .PrepareManaged ObjectForProvid er(Object& oValue, Type destType)
at
System.Manageme nt.Instrumentat ion.Constructor Invoker.InvokeI nfrastructureCt or(ObjectDictio nary
parameters, Int32 hresultForMissi ngProps, String sOperationReque sted)
at UMPProvider.Get (CallContext context, ICIMResultHandl er resultHandler)
at WmiNative.WbemP rovider.WmiNati ve.IWbemService s.GetObjectAsyn c(String
objectPath, Int32 flags, IWbemContext wbemContext, IWbemObjectSink wbemSink)
For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
How can this be handled? Thanks in advance.
--
urkec