开发者

What could cause the Wmi custom MSBuild task to throw "ManagementException not found"?

开发者 https://www.devze.com 2023-01-15 07:12 出处:网络
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:

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 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.


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,

0

精彩评论

暂无评论...
验证码 换一张
取 消