当前位置: 源码素材网 » Delphi教程 » 详情页

如何隐藏系统盘符呢?delphi方法 +演示代码

  •   时间:2019-07-10
  • 概述:盘符 隐藏

Delphi通过实例代码演示,如何隐藏Windows盘符,适合初学者学习Delphi的一段初级代码:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Registry, StdCtrls, Buttons;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    GroupBox1: TGroupBox;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    ListBox1: TListBox;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  MyReg : TRegistry;
  Buf:array [1..4] of byte;
  Str : String;
begin
  Try
  if Application.MessageBox(PAnsichar('确定要'+ListBox1.Items[ListBox1.itemIndex]+'吗?'),'提示',MB_YESNO) = ID_YES then
  begin
    MyReg := TRegistry.Create;
    MyReg.RootKey := HKEY_CURRENT_USER;
    if MyReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',True) then
    begin
      if ListBox1.itemIndex=0 then
      begin
        Buf[1]:=01;
        Buf[2]:=00;
        Buf[3]:=00;
        Buf[4]:=00;
        MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));//隐藏A盘
      end
      else if ListBox1.itemIndex=1 then
      begin
        Buf[1]:=02;
        Buf[2]:=00;
        Buf[3]:=00;
        Buf[4]:=00;
        MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));//隐藏B盘
      end
      else if ListBox1.itemIndex=2 then
      begin
        Buf[1]:=04;
        Buf[2]:=00;
        Buf[3]:=00;
        Buf[4]:=00;
        MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));//隐藏C盘
      end
      else if ListBox1.itemIndex=3 then
      begin
        Buf[1]:=08;
        Buf[2]:=00;
        Buf[3]:=00;
        Buf[4]:=00;
        MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));//隐藏D盘
      end
      else if ListBox1.itemIndex=4 then
      begin
        Buf[1]:=10;
        Buf[2]:=00;
        Buf[3]:=00;
        Buf[4]:=00;
        MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));//隐藏E盘
      end
      else if ListBox1.itemIndex=5 then
      begin
        Buf[1]:=20;
        Buf[2]:=00;
        Buf[3]:=00;
        Buf[4]:=00;
        MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));//隐藏F盘
      end;
      Application.MessageBox('修改成功!','提示',64);
    end;
  end;
  Except
    Application.MessageBox('修改失败!','提示',64);
  end;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
  MyReg : TRegistry;
  Buf:array [1..4] of byte;
begin
  Try
  if Application.MessageBox('确定要显示被隐藏的盘符吗?','提示',MB_YESNO) = ID_YES then
  Buf[1] := 00;
  Buf[2] := 00;
  Buf[3] := 00;
  Buf[4] := 00;
  MyReg := TRegistry.Create;
  MyReg.RootKey := HKEY_CURRENT_USER;
  if MyReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',True) then
  begin
    MyReg.WriteBinaryData('NoDrives',Buf,Sizeof(Buf));
    Application.MessageBox('修改成功,注销计算机即可显示被隐藏的盘符','提示',64);
  end;
  Except
    Application.MessageBox('修改失败!','提示',64);
  end;
end;
end.

    相关声明:

      若“如何隐藏系统盘符呢?delphi方法 +演示代码”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。