欢迎大家访问我的网站!

VB调用API实现光驱,USB的禁用

思博2020-12-03 13:21:50474编程开发

'wshshell.shell是一个注册表修改对象,有三个方法regwrite,regread,regdelete

'Set WshShell = CreateObject("WScript.Shell")

'WshShell.RegWrite "HKEY_CURRENT_USER\Software\zxlxxl\aa", "某些字符串值"

'WshShell.RegWrite "HKEY_CURRENT_USER\Software\zxlxxl\a1", 1, "REG_DWORD"

'wshshell.regdelete "HKEY_CURRENT_USER\Software\zxlxxl\"

Private Sub conCdRom(b As Boolean)

Set WshShell = CreateObject("WScript.Shell")

If b Then

'启用光bai驱

WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom\Start", 1, "REG_DWORD"

Else

'禁用光驱

WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom\Start", 4, "REG_DWORD"

End If

msgbxo "本次操作重启生效"

End Sub

Private Sub conUSB(b As Boolean)

Set WshShell = CreateObject("WScript.Shell")

If b Then

'启用USB

WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start", 3, "REG_DWORD"

Else

'禁用USB

WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start", 4, "REG_DWORD"

End If

MsgBox "本次操作重启生效"

End Sub

Private Sub Command1_Click()

conCdRom True

End Sub

Private Sub Command2_Click()

conCdRom False

End Sub

Private Sub Command3_Click()

conUSB True

End Sub

Private Sub Command4_Click()

conUSB False

End Sub

Private Sub Form_Load()

Command1.Caption = "启用光驱"

Command2.Caption = "禁用光驱"

Command3.Caption = "启用USB"

Command4.Caption = "启用USB"

End Sub


转载声明:本站发布文章及版权归原作者所有,转载本站文章请注明文章来源!

本文链接:http://lxkj.vip/?id=26

网友评论