0
我試圖執行一個硬編碼的變量工作的命令,但是當我嘗試並更換名稱下面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
在弗里斯, 德文