(转载)应用程序开机自启动的C代码
学习转载 文章出处 http://blog.csdn.net/my2005lb/article/details/8693636
<span style="font-size:18px;"> char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(__argv[0],drive,dir,fname,ext);
CString path(drive);
path+=dir;
path+="svhost.exe";//开机自启动的程序,上面的代码是自动获取当前的目录
TCHAR m_path[MAX_PATH];
wsprintf(m_path,path);
HKEY hkey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\Currentversion\\Run",0,KEY_WRITE,&hkey);
RegSetValueEx(hkey,"svhost",0,REG_SZ,(LPBYTE)m_path,lstrlen(m_path)+1);
RegCloseKey(hkey); </span>
分享一段开机自启动代码,基于VC++编译。
- <span style="font-size:18px;"> char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
- _splitpath(__argv[0],drive,dir,fname,ext);
- CString path(drive);
- path+=dir;
- path+="svhost.exe";//开机自启动的程序,上面的代码是自动获取当前的目录
- TCHAR m_path[MAX_PATH];
- wsprintf(m_path,path);
- HKEY hkey;
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\Currentversion\\Run",0,KEY_WRITE,&hkey);
- RegSetValueEx(hkey,"svhost",0,REG_SZ,(LPBYTE)m_path,lstrlen(m_path)+1);
- RegCloseKey(hkey); </span>