#include <tlhelp32.h> 枚举进程头文件
//VC根据进程名获得进程ID
DWORD GetProcessIDFromName(char *name)
{
HANDLE snapshot;
PROCESSENTRY32 processinfo;
processinfo.dwSize = sizeof(processinfo);
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(snapshot == NULL)
return FALSE;
BOOL status = Process32First(snapshot, &processinfo);
while(status)
{
if(_stricmp(name,processinfo.szExeFile)==0)
return processinfo.th32ProcessID;
status = Process32Next(snapshot,&processinfo);
}
return -1;
}
//VC写入注册表,使程序开机启动
if(autoopendlp == 1)
{
HKEY hKey;
LPCTSTR lpRun = "Software//Microsoft//Windows//CurrentVersion//Run";
long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey);
if(lRet == ERROR_SUCCESS)
{
char pFileName[MAX_PATH] = {0};
DWORD dwRet = GetModuleFileName(GetModuleHandle(AfxGetApp()-> m_pszAppName), pFileName, MAX_PATH);
lRet = RegSetValueEx(hKey, "ctrl", 0, REG_SZ, (LPBYTE)pFileName, strlen(pFileName));
MessageBox(pFileName);
if(lRet != ERROR_SUCCESS)
{
AfxMessageBox("系统参数错误,不能随系统启动");
}
}else
RegDeleteValue(hKey,"ctrl");
RegCloseKey(hKey);
}
//VC获得系统特殊文件夹 SHGetSpecialFolderPath
SHGetSpecialFolderPath
作用:
获取特定文件夹路径
原型:
BOOL SHGetSpecialFolderPath(
HWND hwndOwner,
LPTSTR lpszPath,
int nFolder,
BOOL fCreate
);
示例:
获得自启动文件夹的路径
TCHAR filePath[MAX_PATH];
::SHGetSpecialFolderPath(NULL, filePath, CSIDL_STARTUP, FALSE);
以下是nFolder值的对应情况
获取值的机器为多普达838
CSIDL_STARTMENU —— \Windows\“开始”菜单
CSIDL_STARTUP —— \Windows\StartUp
CSIDL_WINDOWS —— \Windows
CSIDL_RECENT ——
CSIDL_PROGRAMS —— \Windows\“开始”菜单\程序
CSIDL_PROGRAM_FILES —— \Program Files
CSIDL_PERSONAL —— \My Documents
CSIDL_MYVIDEO ——\My Documents\我的视频
CSIDL_MYPICTURES —— \My Documents\我的图片
CSIDL_MYMUSIC —— \My Documents\我的音乐
CSIDL_FONTS —— \Windows\Fonts
CSIDL_FAVORITES —— \Windows\Favorites
CSIDL_DESKTOPDIRECTORY ——
CSIDL_DESKTOP —— \My Documents
CSIDL_APPDATA —— \Application Data