C++利用注册表添加桌面右键新建菜单

对于程序员来说,新建一个cpp文件是再频繁不过的事情了。

为了方便,我们习惯在桌面右键新建文件,而不是新建一个文本文档,然后修改后缀名。

百度谷歌查询了一下,终于知道如何添加注册表。

手痒,抽出时间用cpp写了一个程序,方便以后操作。

客户需求是永远无法满足的,经同学测试,陆续写了三个版本。

接下来直接贴代码~

第一个版本,只能添加c、cpp、java三种后缀。

 1 /*
 2  * Author: Haipz
 3  * School: HDU
 4  * File Name: registry1.0.cpp
 5  */
 6 #include <cstdio>
 7 #include <cmath>
 8 #include <ctime>
 9 #include <cctype>
10 #include <cstring>
11 #include <cstdlib>
12 #include <climits>
13 #include <cfloat>
14 #include <iostream>
15 #include <vector>
16 #include <stack>
17 #include <queue>
18 #include <set>
19 #include <map>
20 #include <algorithm>
21 using namespace std;
22
23 char s[1024], buffer[128], result[1024*4];
24
25 void work_1() {
26     system("reg add \"HKEY_CLASSES_ROOT\\.c\\ShellNew\" /v \"NullFile\" /t REG_SZ");
27 }
28
29 void work_2() {
30     system("reg add \"HKEY_CLASSES_ROOT\\.cpp\\ShellNew\" /v \"NullFile\" /t REG_SZ");
31 }
32
33 void work_3() {
34     system("reg add \"HKEY_CLASSES_ROOT\\.java\\ShellNew\" /v \"NullFile\" /t REG_SZ");
35 }
36
37 int main() {
38     printf("Add registry for C, C++ and Java\n");
39     printf("Author: Haipz\nSchool: HDU\n");
40     printf("1 for C;\n2 for C++;\n3 for Java.\n");
41     printf("Example: 12 to add C and C++.\n");
42     printf("Please make choice(s): ");
43     gets(s);
44     for (int i = 0; s[i] != ‘\0‘; ++i) {
45         printf("Working...\n");
46         if (s[i] == ‘1‘) work_1();
47         else if (s[i] == ‘2‘) work_2();
48         else if (s[i] == ‘3‘) work_3();
49         else printf("%c is a wrong enter!\n", s[i]);
50     }
51     system("pause");
52     return 0;
53 }

第二个版本,精简了代码,支持添加用户输入的后缀。

 1 /*
 2  * Author: Haipz
 3  * School: HDU
 4  * File Name: registry2.0.cpp
 5  */
 6 #include <cstdio>
 7 #include <cmath>
 8 #include <ctime>
 9 #include <cctype>
10 #include <cstring>
11 #include <cstdlib>
12 #include <climits>
13 #include <cfloat>
14 #include <iostream>
15 #include <vector>
16 #include <stack>
17 #include <queue>
18 #include <set>
19 #include <map>
20 #include <algorithm>
21 using namespace std;
22
23 char a[1024];
24 char b[1024] = "reg add \"HKEY_CLASSES_ROOT\\.";
25 char c[1024] = "\\ShellNew\" /v \"NullFile\" /t REG_SZ";
26
27 void work(char* a) {
28     strcat(b, a);
29     strcat(b, c);
30     system(b);
31 }
32
33 int main() {
34     printf("Function: Add registry to build a new file simply!\n");
35     printf("Author: Haipz\nSchool: HDU\n");
36     printf("Example: Enter c to add C and enter cpp to add C++.\n");
37     printf("Your opion: ");
38     gets(a);
39     work(a);
40     system("pause");
41     return 0;
42 }

第三个版本,支持多次添加,并允许删除已添加的注册表。

 1 /*
 2  * Author: Haipz
 3  * School: HDU
 4  * File Name: registry2.0.cpp
 5  */
 6 #include <cstdio>
 7 #include <cmath>
 8 #include <ctime>
 9 #include <cctype>
10 #include <cstring>
11 #include <cstdlib>
12 #include <climits>
13 #include <cfloat>
14 #include <iostream>
15 #include <vector>
16 #include <stack>
17 #include <queue>
18 #include <set>
19 #include <map>
20 #include <algorithm>
21 using namespace std;
22
23 char key[1024];
24 char a[1024];
25
26 void add(char* t) {
27     char b[1024] = "reg add \"HKEY_CLASSES_ROOT\\.";
28     char c[1024] = "\\ShellNew\" /v \"NullFile\" /t REG_SZ";
29     strcat(b, t);
30     strcat(b, c);
31     system(b);
32 }
33
34 void del(char* t) {
35     char d[1024] = "reg delete \"HKEY_CLASSES_ROOT\\.";
36     char e[1024] = "\\ShellNew\" /f";
37     strcat(d, t);
38     strcat(d, e);
39     system(d);
40 }
41
42 int main() {
43     printf("Function: Build a new file simply!\n");
44     printf("Author: Haipz\nSchool: HDU\n");
45     printf("Example: Enter \"c\" to add C and enter \"cpp\" to add C++;\n");
46     printf("         Enter \"-c\" to delete C.\n");
47     do {
48         printf("Your opion: ");
49         gets(a);
50         if (a[0] == ‘-‘) del(a + 1);
51         else add(a);
52         printf("Enter \"r\" to run again or any other key to quit: ");
53         gets(key);
54     } while (key[0] == ‘r‘);
55     return 0;
56 }

打包下载地址:

http://files.cnblogs.com/haipzm/Regedity.zip

注意,如果系统提示缺少某dll文件,请到网上下载,并复制到C:\Windows\System32目录下。

时间: 2024-08-05 15:20:56

C++利用注册表添加桌面右键新建菜单的相关文章

利用注册表添加系统右键菜单

最近,不知道是用了什么软件,在清理的时候把右键菜单里面的一些快捷操作都给清理掉了.因为一直在使用git bash命令行工具,要到具体目录操作的时候如果没有右键快捷打开的话,就得一直cd,cd(摩擦,摩擦)...到具体目录下,很痛苦的,所以就去google了下,然后利用修改注册表添加了系统的右键菜单. 注:其实win7以上系统按住shift键在右键就可以在相应目录打开cmd工具 添加空白处的右键菜单(添加 git bash为例) 1.win+r运行regedit(注册表编辑器). 2.找到HKEY

Win10系统桌面右键新建没有内容怎么恢复

Win10系统桌面右键新建没有内容怎么恢复 添加txt文本文档 运行->regedit,打开注册表编辑器 展开HKEY_CLASSES_ROOT 找到.txt 选中.txt,修改右侧窗格的"默认值"数据为txtfile 在.txt上右击,选"新建->项" ,命名为ShellNew,如果有就不用新建了 选中shellNew,然后"新建"->"字符串值",将其名称设置为nullfile,值留空即可 添加word.

利用注册表隐藏硬盘分区

你是否想要隐藏某个盘符,让人不为所知?不管出于什么初衷,我们都有理由去隐藏某个盘符,同时隐藏的盘符中的软件如果有快捷方式在桌面,是不影响运行的.出于安全考虑,该修改涉及注册表,修改前请备份注册表,以备下次还原操作.阅读下文了解Win7利用注册表隐藏硬盘分区的方法. 操作步骤: 1.打开注册表(开始-运行-regedit). 2.打开路径: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\

win8.1右键新建菜单添加新建php文件

最近在学习php没使用IDE,一直使用编辑器,但每次新建文件都要手动该扩展名比较麻烦.于是想着能不能在右键新建菜单直接新建php文件.于是开始百度... 步骤一:win+R打开运行(管理员身份运行) 步骤二:找到.php扩展名注册的项在HKEY_CLASSES_ROOT项下ctrl+F查找.php的项,这个时候这个项下一般是没有东西的. 1.右键添加新建项ShellNew 2.在刚添加的ShellNew上右键添加字符串值NullFile,默认为空就好. 3.如果你按照百度搜的也是我这么来的 那你

注册表添加多级菜单

案例:添加.EXE文件右键菜单父菜单项[DC编程助手],子菜单项[PEiD][OllyDbg] Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\exefile\shell\DC]"SubCommands"="PEiD;OllyDbg""MUIVerb"="DC编程助手""icon"="\"D:\\Program Files\

Office 2016 - 下载、安装、激活后,右键新建菜单中,出现 Micorosoft Excel 97-2003 工作表,而不是 Micorosoft Excel 工作表、以及对新建菜单项位置做调整

安装激活 Office 2016 后,新建菜单项如下: 首先,需要做的是把右键新建菜单项中的 Micorosoft Excel 09-2003 工作表去除(保存格式是 .xls),替换为 Micorosoft Excel 工作表(Excel 2016 的默认格式 .xlsx) 其次,对新建菜单项的排列顺序做调整,额,把 Micorosoft Excel 工作表 移至 Micorosoft Word 文档下面. 调整后样式:

Windows系统下增删右键新建菜单

绝大多数的Windows系统下右键新建菜单都有长长的一串子项,例如WinRAR和Office全家.PS等菜单.如果配置比较低或者正在运行高资源占用的程序时,右键划过新建项时系统会卡卡的严重的时候会卡死掉. 而有些时候我们又需要频繁的建立某类型的文件,如果可以从右键直接创建就会方便很多.特别是Windows现在重命名的方式把文件名和后缀分开编辑,要多点几下才能修改到后缀名. 删除多余的右键菜单 我们需要删除的是多余的右键菜单,而不是全部,那么首先要知道需要删除的文件格式是什么 在桌面右键新建出需要

利用注册表在右键添加VS15的快捷方式打开文件夹

1.简介 最近安装VS15 Preview 5,本版本可以打开"文件夹" 是否可以向Visual Studio Code一样在文件夹或文件右键菜单添加"Open with Code",答案是当然可以的. 2.打开文件 1.Win+R 打开运行,输入regedit,打开注册表,找到HKEY_CLASSES_ROOT\*\shell分支,如果没有shell分支,则在*下点击右键,选择"新建-项",建立shell分支. 2.在shell下新建"

注册表添加和删除文件打开方式列表

http://blog.csdn.net/feng19821209/article/details/5221107 添加: 1.点击“开始”,“运行”,在其中输入regedit,然后确定.2.打开注册表编辑器后,找到如下路径: HKEY_CURRENT_USER/Software/Classes/Applications 比如说,要添加的打开程序为test.exe 那么可以新建这样的项: HKEY_CURRENT_USER/Software/Classes/Applications/text.e