WMI方法中的变量替换

时间:2011-05-05 20:17:48

标签: vb.net iis wmi

我正在尝试执行一个使用硬编码变量的命令,但是当我尝试用 selectedname 替换下面的名称​​ test 时,我无法获得逃避命令。基本思路是我使用WMI查询应用程序池名称,然后选择一个并存储在slectedname变量中,该变量在我使用msgbox(selectedname)行进行测试时有效。当我单步执行时它也显示出来,但是没有传递给bottom命令。任何帮助都会很棒。 我尝试执行命令的函数是

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

在弗里斯, 德文

1 个答案:

答案 0 :(得分:0)

尝试像这样引用变量selectedname

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