You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET应用通过WMI远程执行SCCM应用安装/卸载的技术求助

SCCM Application Install/Uninstall via WMI in .NET: Complete Guide

Hey there! You're already off to a solid start with your VB.NET code for interacting with SCCM via WMI. Let's fill in the missing pieces and get those install/uninstall operations running smoothly.

First: Finish the Install Method

Your existing code sets up the ManagementScope and targets the CCM_Application class, but you need to populate the required parameters for the Install method. Here's what you're missing:

Required Parameters for Install

  • Id: The unique CI ID of your SCCM application (find this in the SCCM console under Application Properties > General > CI Unique ID)
  • RevisionId: The revision ID of the application (also located in the same properties pane)
  • IsMachineTarget: Set to True for machine-wide installs, False for user-specific installs
  • Priority: Typically 2 (normal priority; valid values are 1=high, 2=normal, 3=low)

Here's the complete install code snippet:

Dim wmiLoc As ManagementScope = New ManagementScope("\\" & Target & "\root\ccm\ClientSDK", Options)
wmiLoc.Connect() ' Don't forget to establish the WMI connection!

Dim wmiProcPath As ManagementPath = New ManagementPath("CCM_Application")
Dim mc As ManagementClass = New ManagementClass(wmiLoc, wmiProcPath, Nothing)

' Get and populate install method parameters
Dim inParams As ManagementBaseObject = mc.GetMethodParameters("Install")
inParams("EnforcePreference") = 0 ' 0 = install as required, 1 = install as available
inParams("Id") = "YOUR_APPLICATION_CI_UNIQUE_ID" ' Replace with your app's ID
inParams("RevisionId") = "YOUR_APPLICATION_REVISION_ID" ' Replace with your app's revision ID
inParams("IsMachineTarget") = True ' Adjust based on your target scope
inParams("Priority") = 2 ' Normal priority

' Execute the install method
Dim outParams As ManagementBaseObject = mc.InvokeMethod("Install", inParams, Nothing)

' Handle the return value
Dim returnValue As Integer = Convert.ToInt32(outParams("ReturnValue"))
Select Case returnValue
    Case 0
        Console.WriteLine("Install initiated successfully!")
    Case 1
        Console.WriteLine("Install failed. Check SCCM client logs for details.")
    Case 2
        Console.WriteLine("Install is already in progress on the target machine.")
    ' Add more case handling for other return codes as needed
End Select

Uninstall Method Implementation

Uninstalling follows a nearly identical pattern, but uses the Uninstall method of the CCM_Application class. Here's how to set it up:

' Reuse your existing ManagementScope and ManagementClass setup here

Dim uninstallParams As ManagementBaseObject = mc.GetMethodParameters("Uninstall")
uninstallParams("Id") = "YOUR_APPLICATION_CI_UNIQUE_ID"
uninstallParams("RevisionId") = "YOUR_APPLICATION_REVISION_ID"
uninstallParams("IsMachineTarget") = True
uninstallParams("Priority") = 2

' Execute the uninstall method
Dim uninstallOutParams As ManagementBaseObject = mc.InvokeMethod("Uninstall", uninstallParams, Nothing)

' Handle the uninstall return value
Dim uninstallReturnValue As Integer = Convert.ToInt32(uninstallOutParams("ReturnValue"))
Select Case uninstallReturnValue
    Case 0
        Console.WriteLine("Uninstall initiated successfully!")
    Case 1
        Console.WriteLine("Uninstall failed. Check SCCM client logs for details.")
    Case 2
        Console.WriteLine("Uninstall is already in progress on the target machine.")
End Select

Critical Notes & Troubleshooting

  • Permissions: The account running your .NET app must have local administrator rights on the remote machine, plus SCCM client permissions to initiate installs/uninstalls.
  • WMI Connectivity: Ensure the remote machine's firewall allows WMI traffic (TCP port 135 and dynamic RPC ports). You can test connectivity with wbemtest.exe by connecting to \\TARGET\root\ccm\ClientSDK from your local machine.
  • Parameter Accuracy: Double-check that Id and RevisionId match exactly what's in the SCCM console—typos here will cause silent failures.
  • Error Handling: Wrap your WMI calls in Try/Catch blocks to handle common issues like ManagementException (WMI connectivity/permission problems) and InvalidOperationException.

Example error handling:

Try
    wmiLoc.Connect()
    ' Rest of your install/uninstall code here
Catch ex As ManagementException
    Console.WriteLine($"WMI Error: {ex.Message} | Error Code: {ex.ErrorCode}")
Catch ex As Exception
    Console.WriteLine($"General Error: {ex.Message}")
End Try

内容的提问来源于stack exchange,提问作者Rathfon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:32:18