我們今天不會花太多時間來談論 HTA;如果您對此感興趣,可以查找大約一年前我們針對該主題推出的網絡廣播。可以說,HTA 使我們能夠將 Internet Explorer 和腳本代碼結合在一起,并反過來為腳本提供圖形用戶界面。雖然還有一些方法可以將圖形用戶界面合并到腳本中,但是對于才開始涉足 GUI 開發(fā)的用戶來說,這可能是最簡單的方法。
If ComputerOption(0).Checked Then strComputer = ComputerOption(0).Value End If If ComputerOption(1).Checked Then strComputer = ComputerOption(1).Value End If If ComputerOption(2).Checked Then strComputer = ComputerOption(2).Value End If If ComputerOption(3).Checked Then strComputer = ComputerOption(3).Value End If
If strComputer = "" Then Exit Sub End If
Set objWMIService = GetObject _ ("winmgmts://" & strComputer & "/root/cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_OperatingSystem") For Each objItem in ColItems Msgbox objItem.Caption Next
那么該代碼包含哪些內容呢?我們可以將該代碼分為四部分:其中有兩個部分使用 HTML 標記來實現(xiàn)單選按鈕以及“Run Script(運行腳本)”和“Cancel(取消)”按鈕,而另外兩個部分則根據您所點擊的是“Run Script”還是“Cancel”來運行子例程。讓我們更進一步了解這幾個部分。
例如,HTML 代碼在此顯示這四個單選按鈕。(如果您了解 HTML,那么這里就沒有什么特別的;這是標準的 HTML 編碼。)請注意,所有按鈕都有相同的名稱 (ComputerOption);這是為了確保一次只能選擇一個按鈕。還要注意,每個按鈕的“值”都被設為相應計算機的名稱:
If ComputerOption(0).Checked Then strComputer = ComputerOption(0).Value End If If ComputerOption(1).Checked Then strComputer = ComputerOption(1).Value End If If ComputerOption(2).Checked Then strComputer = ComputerOption(2).Value End If If ComputerOption(3).Checked Then strComputer = ComputerOption(3).Value End If
If strComputer = "" Then Exit Sub End If
Set objWMIService = GetObject _ ("winmgmts://" & strComputer & "/root/cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_OperatingSystem") For Each objItem in ColItems Msgbox objItem.Caption Next
If ComputerOption(0).Checked Then strComputer = ComputerOption(0).Value End If If ComputerOption(1).Checked Then strComputer = ComputerOption(1).Value End If If ComputerOption(2).Checked Then strComputer = ComputerOption(2).Value End If If ComputerOption(3).Checked Then strComputer = ComputerOption(3).Value End If
If strComputer = "" Then Exit Sub End If
Set objWMIService = GetObject _ ("winmgmts://" & strComputer & "/root/cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_Service") For Each objItem in ColItems strText = strText & objItem.Name & "<BR>" Next