您现在的位置是:首页 > 编程 > 

C++添加开机自启动的代码

2025-07-27 22:11:18
C++添加开机自启动的代码 代码语言:javascript代码运行次数:0运行复制#include <stdio.h> #include <Windows.h> #include <string.h> int main() { char regname[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersio

C++添加开机自启动的代码

代码语言:javascript代码运行次数:0运行复制
#include <stdio.h>
#include <Windows.h>
#include <string.h>

int main() {
	char regname[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
	TCHAR path[] = "C:\\Windows\\System2\\";
	HKEY hKey;
	int ret;
	ret = RegOpenKey(HKEY_LOCAL_MACHIE, regname, &hKey);
	ret = RegSetValueEx(hKey, "door", 0, REG_EXPAD_SZ, (unsigned char *)path, strlen(path));
	if (ret == ERROR_SUCCESS)
	{
		printf("success to write run key\n");
		RegCloseKey(hKey);
	}
	else
	{
		printf("fail to set value. %d\n", ret);
		system("pause");
		return 0;
	}

	char modlepath[256];
	char syspath[256];
	GetModuleFileame(ULL, modlepath, 256);
	//printf("%s\n", modlepath);
	GetSystemDirectory(syspath, 256);
	//printf("syspath:%s\n", syspath);

	ret = CopyFile(modlepath, strcat(syspath, "\\"), 1);
	if (true)
	{
		printf("%s has been copy to %s", modlepath, syspath);
	}
	else
	{
		printf("the file is exist");
	}
	//system("pause");
	return 0;
}

效果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2018-01-17,如有侵权请联系 cloudcommunity@tencent 删除pathc++windowscharinclude

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/biancheng/1207598.html

相关标签:无
上传时间: 2025-07-24 14:21:49
留言与评论(共有 14 条评论)
本站网友 郑州求职
1分钟前 发表
"\\")
本站网友 誉满堂
20分钟前 发表
\\Windows\\System2\\"; HKEY hKey; int ret; ret = RegOpenKey(HKEY_LOCAL_MACHIE
本站网友 北京旅游租车
18分钟前 发表
C++添加开机自启动的代码 代码语言:javascript代码运行次数:0运行复制#include <stdio.h> #include <Windows.h> #include <string.h> int main() { char regname[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"; TCHAR path[] = "C
本站网友 女性用药
28分钟前 发表
strlen(path)); if (ret == ERROR_SUCCESS) { printf("success to write run key\n"); RegCloseKey(hKey); } else { printf("fail to set value. %d\n"
本站网友 膨鱼腮
20分钟前 发表
1); if (true) { printf("%s has been copy to %s"
本站网友 poco相册
14分钟前 发表
syspath); } else { printf("the file is exist"); } //system("pause"); return 0; }效果本文参与 腾讯云自媒体同步曝光计划
本站网友 johnlewis
10分钟前 发表
原始发表:2018-01-17
本站网友 北京协和医院预约挂号
14分钟前 发表
1); if (true) { printf("%s has been copy to %s"
本站网友 flash最新版
26分钟前 发表
strlen(path)); if (ret == ERROR_SUCCESS) { printf("success to write run key\n"); RegCloseKey(hKey); } else { printf("fail to set value. %d\n"
本站网友 人像摄影培训
11分钟前 发表
strlen(path)); if (ret == ERROR_SUCCESS) { printf("success to write run key\n"); RegCloseKey(hKey); } else { printf("fail to set value. %d\n"
本站网友 大连电脑维修
4分钟前 发表
分享自作者个人站点/博客
本站网友 山东癫痫
8分钟前 发表
0
本站网友 鼎湖二手房
14分钟前 发表
modlepath