void CteamtalkApp::SetAutoRun(BOOL bAutoRun)
{
HKEY hKey;
if (bAutoRun)
{
if (RegOpenKeyEx(HKEY_CURRENT_USER,
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) //打开启动项
{
TCHAR szModule[_MAX_PATH];
GetModuleFileName(NULL, szModule, _MAX_PATH);//得到本程序自身的全路径
RegSetValueEx(hKey, _T("CTalk"), 0, REG_SZ, (const BYTE*)(LPCSTR)szModule, _MAX_PATH); //添加一个子Key,并设置值,"Client"是应用程序名字(不加后缀.exe)
RegCloseKey(hKey); //关闭注册表
}
else
{
AfxMessageBox(_T("系统参数错误,不能随系统启动"));
}
}
else
{
if (RegOpenKeyEx(HKEY_CURRENT_USER,
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
RegDeleteValue(hKey, _T("CTalk"));
RegCloseKey(hKey);
}
}
}
{
HKEY hKey;
if (bAutoRun)
{
if (RegOpenKeyEx(HKEY_CURRENT_USER,
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) //打开启动项
{
TCHAR szModule[_MAX_PATH];
GetModuleFileName(NULL, szModule, _MAX_PATH);//得到本程序自身的全路径
RegSetValueEx(hKey, _T("CTalk"), 0, REG_SZ, (const BYTE*)(LPCSTR)szModule, _MAX_PATH); //添加一个子Key,并设置值,"Client"是应用程序名字(不加后缀.exe)
RegCloseKey(hKey); //关闭注册表
}
else
{
AfxMessageBox(_T("系统参数错误,不能随系统启动"));
}
}
else
{
if (RegOpenKeyEx(HKEY_CURRENT_USER,
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
RegDeleteValue(hKey, _T("CTalk"));
RegCloseKey(hKey);
}
}
}