惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - Findekano

C#异步调用的bug? 恩,VS调试时候的监视也不能够尽信啊 最近正在看的几本书 VS.NET2005使用体验(二) [C# FAQ]通过Windows Forms预处理Win32消息 VS.NET2005使用体验(一) OpenGL & MFC 相关联接 .::Findekano's Tidbet:: .::Findekano's Tidbet:: .::Findekano's Tidbet:: .:: Findekano's Tidbet :: CorelDraw's Application Recovery Manager.. .:: Findekano's Tidbet :: C#&.NET Framework中的Beep .:: Findekano's Tidbet :: [C# FAQ]C#代码中如何启动另一个应用程序或批处理程序? 今天开始,努力攒钱... 又闻到味道 如何保持代码格式?
将应用程序直接加入到"Run..."中打开的小工具
Findekano · 2004-11-07 · via 博客园 - Findekano

      一直以来很习惯用Win+R打开"Run..."对话框,然后输入命令来打开要使用的程序,如winword,如wmplayer....
然而很多程序安装好之后并不能在Run...中简单输入程序名来打开,于是原来一直手动编辑注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
将新安装的项添加进去。近日重装了系统,原来加好的列表全没了-_-||,一个一个的重新手动加又嫌麻烦,所以干脆写个小工具,能够把选定的可执行文件快速加入到app Paths列表中。
     要做的很简单。首先修改注册表,在HKEY_CLASSES_ROOT\exefile\shell下加一个新项"Add2Cmd",默认值为“加入到命令列表...",在其下再创建一个名为"command"的项,其默认值为"C:\Document\Visual Studio Projects\Add2Cmd\Add2Cmd\bin\Debug\Add2Cmd.exe" "%1",其中C:\Document\Visual Studio Projects\Add2Cmd\Add2Cmd\bin\Debug\Add2Cmd.exe是我写的程序的地址。%1作为参数即为被选定的可执行文件的绝对路径和文件名。
    执行Add2Cmd.exe的时候将被选定的可执行文件的绝对路径和文件名记入HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths即可。
代码如下所示:

static void Main(string[] args) 
        
{
            
using (RegistryKey
                       Software 
= Registry.ClassesRoot.OpenSubKey(@"exefile\shell",true),
                       shell 
= Software.CreateSubKey("add2cmd"),
                       command 
= shell.CreateSubKey("command"))
            
{
                shell.SetValue(
"""添加到命令列表");    // 修改(默认)项的值
                command.SetValue("""\"" + Application.ExecutablePath + "\" \"%1\"");    // 修改路径
            }


            
if( args.Length > 1 )
                MessageBox.Show(
"参数过多,程序没有正常执行。","错误",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
            
else if( args.Length == 1 )
            
{
                
string appPathName = args[0];
                
int index = appPathName.LastIndexOf("\\");
                
string appName = appPathName.Substring(index+1);
                
string appPath = appPathName.Substring(0,index);

                
using (RegistryKey
                           Software 
= Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths",true),
                           newCmd 
= Software.CreateSubKey(appName))
                
{
                    newCmd.SetValue(
"Path", appPath);    // 修改路径
                    newCmd.SetValue("", appPathName);    // 修改(默认)项的值
                }


                MessageBox.Show(
"成功加入到命令列表,可以在Start->Run中输入"+appName+"运行该程序了。","成功",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information);
            }

        }