实现电脑启动后应用程序实现自启动,在vc应用程序里该如何填写代码?尽量详细

来源:百度知道 编辑:UC知道 时间:2024/06/10 05:20:47

写注册表Software\\Microsoft\\Windows\\CurrentVersion\\Run 。

参考程序可以见下:(查找程序目录的执行文件,存在则进行添加注册表操作)

//实用代码一

int C***Dlg::CreateRun(void)
{

//添加以下代码
HKEY RegKey;
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer();
int nPos;
nPos=sPath.ReverseFind('\\');
sPath=sPath.Left(nPos);
CString lpszFile=sPath+"\\getip.exe";//这里加上你要查找的执行文件名称
CFileFind fFind;
BOOL bSuccess;
bSuccess=fFind.FindFile(lpszFile);
fFind.Close();
if(bSuccess)
{
CString fullName;
fullName=lpszFile;
RegKey=NULL;
RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&RegKey);
RegSetValueEx(RegKey,"getip",0