| | |
| | | strAppName = strAppName.Left(strAppName.ReverseFind('.')); |
| | | |
| | | HKEY hKey; |
| | | LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_WRITE, &hKey); |
| | | LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_READ | KEY_WRITE, &hKey); |
| | | |
| | | if (lRet != ERROR_SUCCESS) { |
| | | return false; |
| | | } |
| | | |
| | | DWORD dwType = 0; |
| | | TCHAR szValue[MAX_PATH] = { 0 }; |
| | | DWORD dwSize = sizeof(szValue); |
| | | lRet = RegQueryValueEx(hKey, strAppName, 0, &dwType, (LPBYTE)szValue, &dwSize); |
| | | |
| | | if (bEnable) { |
| | | // 设置自启 |
| | | lRet = RegSetValueEx(hKey, strAppName, 0, REG_SZ, (BYTE*)(LPCTSTR)strAppPath, (strAppPath.GetLength() + 1) * sizeof(TCHAR)); |
| | | if (lRet != ERROR_SUCCESS || _tcsicmp(szValue, strAppPath) != 0) { |
| | | // 设置自启 |
| | | lRet = RegSetValueEx(hKey, strAppName, 0, REG_SZ, (BYTE*)(LPCTSTR)strAppPath, (strAppPath.GetLength() + 1) * sizeof(TCHAR)); |
| | | } |
| | | else { |
| | | lRet = ERROR_SUCCESS; |
| | | } |
| | | } |
| | | else { |
| | | // 取消自启 |
| | | lRet = RegDeleteValue(hKey, strAppName); |
| | | if (lRet == ERROR_SUCCESS) { |
| | | // 取消自启 |
| | | lRet = RegDeleteValue(hKey, strAppName); |
| | | } |
| | | else { |
| | | lRet = ERROR_SUCCESS; |
| | | } |
| | | } |
| | | |
| | | RegCloseKey(hKey); |