delphi 隱藏磁碟機代號

Tag發表於2024-08-10
 {
 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;

相關文章