当前位置:DOS资源站资料中心VBS脚本 → 用VBS禁止运行指定的程序

用VBS禁止运行指定的程序

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-4-24 20:54:30

choice=inputbox("请根据不同的操作,键入相应的字符"&vbcrlf&""&vbcrlf&"1   添加一个禁止运行的程序"&vbcrlf&"2   恢复一个禁止运行的程序"&vbcrlf&"3   恢复所有禁止运行的程序"&vbcrlf&"4   查看已经添加的程序"&vbcrlf&"5   退出","选择操作")
set wind9=createobject("scripting.filesystemobject")
If (wind9.fileexists("c:\windows\wind.txt")) Then
      else
wind9.createtextfile "c:\windows\wind.txt",true
set wind0=wind9.opentextfile("c:\windows\wind.txt",8)
wind0.writeline " "
wind0.close
     end if
set wind=createobject("wscript.shell")
     if choice="1" then
wind1=inputbox("请键入程序名 (不需要路径)"&vbcrlf&""&vbcrlf&"按确定后,该程序将不能运行","指定程序名")
wind.run "reg add "&"""HKLM\software\microsoft\Windows nt\currentVersion\image file execution Options\"&wind1&""""&" /v debugger"&" /t reg_sz"&" /d """&wind1&""""&" /f",0
set wind7=wind9.opentextfile("c:\windows\wind.txt",8)
set wind2=wind9.opentextfile("c:\windows\wind.txt",1)
w=wind2.readall
if instr(w,wind1) then
else
wind7.writeline wind1
wind7.close
end if
decide=msgbox("添加成功   "&vbcrlf&""&vbcrlf&"是否继续",52,"清风")
if decide=6 then
wind.run """"&wscript.scriptfullname&""""
else wscript.quit
end if
     elseif choice="2" then
wind1=inputbox("请键入程序名 (不需要路径)"&vbcrlf&""&vbcrlf&"按确定后,该程序将可以运行","指定程序名")
set wind3=wind9.opentextfile("c:\windows\wind.txt",1)
w=wind3.readall
wind3.close
    if instr(w, wind1) Then
wind.run "reg delete "&"""hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\"&wind1&""""&" /f",0
decide=msgbox("已恢复!!   "&vbcrlf&""&vbcrlf&"是否继续",52,"清风")
if decide=6 then
wind.run """"&wscript.scriptfullname&""""
else wscript.quit
end if
else
decide=msgbox("指定的程序并未添加!   "&vbcrlf&""&vbcrlf&"是否继续",20,"错误")
if decide=6 then
wind.run """"&wscript.scriptfullname&""""
else wscript.quit
end if
    end if
     elseif choice="3" then
set wind1=wind9.opentextfile("c:\windows\wind.txt",1)  
do until wind1.atendofstream  
w=wind1.readline  
wind.run "reg delete "&"""hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\"&w&""""&" /f",vbhide
loop
wind1.close
wind9.deletefile "c:\windows\wind.txt"
decide=msgbox("操作成功   "&vbcrlf&""&vbcrlf&"是否继续",52,"清风")
if decide=6 then
wind.run """"&wscript.scriptfullname&""""
else wscript.quit
end if
    elseif choice="4" then
set wind1=wind9.opentextfile("c:\windows\wind.txt",1)
w=wind1.readall
wind1.close
msgbox w,48,"查看所有                    "
       else
wscript.quit
      end if

简单的注解

choice=inputbox("请根据不同的操作,键入相应的字符"&vbcrlf&""&vbcrlf&"1   添加一个禁止运行的程序"&vbcrlf&"2   恢复一个禁止运行的程序"&vbcrlf&"3   恢复所有禁止运行的程序"&vbcrlf&"4   查看已经添加的程序"&vbcrlf&"5   退出","选择操作")
通过inputbox函数将用户输入的字符赋值给变量choice  vbcrlf 是vbs中的换行符
相应的批处理语句为:
@echo off&(echo 1   添加一个禁止运行的程序)&(echo 2   恢复一个禁止运行的程序)&(echo 3   恢复所有禁止运行的程序)&(echo 4   查看已经添加的程序)&(echo 5   退出)
set /p choice=请根据不同的操作,键入相应的字符:

set wind9=createobject("scripting.filesystemobject")
定义对象 wind9 (filesystemobject)
If (wind9.fileexists("c:\windows\wind.txt")) Then
      else
如果不存在c:\windows\wind.txt
wind9.createtextfile "c:\windows\wind.txt",true
wind9.createtextfile 命令将新建它
true 新键的文件可以被之后的同名文件覆盖
set wind0=wind9.opentextfile("c:\windows\wind.txt",8)
指定操作对象为c:\windows\wind.txt
8  在文件的末尾(写入)模式
wind0.writeline " "
向文件中写入一个空格
wind0.close
关闭(或者说取消)指定的对象
     end if
if then else end if 为一个整体
相应的批处理语句为:
if not exist c:\windows\wind.txt echo.>c:\windows\wind.txt

set wind=createobject("wscript.shell")
定义对象wind    wscript.shell
     if choice="1" then
如果变量choice的值是1
wind1=inputbox("请键入程序名 (不需要路径)"&vbcrlf&""&vbcrlf&"按确定后,该程序将不能运行","指定程序名")
通过inputbox函数将用户输入的字符赋值给变量wind1
wind.run "reg add "&"""HKLM\software\microsoft\Windows nt\currentVersion\image file execution Options\"&wind1&""""&" /v debugger"&" /t reg_sz"&" /d """&wind1&""""&" /f",0
vbs运行reg add命令
格式为: reg add "注册表路径" /v 键名 /t 键值类型 /d 具体键值   (/f 强制执行)
另外,vbs中,对注册表进行读写操作也有相应命令,不过感觉这样方便一点

相应批处理语句:
reg add "hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\%wind1%" /v debugger /t reg_sz /d %wind1% /f
set wind7=wind9.opentextfile("c:\windows\wind.txt",8)
指定操作对象为c:\windows\wind.txt
8 在文件的末尾(写入)模式
wind7.writeline wind1
将变量wind1写入txt中
wind7.close
msgbox "添加成功   ",64,"清风"
提示信息
相应批处理语句:
echo %wind1%>>c:\windows\wind.txt
echo 添加成功
     elseif choice="2" then
wind1=inputbox("请键入程序名 (不需要路径)"&vbcrlf&""&vbcrlf&"按确定后,该程序将可以运行","指定程序名")
set wind3=wind9.opentextfile("c:\windows\wind.txt",1)
指定操作对象为c:\windows\wind.txt
1 只读模式
w=wind3.readall
读取txt的全部,将结果赋值给变量w
wind3.close
if instr(w, wind1) Then
在变量w(readall) 中查找 变量wind1  如果找到
wind.run "reg delete "&"""hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\"&wind1&""""&" /f",0
运行reg delete 命令
msgbox "已恢复!!   ",64,"清风"
提示信息
else
否则
msgbox "指定的程序并未添加!   ",16,"错误"
提示错误
end if
相应批处理语句:
find "%wind1%" c:\windows\wind.txt && (reg delete "hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\%wind1%"  /f)
     elseif choice="3" then
set wind1=wind9.opentextfile("c:\windows\wind.txt",1)  
do until wind1.atendofstream  
do loop 循环
相当于批处理的for /f
w=wind1.readline  
wind.run "reg delete "&"""hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\"&w&""""&" /f",vbhide
loop
wind1.close
wind9.deletefile "c:\windows\wind.txt"
删除文本
msgbox "操作成功   ",64,"清风"

相应批处理语句为:
for /f %%a in (c:\windows\wind.txt) do (reg delete "hklm\software\microsoft\Windows nt\currentVersion\image file execution Options\%%a"  /f)
    elseif choice="4" then
set wind1=wind9.opentextfile("c:\windows\wind.txt",1)
w=wind1.readall
读取文本的全部 ,赋值给变量w
wind1.close
msgbox w,48,"查看所有                    "
提示信息(w的值)
相应批处理语句:
type c:\windows\wind.txt
       else
wscript.quit
退出
相应批处理语句:
exit
      end if