首页 > 编程 > VBScript > 正文

使用vbs脚本添加程序到自启动项的代码

2019-10-26 18:06:10
字体:
来源:转载
供稿:网友
因编辑器过滤了一些字符,比如&,所以下面的脚本可能会运行错误。。看官添加&&这个字符就可以了。
vbs脚本的功能呢是很多的,不过有时候我们只需要其中的某些功能,今天我突然想研究下怎么用vbs脚本实现添加程序到自启动项......

首先来一段吧...

复制代码 代码如下:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: add2run01.vbs
'
' AUTHOR: shile
' DATE : 2008-12-13
'
' COMMENT: vbs实现添加程序到自启动项
'
'==========================================================================
On Error Resume Next '出错继续执行下个命令
dim ws
Set ws=CreateObject("Wscript.Shell")
ws.RegWrite "HKLM/Software/Microsoft/Windows/CurrentVersion/Run/cmd","cmd.exe"

竟然被360安全卫士拦截了,不过点击同意就可以了。在autoruns里面刷新后还是不能显示这个启动项,看来这软件不太完美.
功能太弱了,我想增强一下....
首先,弹个窗口询问询问添加什么程序到启动项,并且询问下启动项的键值。
复制代码 代码如下:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: add2run02.vbs
'
' AUTHOR: shile
' DATE : 2008-12-13
'
' COMMENT: vbs实现添加程序到自启动项
'
'==========================================================================
On Error Resume Next '出错继续执行下个命令
Dim ws
Set ws=CreateObject("Wscript.Shell")
Dim runKey,runPath
runKey = InputBox("输入自启动项键值名称","请输入")
runPath = InputBox("输入相应的程序路径","请输入")

'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的,但是发现还是两个按钮,还是vbYes好!
功能还是不太强的,如果能判断是否存在已经有的项,是否替换确认,那么就比较完善了!
继续下去...
复制代码 代码如下:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: add2run03.vbs
'
' AUTHOR: shile
' DATE : 2008-12-13
'
' COMMENT: vbs实现添加程序到自启动项
'
'==========================================================================
On Error Resume Next '出错继续执行下个命令
dim ws
Set ws=CreateObject("Wscript.Shell")
Dim runKey,runPath
runKey = InputBox("输入自启动项键值名称","请输入")
runPath = InputBox("输入相应的程序路径","请输入")
Dim temp,ret
temp = ws.RegRead("HKLM/Software/Microsoft/Windows/CurrentVersion/Run/"&runKey)
'MsgBox temp
If temp <> Empty Then
ret = MsgBox( "键值"&runKey"已经存在,其值为"&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
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表