Vb.net WMI方法中的变量替换
我试图执行一个使用硬编码变量的命令,但是当我尝试用selectedname替换下面的名称测试时,我无法获取转义命令的语法。基本思想是我使用WMI查询应用程序池名称,然后选择一个并存储在slectedname变量中,当我使用msgboxselectedname行进行测试时,该变量起作用。当我单步执行时,它也会显示,但不会传递到底部命令。任何帮助都会很好。 我尝试执行命令的函数是Vb.net WMI方法中的变量替换,vb.net,iis,wmi,Vb.net,Iis,Wmi,我试图执行一个使用硬编码变量的命令,但是当我尝试用selectedname替换下面的名称测试时,我无法获取转义命令的语法。基本思想是我使用WMI查询应用程序池名称,然后选择一个并存储在slectedname变量中,当我使用msgboxselectedname行进行测试时,该变量起作用。当我单步执行时,它也会显示,但不会传递到底部命令。任何帮助都会很好。 我尝试执行命令的函数是 Private Sub Stpbtn_Click(sender As Object, e As System.Event
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
在弗里斯,
Devin试着像这样引用变量selectedname
objOutParams = objWMIService.ExecMethod("ApplicationPool.Name='" & selectedname & "'", "Stop")