• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-11
  • 语言: C/C++
  • 标签: VS2017  

资源简介

VS2017 C++ 编写一个通过注册表自定义软件开机启动程序,里面包含一个sln,一个cpp文件。

资源截图

代码片段和文件信息

#include 
#include 
#include  // 使用 _T宏

using namespace std;

int test()
{
//_T宏可以把一个引号引起来的字符串,根你的环境设置,使得编译器会根据编译目标环境选择合适的(Unicode还是ANSI)字符处理方式
LPCTSTR lpSubKey = _T(“SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run“);
HKEY hKey;
REGSAM flag = KEY_WOW64_64KEY;//当前系统为win7 64位,访问的是64位的注册表,如果访问32位,则改为KEY_WOW64_32KEY
LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE lpSubKey 0 KEY_ALL_ACCESS|flag&hKey);

if (ERROR_SUCCESS != lRet)
{
cout << “RegOpenKeyEx fail!“ << endl;
return 0;
}

LPCTSTR pchrName = _T(“D:\\Program Files (x86)\\test.exe“);//test.exe为随意的一个测试程序。
lRet = RegSetValueEx(hKey TEXT(“TEST“) 0 REG_SZ (LPBYTE)pchrName wcslen(pchrName) * sizeof(TCHAR) + 1);

if (ERROR_SUCCESS != lRet)
{
cout << “RegSetValueEx fail!“ << endl;
return 0;
}
RegCloseKey(hKey);

return 0;
}

int main()
{
test();
system(“pause“);
    return 0;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1878  2018-05-25 21:31  AutoStartProcess\AutoStartProcess.cpp

     文件       7504  2018-05-25 20:47  AutoStartProcess\AutoStartProcess.vcxproj

     文件        961  2018-05-25 20:40  AutoStartProcess\AutoStartProcess.vcxproj.filters

     文件        165  2018-05-25 20:39  AutoStartProcess\AutoStartProcess.vcxproj.user

     文件       1462  2018-05-25 20:39  AutoStartProcess.sln

     目录          0  2018-05-26 09:21  AutoStartProcess

----------- ---------  ---------- -----  ----

                11970                    6


评论

共有 条评论