【问题标题】:variable replacement in WMI methodWMI方法中的变量替换
【发布时间】:2011-05-05 20:17:47
【问题描述】:

我正在尝试执行一个适用于硬编码变量的命令,但是当我尝试将下面的名称 test 替换为 selectedname 时,我无法获得逃避命令。基本思想是我使用 WMI 来查询应用程序池名称,然后选择一个并存储在 slectedname 变量中,当我使用 msgbox(selectedname) 行进行测试时,它可以工作。当我单步执行时它也会显示,但不会传递给底部命令。任何帮助都会很棒。 我试图执行命令的功能是

Private Sub Stpbtn_Click(sender As Object, e As System.EventArgs) Handles Stpbtn.Click

        Dim selectedname As String
        selectedname = RWM_lst1.SelectedItem.ToString
        MsgBox(selectedname)

        Dim strComputer
        Dim objShare
        Dim objWMIService
        Dim objOutParams
        strComputer = "."
        objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WebAdministration")
        '' Obtain an instance of the the class 
        '' using a key property value.
        objShare = objWMIService.Get("ApplicationPool.Name='test'")

        '' no InParameters to define

        '' Execute the method and obtain the return status.
        '' The OutParameters object in objOutParams
        '' is created by the provider.


        objOutParams = objWMIService.ExecMethod("ApplicationPool.Name='test'", "Stop") -- I know this works with the hard coded value of test
        objOutParams = objWMIService.ExecMethod("ApplicationPool.Name=" & selectedname & ", "Stop") --I want to replace the variable selectedname with the value captured in the selectedname  variable

    End Sub
End Class

在弗里斯, 德文

【问题讨论】:

    标签: vb.net iis wmi


    【解决方案1】:

    尝试像这样引用变量selectedname

    objOutParams = objWMIService.ExecMethod("ApplicationPool.Name='" & selectedname & "'", "Stop")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2022-01-15
      相关资源
      最近更新 更多