CSDN博客

img online

如何隐藏我的电脑中的磁盘

发表于2004/7/17 17:55:00  2729人阅读

分类: visualbasic

用过超级兔子的都知道,有一个隐藏磁盘

的功能,选择隐藏的磁盘,确定后,

重新启动,看到磁盘隐藏了

主要是通过操作注册表来实现这个功能的

 

打开注册表

打开HKEY_CURRENT_USER/Software

/Microsoft/Windows/CurrentVersion

/Policies/Explorer分支

在这个分支下,NoDrives键值可以进行设置。

磁盘驱动器一一对应的键值如下:

A:0x00000001,B:0x00000002,

C:0x00000004,D:0x00000008,

E:0x00000010,F:0x00000020.

即按磁盘驱动器的英文字母顺序(A~Z)从十六进制的二倍数递增.将你要隐藏的磁盘驱动器所对应的键值按十六进制相加赋值给”NoDrivers”,如果要隐藏A,C,D,则将0x0000000D赋值给”NoDrives”

 

代码如下:WinXP+VB+SP6

winxp下注销重新登陆即可看到

添加list控件,command控件

Option Explicit

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

Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long

Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Private 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

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

 

Const HKEY_CLASSES_ROOT = &H80000000

Const HKEY_CURRENT_USER = &H80000001

Const HKEY_LOCAL_MACHINE = &H80000002

 

Private Sub Command3_Click()

Dim i As Integer

Dim KeyValue As Long

Dim hCurKey As Long

Dim lRegResult As Long

Dim KeyID As Long

Dim subKey As String

Dim regkey As String

Dim retvalue As Long

 

For i = 0 To List1.ListCount - 1

If List1.Selected(i) Then

    MsgBox List1.List(i)

    KeyValue = KeyValue + List1.ItemData(i)

End If

Next

'如果没有选择,删除NoDrivers键值,取消所有磁盘的隐藏

regkey = "Software/Microsoft/Windows/CurrentVersion/Policies/Explorer"

subKey = "NoDrives"

   

If KeyValue = 0 Then

    lRegResult = RegOpenKey(HKEY_CURRENT_USER, regkey, hCurKey)

    lRegResult = RegDeleteValue(hCurKey, subKey)

    lRegResult = RegCloseKey(hCurKey)

Else

'根据选择的磁盘进行隐藏

    retvalue = RegCreateKey(HKEY_CURRENT_USER, regkey, KeyID)

    subKey = "NoDrives"

    'KeyValue = a1

    retvalue = RegSetValueEx(KeyID, subKey, 0&, 4, KeyValue, 4)

End If

 

End Sub

 

Private Sub Command4_Click()

Unload Me

End Sub

 

Private Sub Form_Load()

List1.AddItem "A:"

List1.ItemData(0) = 1

List1.AddItem "B:"

List1.ItemData(1) = 2

List1.AddItem "C:"

List1.ItemData(2) = 4

List1.AddItem "D:"

List1.ItemData(3) = 8

List1.AddItem "E:"

List1.ItemData(4) = 16

List1.AddItem "F:"

List1.ItemData(5) = 32

List1.AddItem "G:"

List1.ItemData(6) = 64

List1.AddItem "H:"

List1.ItemData(7) = 128

List1.AddItem "I:"

List1.ItemData(8) = 256

List1.AddItem "J:"

List1.ItemData(9) = 512

List1.AddItem "K:"

List1.ItemData(10) = 1024

List1.AddItem "L:"

List1.ItemData(11) = 2048

List1.AddItem "M:"

List1.ItemData(12) = 4096

List1.AddItem "N:"

List1.ItemData(13) = 8192

List1.AddItem "O:"

List1.ItemData(14) = 16384

List1.AddItem "P:"

List1.ItemData(15) = 32768

List1.AddItem "Q:"

List1.ItemData(16) = 65536

List1.AddItem "R:"

List1.ItemData(17) = 131072

List1.AddItem "S:"

List1.ItemData(18) = 262144

List1.AddItem "T:"

List1.ItemData(19) = 524288

List1.AddItem "U:"

List1.ItemData(20) = 1048576

List1.AddItem "V:"

List1.ItemData(21) = 2097152

List1.AddItem "W:"

List1.ItemData(22) = 4194304

List1.AddItem "X:"

List1.ItemData(23) = 8388608

List1.AddItem "Y:"

List1.ItemData(24) = 16777216

List1.AddItem "Z:"

List1.ItemData(25) = 33554432

End Sub

0 0

相关博文

我的热门文章

img
取 消
img