我刚写过,在你的应用程序类的InitInstance()里加入以下代友
//注册使之可以每次开机时自动运行    char  *Path="software\\microsoft\\windows\\currentversion\\run",
  *KeyName="Java_cjh";    HKEY  hSearchKey;
REGSAM samWanted;
DWORD  lRegCallResult;
samWanted=KEY_ALL_ACCESS;
    
TCHAR FilePathName[200];
::GetModuleFileName(AfxGetInstanceHandle( ),FilePathName,sizeof(FilePathName));
LPSTR lpPath,fileName;
lpPath=FilePathName;//全路径
for(fileName = FilePathName + lstrlen(FilePathName); 
    fileName > FilePathName && *(fileName-1) != '\\'; fileName--);
    //循环得到应用程序文件名
    CString path,pathName(FilePathName);
path=pathName.Left(strlen(lpPath)-strlen(fileName));
    //得到路径
lRegCallResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                        Path,
0,
samWanted,
&hSearchKey);
    
if(lRegCallResult==ERROR_SUCCESS)
{
lRegCallResult=RegSetValueEx(hSearchKey,
                         KeyName,
 0,
 REG_SZ,
                        (CONST BYTE*)FilePathName,
pathName.GetLength()); if(lRegCallResult=!ERROR_SUCCESS)
{
TRACE("Registry failed!");
}

ASSERT(RegCloseKey(hSearchKey)==ERROR_SUCCESS);
}