变量替换在WMI方法

问题描述:

我试图执行一个硬编码的变量工作的命令,但是当我尝试并更换名称下面selectedname测试,我不能让语法转义命令。基本思想是我使用WMI来查询应用程序池名称,然后选择一个并存储在slectedname变量中,当我使用msgbox(selectedname)行进行测试时,该变量起作用。它也显示了当我正在通过,但不会传递到底部的命令。任何帮助都会很棒。 这里我想执行命令的功能是变量替换在WMI方法

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 

在弗里斯, 德文

尝试引用变量selectedname这样

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