您现在的位置是:网站首页 > 语言基础 > MFC设置开机自启动

简介本文介绍一个C++代码片段:MFC设置开机自启动,感兴趣的朋友可以参考一下。

代码

char dir[_MAX_DIR];
_splitpath(tcsModulePath, drive, dir, NULL, NULL);
CString strPath;
strPath.Format("%s%s主程序.exe", drive, dir);  // strPath即为得到的当前运行程序所在目录
// AfxMessageBox(strPath);
CRegKey writevalue;
CString skey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
writevalue.Create(HKEY_LOCAL_MACHINE, skey);// 等同与Attach("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run")
writevalue.SetValue(strPath, "MyRun");
writevalue.Close();


更多为你推荐