溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

VBS腳本如何實現(xiàn)GUI圖形界面和日志清除功能

發(fā)布時間:2021-10-12 10:19:10 來源:億速云 閱讀:178 作者:小新 欄目:開發(fā)技術(shù)

這篇文章給大家分享的是有關(guān)VBS腳本如何實現(xiàn)GUI圖形界面和日志清除功能的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

使用方法:將下面的代碼保存為rizhi.vbs雙擊運行即可,如果不行可能是殺毒軟件的問題。可以搜索下。億速云以前提供過解決方法。

set ie=wscript.createobject("internetexplorer.application","event_") '創(chuàng)建ie對象' 
ie.menubar=0 '取消菜單欄' 
ie.addressbar=0 '取消地址欄' 
ie.toolbar=0 '取消工具欄' 
ie.statusbar=0 '取消狀態(tài)欄' 
ie.width=400 '寬400' 
ie.height=400 '高400' 
ie.resizable=0 '不允許用戶改變窗口大小' 
ie.navigate "about:blank" '打開空白頁面' 
ie.left=fix((ie.document.parentwindow.screen.availwidth-ie.width)/2) '水平居中' 
ie.top=fix((ie.document.parentwindow.screen.availheight-ie.height)/2) '垂直居中' 
ie.visible=1 '窗口可見' 

with ie.document '以下調(diào)用document.write方法,' 
.write "<html><body bgcolor=#dddddd scroll=no>" '寫一段html到ie窗口中。' 
.write "<h3 align=center>遠程清除系統(tǒng)日志</h3><br>" 
.write "<p>目標IP:<input id=ip type=text size=15>" '也可以用navigate方法直接打開一' 
.write "<p>用戶名:<input id=user type=text size=30>" '個html文件,效果是一樣的。' 
.write "<p>密碼: <input id=pass type=password size=30>" 
.write "<p align=center>類型:" '不僅是input對象,所有DHTML支持' 
.write "<input id=app type=checkbox>應用程序 " '的對象及其屬性、方法都可以使用。' 
.write "<input id=sys type=checkbox>系統(tǒng) " 
.write "<input id=sec type=checkbox>安全" '訪問這些對象的辦法和網(wǎng)頁中訪問' 
.write "<p align=center><br>" '框架內(nèi)對象是類似的。' 
.write "<input id=confirm type=button value=確定> " 
.write "<input id=cancel type=button value=取消>" 
.write "</body></html>" 
end with 

dim wmi '顯式定義一個全局變量' 
set wnd=ie.document.parentwindow '設置wnd為窗口對象' 
set id=ie.document.all '設置id為document中全部對象的集合' 
id.confirm.onclick=getref("confirm") '設置點擊"確定"按鈕時的處理函數(shù)' 
id.cancel.onclick=getref("cancel") '設置點擊"取消"按鈕時的處理函數(shù)' 

do while true '由于ie對象支持事件,所以相應的,' 
wscript.sleep 200 '腳本以無限循環(huán)來等待各種事件。' 
loop 

sub event_onquit 'ie退出事件處理過程' 
wscript.quit '當ie退出時,腳本也退出' 
end sub 

sub cancel '"取消"事件處理過程' 
ie.quit '調(diào)用ie的quit方法,關(guān)閉IE窗口' 
end sub '隨后會觸發(fā)event_onquit,于是腳本也退出了' 

sub confirm '"確定"事件處理過程,這是關(guān)鍵' 
with id 
if .ip.value="" then .ip.value="." '空ip值則默認是對本地操作' 
if not (.app.checked or .sys.checked or .sec.checked) then 'app等都是checkbox,通過檢測其checked' 
wnd.alert("至少選擇一種日志") '屬性,來判斷是否被選中。' 
exit sub 
end if 
set lct=createobject("wbemscripting.swbemlocator") '創(chuàng)建服務器定位對象' 
on error resume next '使腳本宿主忽略非致命錯誤' 
set wmi=lct.connectserver(.ip.value,"root/cimv2",.user.value,.pass.value) '連接到root/cimv2名字空間' 
if err.number then '自己捕捉錯誤并處理' 
wnd.alert("連接WMI服務器失敗") '這里只是簡單的顯示“失敗”' 
err.clear 
on error goto 0 '仍然讓腳本宿主處理全部錯誤' 
exit sub 
end if 
if .app.checked then clearlog "application" '清除每種選中的日志' 
if .sys.checked then clearlog "system" 
if .sec.checked then clearlog "security" '注意,在XP下有限制,不能清除安全日志' 
wnd.alert("日志已清除") 
end with 
end sub 

sub clearlog(name) 
wql="select * from Win32_NTEventLogFile where logfilename='"&name&"'" 
set logs=wmi.execquery(wql) '注意,logs的成員不是每條日志,' 
for each l in logs '而是指定日志的文件對象。' 
if l.cleareventlog() then 
wnd.alert("清除日志"&name&"時出錯!") 
ie.quit 
wscript.quit 
end if 
next 
end sub

上面是通過vbs輸出html內(nèi)容來實現(xiàn),一般情況下,億速云小編是使用hta來實現(xiàn)圖像界面。

感謝各位的閱讀!關(guān)于“VBS腳本如何實現(xiàn)GUI圖形界面和日志清除功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI