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

发布时间:2024-04-28 23:34 发布:上海旅游网

问题描述:

问题解答:

写注册表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,REG_SZ,(const unsigned char*)(LPCTSTR)fullName,fullName.GetLength());//这里加上你需要在注册表中注册的内容
this->UpdateData(FALSE);
}
else
{
//theApp.SetMainSkin();
::AfxMessageBox("没找到执行程序,自动运行失败");
exit(0);
}
return 0;
}

//把上面的getip(共2处)替换成自己想启动程序的名字。

热点新闻