修改注册表开机自动启动程序

修改注册表开机自动启动程序
HKEY     hKey;    
char     szFileName[256];
GetModuleFileName(NULL,szFileName,256);
RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE//Microsoft//windows//currentversion//run",&hKey);
if(m_bAutoRun)
{
     RegSetValueEx(hKey,"RunmeAtStartup",0,REG_SZ,(BYTE *)szFileName,sizeof(szFileName));
}
else
{
     RegDeleteValue(hKey,"RunmeAtStartup");
}
RegCloseKey(hKey);     

 

开机自动运行

BOOL 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;
}    

你可能感兴趣的:(null,Path,byte)