因編輯器過濾了一些字符,比如,所以下面的腳本可能會運行錯誤。。看官添加這個字符就可以了。
vbs腳本的功能呢是很多的,不過有時候我們只需要其中的某些功能,今天我突然想研究下怎么用vbs腳本實現(xiàn)添加程序到自啟動項......
首先來一段吧...
復(fù)制代碼 代碼如下:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: add2run01.vbs
'
' AUTHOR: shile
' DATE : 2008-12-13
'
' COMMENT: vbs實現(xiàn)添加程序到自啟動項
'
'==========================================================================
On Error Resume Next '出錯繼續(xù)執(zhí)行下個命令
dim ws
Set ws=CreateObject("Wscript.Shell")
ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd","cmd.exe"
竟然被360安全衛(wèi)士攔截了,不過點擊同意就可以了。在autoruns里面刷新后還是不能顯示這個啟動項,看來這軟件不太完美.
功能太弱了,我想增強(qiáng)一下....
首先,彈個窗口詢問詢問添加什么程序到啟動項,并且詢問下啟動項的鍵值。
復(fù)制代碼 代碼如下:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: add2run02.vbs
'
' AUTHOR: shile
' DATE : 2008-12-13
'
' COMMENT: vbs實現(xiàn)添加程序到自啟動項
'
'==========================================================================
On Error Resume Next '出錯繼續(xù)執(zhí)行下個命令
Dim ws
Set ws=CreateObject("Wscript.Shell")
Dim runKey,runPath
runKey = InputBox("輸入自啟動項鍵值名稱","請輸入")
runPath = InputBox("輸入相應(yīng)的程序路徑","請輸入")
'ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd","cmd.exe"
ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\"runKey,runPath
'提示下
MsgBox "添加"runKey""runPath">成功",vbYes,"恭喜!"
本來要用vbOK的,但是發(fā)現(xiàn)還是兩個按鈕,還是vbYes好!
功能還是不太強(qiáng)的,如果能判斷是否存在已經(jīng)有的項,是否替換確認(rèn),那么就比較完善了!
繼續(xù)下去...
復(fù)制代碼 代碼如下:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: add2run03.vbs
'
' AUTHOR: shile
' DATE : 2008-12-13
'
' COMMENT: vbs實現(xiàn)添加程序到自啟動項
'
'==========================================================================
On Error Resume Next '出錯繼續(xù)執(zhí)行下個命令
dim ws
Set ws=CreateObject("Wscript.Shell")
Dim runKey,runPath
runKey = InputBox("輸入自啟動項鍵值名稱","請輸入")
runPath = InputBox("輸入相應(yīng)的程序路徑","請輸入")
Dim temp,ret
temp = ws.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Run\"runKey)
'MsgBox temp
If temp > Empty Then
ret = MsgBox( "鍵值"runKey"已經(jīng)存在,其值為"temp",是否替換為新的值"runPath, vbOKCancel, "提示!")
If ret = vbOK Then
ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\"runKey,runPath
MsgBox "修改"runKey"值為"runPath"成功",vbYes,"恭喜!"
End If
Else
ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\"runKey,runPath
MsgBox "添加"runKey""runPath">成功",vbYes,"恭喜!"
End If
當(dāng)然了,啟動項在注冊表有很多地方,就不一一說明了......