tags:

views:

13

answers:

1

The Wmi task is part of the MSBuild Extension Pack. On one of our development machines, it thrown ManagementException not found. Here's the target:

<Target Name="Clean">
    <ItemGroup>
      <WmiProps Include="State"/>
      <WmiProps Include="DisplayName"/>
    </ItemGroup>

    <!-- Create list of VIKAD services that are currently running. -->
    <Wmi TaskAction="Query" Class="Win32_Service WHERE DisplayName LIKE '%ServiceName%'" Properties="@(WmiProps)" Namespace="\root\CIMV2" MachineName="$(LocalDbServer)">
      <Output TaskParameter="Info" ItemName="Info"/>
    </Wmi>

    <Wmi TaskAction="Execute" Class="Win32_Service" Method="StopService" Instance="Name='%(Info.DisplayName)'" Namespace="\root\CIMV2">
      <Output TaskParameter="ReturnValue" PropertyName="Rval1"/>
    </Wmi>
</Target>

The second WMI task is the one that throws the exception.

+1  A: 

The error is pretty straightforward (the class wasn't found). I believe it's happening because you're attempting to query for a service by it's display name, not it's actual name. Switching the second task to be

Instance="Name='%(Info.Name)'"

Should probably do the trick.

Hope this helps,

Start-Automating
I'll give this a try.
Scott A. Lawrence
@Start-Automating Thanks! The way that our services were done previously, the display name and the name were the same (the previous target worked under that assumption). That seems to have changed recently, which broke the target. Adding Name to WmiProps and updating the attribute to what you have in your answer fixed everything.
Scott A. Lawrence