如何使我的程序一开机就运行? 如何使我的程序一开机就运行?无论是写在注册表里还是其他方法,是否能提供一些原代码? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 bool AutoRun(BOOL bAutoRun){ //* LONG lRc; HKEY hNewKey; DWORD dwDisposition; LPCTSTR lpszTransparent = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); CString strAppPath(_T("")); CHAR lpszAppPath[MAX_PATH*2] = {0}; lRc = RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpszTransparent, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNewKey, &dwDisposition); if (lRc != ERROR_SUCCESS) { TRACE(_T("Error int RegCreateKeyEx: %x \n"),lRc); return false; } strAppPath = AfxGetApp()->m_pszHelpFilePath; strAppPath = strAppPath.Left(strAppPath.GetLength() - 4) + _T(".exe"); memcpy(lpszAppPath,strAppPath,strAppPath.GetLength()); if (dwDisposition == REG_CREATED_NEW_KEY) TRACE(_T("New Key Create!\n")); if (dwDisposition == REG_OPENED_EXISTING_KEY) TRACE(_T("Existing key opened!\n")); if (bAutoRun) { lRc = RegSetValueEx(hNewKey, _T("TransparentDesktop"), 0, REG_SZ, (BYTE *)lpszAppPath, strAppPath.GetLength()); if (lRc != ERROR_SUCCESS) { TRACE(_T("Error in RegSetValueEx :%x \n"),lRc); return false; } lRc = RegFlushKey(hNewKey); if (lRc != ERROR_SUCCESS) { TRACE(_T("Error in RegFlushKey :%x \n"),lRc); return false; } } else { if ( ERROR_SUCCESS != RegDeleteValue(hNewKey, _T("TransparentDesktop"))) { TRACE(_T("Error in RegDeleteValue \n")); return false; } } lRc = RegCloseKey(hNewKey); if (lRc != ERROR_SUCCESS) { TRACE(_T("Error in RegCloseKey :%x \n"),lRc); return false; } //*/ return true;}这个是将我写的自身是否开机就运行的函数!只要改一下!调用方面! 把你的.exe文件放到“启动”文件夹里去。 两种做法:1、做成NT服务程序2、写注册表:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run写注册表到以上位置 窗口前端显示的问题,急求答案 VS2008SP1自动生成的多文档工程的问题(CFileView和CClassView) 有关IP address控件获取再设置的问题 MYSQL访问冲突 如何在 VC/MFC 下编译链接 UNICODE 程序 怎样看到我的电脑的桌面? H263的源程序怎么编译啊 请问如何用 命令行 编译完成一个多动态库的项目? 为什么类中定义的公共函数编译时出现本地函数定义非法?? 【高分】小波变换获取低频和高频图像(vc++代码) VB 的exe组件通过DCOM发布 <<<<<<<<<<<<谁知道联众的设计思路,简单的思路!程序流程!>>>>>>>>>
{
//*
LONG lRc;
HKEY hNewKey;
DWORD dwDisposition;
LPCTSTR lpszTransparent = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
CString strAppPath(_T(""));
CHAR lpszAppPath[MAX_PATH*2] = {0}; lRc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
lpszTransparent,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hNewKey,
&dwDisposition); if (lRc != ERROR_SUCCESS)
{
TRACE(_T("Error int RegCreateKeyEx: %x \n"),lRc);
return false;
} strAppPath = AfxGetApp()->m_pszHelpFilePath;
strAppPath = strAppPath.Left(strAppPath.GetLength() - 4) + _T(".exe");
memcpy(lpszAppPath,strAppPath,strAppPath.GetLength()); if (dwDisposition == REG_CREATED_NEW_KEY)
TRACE(_T("New Key Create!\n"));
if (dwDisposition == REG_OPENED_EXISTING_KEY)
TRACE(_T("Existing key opened!\n")); if (bAutoRun)
{
lRc = RegSetValueEx(hNewKey,
_T("TransparentDesktop"),
0,
REG_SZ,
(BYTE *)lpszAppPath,
strAppPath.GetLength());
if (lRc != ERROR_SUCCESS)
{
TRACE(_T("Error in RegSetValueEx :%x \n"),lRc);
return false;
}
lRc = RegFlushKey(hNewKey);
if (lRc != ERROR_SUCCESS)
{
TRACE(_T("Error in RegFlushKey :%x \n"),lRc);
return false;
}
}
else
{
if ( ERROR_SUCCESS != RegDeleteValue(hNewKey, _T("TransparentDesktop")))
{
TRACE(_T("Error in RegDeleteValue \n"));
return false;
}
}
lRc = RegCloseKey(hNewKey);
if (lRc != ERROR_SUCCESS)
{
TRACE(_T("Error in RegCloseKey :%x \n"),lRc);
return false;
}
//*/
return true;
}
这个是将我写的自身是否开机就运行的函数!只要改一下!调用方面!
1、做成NT服务程序2、写注册表:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
写注册表到以上位置