首页 技术 正文
技术 2022年11月18日
0 收藏 440 点赞 2,913 浏览 2902 个字

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

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

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

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

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

接下来直接贴代码~

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

 /*
* Author: Haipz
* School: HDU
* File Name: registry1.0.cpp
*/
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std; char s[], buffer[], result[*]; void work_1() {
system("reg add \"HKEY_CLASSES_ROOT\\.c\\ShellNew\" /v \"NullFile\" /t REG_SZ");
} void work_2() {
system("reg add \"HKEY_CLASSES_ROOT\\.cpp\\ShellNew\" /v \"NullFile\" /t REG_SZ");
} void work_3() {
system("reg add \"HKEY_CLASSES_ROOT\\.java\\ShellNew\" /v \"NullFile\" /t REG_SZ");
} int main() {
printf("Add registry for C, C++ and Java\n");
printf("Author: Haipz\nSchool: HDU\n");
printf("1 for C;\n2 for C++;\n3 for Java.\n");
printf("Example: 12 to add C and C++.\n");
printf("Please make choice(s): ");
gets(s);
for (int i = ; s[i] != '\0'; ++i) {
printf("Working...\n");
if (s[i] == '') work_1();
else if (s[i] == '') work_2();
else if (s[i] == '') work_3();
else printf("%c is a wrong enter!\n", s[i]);
}
system("pause");
return ;
}

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

 /*
* Author: Haipz
* School: HDU
* File Name: registry2.0.cpp
*/
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std; char a[];
char b[] = "reg add \"HKEY_CLASSES_ROOT\\.";
char c[] = "\\ShellNew\" /v \"NullFile\" /t REG_SZ"; void work(char* a) {
strcat(b, a);
strcat(b, c);
system(b);
} int main() {
printf("Function: Add registry to build a new file simply!\n");
printf("Author: Haipz\nSchool: HDU\n");
printf("Example: Enter c to add C and enter cpp to add C++.\n");
printf("Your opion: ");
gets(a);
work(a);
system("pause");
return ;
}

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

 /*
* Author: Haipz
* School: HDU
* File Name: registry2.0.cpp
*/
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std; char key[];
char a[]; void add(char* t) {
char b[] = "reg add \"HKEY_CLASSES_ROOT\\.";
char c[] = "\\ShellNew\" /v \"NullFile\" /t REG_SZ";
strcat(b, t);
strcat(b, c);
system(b);
} void del(char* t) {
char d[] = "reg delete \"HKEY_CLASSES_ROOT\\.";
char e[] = "\\ShellNew\" /f";
strcat(d, t);
strcat(d, e);
system(d);
} int main() {
printf("Function: Build a new file simply!\n");
printf("Author: Haipz\nSchool: HDU\n");
printf("Example: Enter \"c\" to add C and enter \"cpp\" to add C++;\n");
printf(" Enter \"-c\" to delete C.\n");
do {
printf("Your opion: ");
gets(a);
if (a[] == '-') del(a + );
else add(a);
printf("Enter \"r\" to run again or any other key to quit: ");
gets(key);
} while (key[] == 'r');
return ;
}

打包下载地址:

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

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,497
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298