个怎样在我的电脑里隐藏驱动器的例子。希望对一些人有用。
使用下面的程序后请重新启动计算机。
"NoDrives"是二进制值,也可以是十进制值。
一个驱动器的值是前面驱动器的值的两倍:A = 1 , B = 2 , C = 4 , D = 8 , E = 16 ......依次类推。
例如:如果想隐藏盘符C和盘符E,就要将 4 和 16 相加,结果是 4 + 16 = 20 ,然后调用 HideDriver(20);
uses Registry;
procedure HideDriver(HideNumber: integer);
var Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
with Reg do
begin
RootKey := HKEY_CURRENT_USER;
OpenKey('Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
WriteInteger('NoDrives', HideNumber);
CloseKey;
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
WriteInteger('NoDrives', HideNumber);
CloseKey;
end;
finally
Reg.Free;
end;
end;
增加下列代码在一个 Button 的 OnClick 事件中,可以让我的电脑里隐藏的驱动器重新显示,但必须重新启动计算机。
var Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
with Reg do
begin
RootKey := HKEY_CURRENT_USER;
OpenKey('Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
DeleteValue('NoDrives');
CloseKey;
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software/Microsoft/Windows/CurrentVersion/Policies/Explorer', True);
DeleteValue('NoDrives');
CloseKey;
end;
finally
Reg.Free;
end;
end;