我想获得一份当前机器所有自启动程序的列表,希望可以和"msconfig"执行的System Configuration Utility中的Startup一致。我现在遇到几个问题:
1. 我得到开始菜单中对应的路径的启动目录,里面是后缀为.lnk的快捷方式,我如何通过快捷方式得到该文件的属性信息
2. 在开始菜单对应的路径下(Documents and Settings),有“All Users.WINDOWS”和“All Users”路径,我应该取哪个,两个区别是什么?如何去区分
3. 从注册表Run下面读取的自启动信息,软件的Name如何得到,得到的是哪个内容?希望能得到解决方法或是一些想法。提供解决方法后,在开贴散分(可用分多)。
1. 我得到开始菜单中对应的路径的启动目录,里面是后缀为.lnk的快捷方式,我如何通过快捷方式得到该文件的属性信息
2. 在开始菜单对应的路径下(Documents and Settings),有“All Users.WINDOWS”和“All Users”路径,我应该取哪个,两个区别是什么?如何去区分
3. 从注册表Run下面读取的自启动信息,软件的Name如何得到,得到的是哪个内容?希望能得到解决方法或是一些想法。提供解决方法后,在开贴散分(可用分多)。
RegistryKey vRegistryKey = Registry.CurrentUser.OpenSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Run");
string[] ValueNames = vRegistryKey.GetValueNames();
foreach (string vValueName in ValueNames)
{
richTextBox1.AppendText(string.Format("{0}={1}\r\n",
vValueName, vRegistryKey.GetValue(vValueName)));
}
vRegistryKey = Registry.LocalMachine.OpenSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Run");
ValueNames = vRegistryKey.GetValueNames();
foreach (string vValueName in ValueNames)
{
richTextBox1.AppendText(string.Format("{0}={1}\r\n",
vValueName, vRegistryKey.GetValue(vValueName)));
}
WshShell vWshShell = new WshShell();
string[] vFiles = Directory.GetFiles(
Environment.GetFolderPath(Environment.SpecialFolder.Startup));
foreach (string vFile in vFiles)
{ if (Path.GetExtension(vFile).ToLower() == ".lnk")
{
IWshShortcut shortcut = (IWshShortcut)vWshShell.CreateShortcut(vFile);
richTextBox1.AppendText(Path.GetFileName(shortcut.FullName) + "=" +
shortcut.TargetPath + "\r\n");
}
}
using Microsoft.Win32;
RegistryKey hklm=Registry.LocalMachine;
RegistryKey software=hklm.OpenSubKey("SOFTWARE");
RegistryKey microsoft=software.OpenSubKey("Microsoft");
RegistryKey win=microsoft.OpenSubKey("Windows");
RegistryKey cur=win.OpenSubKey("CurrentVersion");
RegistryKey run=cur.OpenSubKey("Run");
string[] a;
//获得名称存入数组
a=run.GetValueNames();
try
{
string[] s=new string[2];
ListViewItem b=new ListViewItem();
for(int i=0;i<run.ValueCount;i++)
{
s[0]=a[i];
s[1]=run.GetValue(s[0]).ToString();
b=new ListViewItem(s);
this.listView1.Items.Add(b); //添加数据到listview }
hklm.Close();
}