用一个CheckListBox----CheckListBoxDriver来显示所有分区。
1、读值并显示:
r->RootKey=HKEY_CURRENT_USER;
if(r->OpenKey("SoftWare//Microsoft//Windows//CurrentVersion//Policies//Explorer",true))
{
//取消光盘的自动运行功能
int num=0x95;
if(!r->ValueExists("NoDriveTypeAutoRun"))
r->WriteBinaryData("NoDriveTypeAutoRun",&num,4);
r->ReadBinaryData("NoDriveTypeAutoRun",&num,4);
switch(num)
{
case 0xb5:CheckBoxCDROM->Checked=true;
break;
case 0x95:CheckBoxCDROM->Checked=false;
break;
}
// 隐藏桌面上所有图标;
if(!r->ValueExists("NoDesktop"))
r->WriteBool("NoDesktop",false);
CheckBoxDesktop->Checked=r->ReadBool("NoDesktop");
//禁用任务栏
if(!r->ValueExists("NoSetTaskbar"))
r->WriteBool("NoSetTaskbar",false);
CheckBoxTask->Checked=r->ReadBool("NoSetTaskbar");
//禁用控制面板和打印机
if(!r->ValueExists("NoSetFolders"))
r->WriteBool("NoSetFolders",false);
CheckBoxControl->Checked=r->ReadBool("NoSetFolders");
//禁用收藏夹
if(!r->ValueExists("NoFavoritesMenu"))
r->WriteBool("NoFavoritesMenu",false);
CheckBoxFavorites->Checked=r->ReadBool("NoFavoritesMenu");
//隐藏驱动器
DWORD Drive=GetLogicalDrives();
int number=0;
char sum,driver='A';
for(int i=0;i<32;i++)
{
if((Drive>>i)&0x00000001)
{
sum=driver+i;
CheckListBoxDriver->Items->Add(sum);
number++;
}
}
if(!r->ValueExists("NoDrives"))
r->WriteInteger ("NoDrives",0x0);
DWORD disk=r->ReadInteger ("NoDrives");
for(int right=0;right<32;right++)
{
if((disk>>right)&0x1)
{
sum=driver+right;
for(int k=0;k<CheckListBoxDriver->Items->Count;k++)
{
if(sum==CheckListBoxDriver->Items->Strings[k])
CheckListBoxDriver->Checked[k]=true;
}
}
}
r->CloseKey ();
}
2、写入修改并设置重新启动标志为True
if(r->OpenKey("SoftWare//Microsoft//Windows//CurrentVersion//Policies//Explorer",false))
{
//取消光盘的自动运行功能
int num1=0x95;
int num2=0xb5;
int num3;//可以设为其他值,让硬盘,软盘都支持自动运行。
r->ReadBinaryData( "NoDriveTypeAutoRun",&num3,4);
if(CheckBoxCDROM->Checked==true)
{ if(num3!=num2)
{
r->WriteBinaryData("NoDriveTypeAutoRun",&num2,4);
Restart=true; //************************
}
}
else
{
if(num3!=num1)
{
r->WriteBinaryData("NoDriveTypeAutoRun",&num1,4);
Restart=true; //*************************
}
}
// 隐藏桌面上所有图标;
bool i=r->ReadBool("NoDesktop");
if(i!=CheckBoxDesktop->Checked)
{
r->WriteBool ("NoDesktop",CheckBoxDesktop->Checked);
Restart=true; //******************************
}
//禁用任务栏
i=r->ReadBool("NoSetTaskbar");
if(i!=CheckBoxTask->Checked)
{
r->WriteBool ("NoSetTaskbar",CheckBoxTask->Checked);
Restart=true;
}
//禁用控制面板和打印机
i=r->ReadBool("NoSetFolders");
if(i!=CheckBoxControl->Checked)
{
r->WriteBool ("NoSetFolders",CheckBoxControl->Checked);
Restart=true;
}
//禁用收藏夹
i=r->ReadBool("NoFavoritesMenu");
if(i!=CheckBoxFavorites->Checked)
{
r->WriteBool ("NoFavoritesMenu",CheckBoxFavorites->Checked);
Restart=true;
}
//隐藏驱动器
DWORD disks=0;
char driver='A';
for(int Number=0;Number<CheckListBoxDriver->Items->Count ;Number++)
{
if(CheckListBoxDriver->Checked[Number])
{
AnsiString s=CheckListBoxDriver->Items->Strings[Number];
char *ss=s.c_str();
DWORD k=1;
k=k<<(int)(ss[0]-driver);
disks=disks+k;
}
}
DWORD value=r->ReadInteger("NoDrives");
if(value!=disks)
{
r->WriteInteger("NoDrives",disks);
Restart=true; //重启标志
}
r->CloseKey ();
}
3、重启
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
DWORD temp;
if(Restart)
{
if(MessageDlg("所做的改动只有在重新启动计算机后才能/n生效,是否现在启动计算机?",
mtConfirmation,TMsgDlgButtons()<<mbYes<<mbNo,0)==mrYes)
ExitWindowsEx(EWX_REBOOT,temp);
}
Action=caFree;
}
这是以前我用C++ Builder做的小玩意的一部分,很容易换成DELPHI代码,时间久了,幸好没有删掉。