zoukankan      html  css  js  c++  java
  • [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);

  • 相关阅读:
    关于firstChild,firstElementChild和children
    trim(),正则表达式中文匹配
    Shell之基本用法
    Samba服务部署
    Linux基础(3)
    linux基础(2)
    Linux基础(1)
    网络基础及网络协议
    操作系统简介
    为何要学习计算机基础
  • 原文地址:https://www.cnblogs.com/gredswsh/p/vc_program_start_automatically.html
Copyright © 2011-2022 走看看