delphi 隐藏盘符

 {
 0000000为不隐藏或禁止所以驱动器,FFFFFFFF相反。

00000001-A
00000002-B
00000004-C
00000008-D
00000010-E
00000020-F
00000040-G
00000080-H
00000100-I
00000200-J
00000400-K
00000800-L
00001000-M
00002000-N
00004000-O
00008000-P
例子:
隐藏D盘\禁止D盘:
NoDrives=00000008
NoViewOnDrive=00000008

如果要隐藏几个盘,只要把相应盘符的值相加就行,是逢16进1。
例子:
隐藏D盘、E盘,禁止E盘、F盘
NoDrives=00000018
NoViewOnDrive=00000030
 }
 procedure NoDriver(HideNumber: integer);
 var
  Reg2: TRegistry;
 begin
  Reg2 := TRegistry.Create;
  try
   with Reg2 do
   begin
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True);
    WriteInteger('NoDrives', HideNumber);
    WriteInteger('NoViewOnDrive', HideNumber);
    CloseKey;

//    RootKey := HKEY_LOCAL_MACHINE;
//    OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True);
//    WriteInteger('NoDrives', HideNumber);
//    WriteInteger('NoViewOnDrive', HideNumber);
//    CloseKey;
   end;
  finally
   Reg2.Free;
  end;
  sendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0); //发送安装信息广播
 end;

 

posted @ 2024-08-10 08:37  Tag  阅读(9)  评论(0编辑  收藏  举报