取Run下所有值(原创)
下面,图老师小编带您去了解一下取Run下所有值(原创),生活就是不断的发现新事物,get新技能~
var
num1,num2:integer;
reg:Tregistry;
nums1:Tstringlist;
nums2:Tstringlist;
I:integer;
begin
list.Clear;
nums1:=Tstringlist.Create;
nums2:=Tstringlist.Create;
reg:=Tregistry.create;
reg.Rootkey:=HKEY_LOCAL_MACHINE;
If reg.OpenKey('SOFTWAREMicrosoftWindowsCurrentVersionRun',false) then
begin
reg.GetValueNames(nums1);
num1:=nums1.Count;
end;
For i:=0 To nums1.Count-1 Do
begin
with list.Items.Add do
begin
caption := nums1[i];
subitems.Add(reg.ReadString(nums1.Strings[i]));
end;
end;
reg.RootKey:=HKEY_CURRENT_USER;
If reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRun',false) Then
begin
reg.GetValueNames(nums2);
num2:=nums2.Count;
end;
For i:=0 To nums2.count-1 Do
begin
with list.Items.Add do
begin
caption := nums2[i];
subitems.Add(reg.ReadString(nums2.Strings[i]));
end;
end;
reg.CloseKey;
reg.Free;
end;
//删除所选的项目
procedure TForm1.FlatButton10Click(Sender: TObject);
begin
if Assigned(List.selected) then
begin
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_CURRENT_USER;
Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRun',False);
Reg.deleteValue(list.Selected.Caption);
Reg.CloseKey;
Reg.Free;
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRun',False);
Reg.deleteValue(list.Selected.Caption);
Reg.CloseKey;
Reg.Free;
list.DeleteSelected;
end
else
showmessage('请选择您要删除的项目名称!');
end;
//修改
procedure TForm5.FlatButton2Click(Sender: TObject);
var
Reg:Tregistry;
begin
if not (edit1.Text='')then //检查项目名称不为空
if not (edit2.Text='') then//检查项目路径不为空
//如果两者完全不为空,则执行以下代码!
begin
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey('SoftwareMicrosoftwindowsCuRRentVersionRun',False);
Reg.WriteString(Edit1.Text,Edit2.text);
Reg.CloseKey;
Reg.Free;
StatusBar1.Panels[0].Text:='网吧助手提醒您:修改启动项目成功!';
end;
if (edit1.Text='')then //检查项目名称是空
begin
StatusBar1.Panels[0].Text:='网吧助手提醒您:项目名称不能为空!';
end;
if (edit2.Text='') then //检查项目路径是空
begin
StatusBar1.Panels[0].Text:='网吧助手提醒您:项目路径不能为空!';
end;
if (edit1.Text='')then //检查项目名称是空
if (edit2.Text='') then //检查项目路径是空
begin
StatusBar1.Panels[0].Text:='网吧助手提醒您:项目名称和路径都不能为空!';
end
end;
procedure TForm5.FlatButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
edit2.text:=OpenDialog1.FileName;
if not (edit2.Text='') then
//如果edit2.text不为空的话,则返回Edit2.text的内容到StatusBar里
begin
StatusBar1.Panels[0].Text:='路径 → '+edit2.text;
end;
end;
procedure TForm5.FlatButton3Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
StatusBar1.Panels[0].Text:='网吧助手提醒您:请执行操作!';
end;
end.
//添加
//把文件读取到Edit2.text中
procedure TForm3.FlatButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
edit2.text:=OpenDialog1.FileName;
if not (edit2.Text='') then
//如果edit2.text不为空的话,则返回Edit2.text的内容到StatusBar里
begin
StatusBar1.Panels[0].Text:='路径 → '+edit2.text;
end;
end;
//重置,将edit1,edit2,StatusBar初始化
procedure TForm3.FlatButton3Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
StatusBar1.Panels[0].Text:='网吧助手提醒您:请执行操作!';
end;
//启动时清空edit1,edit2的内容
procedure TForm3.FormCreate(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
StatusBar1.Panels[0].Text:='网吧助手提醒您:请执行操作!';
end;
//写入内容到注册表Run里
procedure TForm3.FlatButton2Click(Sender: TObject);
var
Reg:Tregistry;
begin
if not (edit1.Text='')then //检查项目名称不为空
if not (edit2.Text='') then//检查项目路径不为空
//如果两者完全不为空,则执行以下代码!
begin
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey('SoftwareMicrosoftwindowsCuRRentVersionRun',False);
Reg.WriteString(Edit1.Text,Edit2.text);
Reg.CloseKey;
Reg.Free;
StatusBar1.Panels[0].Text:='网吧助手提醒您:添加启动项目成功!';
end;
if (edit1.Text='')then //检查项目名称是空
begin
StatusBar1.Panels[0].Text:='网吧助手提醒您:项目名称不能为空!';
end;
if (edit2.Text='') then //检查项目路径是空
begin
StatusBar1.Panels[0].Text:='网吧助手提醒您:项目路径不能为空!';
end;
if (edit1.Text='')then //检查项目名称是空
if (edit2.Text='') then //检查项目路径是空
begin
StatusBar1.Panels[0].Text:='网吧助手提醒您:项目名称和路径都不能为空!';
end
end;
end.
发布人:Jony 分类: 编程相关 发布时间: 2005-6-21
你这个咋就这么长?我也把我以前写的枚举RUN键的代码贴出来玩玩~~
bool CSystemDlg::RegRun()
{
HKEY hKey;
char Value[1024];
DWORD szSize;
LPTSTR RegKey ="SOFTWAREMicrosoftWindowsCurrentVersionRun";
TCHAR EnvironVariable[1024];
DWORD dwIndex=0;
DWORD dwVariableLength;
DWORD dwReturn;
DWORD Return;
CString id="";
CString name="";
CString path="";
dwReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE,RegKey,0,KEY_QUERY_VALUE,&hKey);
if(dwReturn != ERROR_SUCCESS)
{
return FALSE;
}
for(dwIndex=0;;dwIndex++)
{
dwVariableLength = 1024;
Return=RegEnumValue(hKey,dwIndex,EnvironVariable,&dwVariableLength,NULL,NULL,NULL,NULL);
szSize = sizeof(Value);
RegQueryValueEx(hKey,EnvironVariable,NULL,NULL,(LPBYTE)Value,&szSize);
path.Format("%s",Value);
if(Return == ERROR_NO_MORE_ITEMS)
{
break;
}
id.Format("%d",dwIndex);
m_reglist.InsertItem(dwIndex, id ,NULL);
name.Format("%s",EnvironVariable);
m_reglist.SetItemText(dwIndex,1,name);
m_reglist.SetItemText(dwIndex,2,path);
}
RegCloseKey(hKey);
return TRUE;
}
void CSystemDlg::OnButton4()
{
HKEY key;
CString R_name;
DWORD dwReturn;
R_name=m_reglist.GetItemText(m_reglist.GetNextItem(-1,LVNI_FOCUSED|LVNI_SELECTED),1);
if(RegOpenKey(HKEY_LOCAL_MACHINE,"SoftwareMicrosoftWindowsCurrentVersionRun",&key)==ERROR_SUCCESS)
{
dwReturn=RegDeleteValue(key,R_name);
}
if(dwReturn==ERROR_SUCCESS)
{
MessageBox("删除成功!","提醒",MB_ICONWARNING);
m_reglist.DeleteItem(m_reglist.GetNextItem(-1,LVNI_FOCUSED|LVNI_SELECTED));
}
else
{
MessageBox("删除失败!","提醒",MB_ICONSTOP);
}
RegCloseKey(key);