• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Gredswsh的技术生活

Java,Python,Go,SCI_NUM
  • 联系
  • 订阅
  • 管理

公告

View Post

[VC]VC实现开机自动运行程序

有时候,我们需要在计算机启动的时候就启动某些程序,不要人干预。这里,提供一种让程序开机自动运行的方法。见下面代码:

BOOL CXXX::SetAutoRun(CString strPath)

{

CString str;

HKEY hRegKey;

BOOL bResult;

str=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");

if(RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey) != ERROR_SUCCESS)

bResult=FALSE;

else

{

_splitpath(strPath.GetBuffer(0),NULL,NULL,str.GetBufferSetLength(MAX_PATH+1),NULL);

strPath.ReleaseBuffer();

str.ReleaseBuffer();

if(::RegSetValueEx( hRegKey,str,0,REG_SZ,(CONST BYTE *)strPath.GetBuffer(0),strPath.GetLength() )!=ERROR_SUCCESS)

bResult=FALSE;

else

bResult=TRUE;

strPath.ReleaseBuffer();

}

return bResult;

}

CString CXXX::GetMyPath()

{

CString strPath;

GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);

strPath.ReleaseBuffer();

return strPath;

}

//把上面的两个函数加入在程序初始化的地方

CString mypath;

mypath=GetMyPath();

SetAutoRun(mypath);

转载请注明文章出处:http://www.cnblogs.com/gredswsh   Gredswsh  专栏

posted on 2014-05-19 21:13  fxcl  阅读(649)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3