00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "fsAutorunMgr.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 fsAutorunMgr::fsAutorunMgr()
00017 {
00018 m_hAutoStart = NULL;
00019 }
00020
00021 fsAutorunMgr::~fsAutorunMgr()
00022 {
00023
00024 }
00025
00026 BOOL fsAutorunMgr::SetAutoStart(BOOL bSet)
00027 {
00028 if (FALSE == OpenAutoStartKey ())
00029 return FALSE;
00030
00031 TCHAR szModule [MY_MAX_PATH + 50];
00032 *szModule = 0;
00033 BOOL bRet;
00034
00035
00036 GetModuleFileName (NULL, szModule, MY_MAX_PATH);
00037
00038 if (bSet)
00039 {
00040
00041 _tcscat (szModule, _T (" -autorun"));
00042 bRet = ERROR_SUCCESS == RegSetValueEx (m_hAutoStart, _T ("Free Download Manager"), 0, REG_SZ, (CONST BYTE*) szModule, _tcslen (szModule) + 1);
00043 }
00044 else
00045 {
00046 bRet = ERROR_SUCCESS == RegDeleteValue (m_hAutoStart, _T ("Free Download Manager"));
00047 }
00048
00049 CloseAutoStartKey ();
00050
00051 return bRet;
00052 }
00053
00054 BOOL fsAutorunMgr::OpenAutoStartKey()
00055 {
00056
00057 if (ERROR_SUCCESS != RegOpenKey (HKEY_CURRENT_USER,
00058 _T ("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), &m_hAutoStart))
00059 return FALSE;
00060
00061 return TRUE;
00062 }
00063
00064 void fsAutorunMgr::CloseAutoStartKey()
00065 {
00066 RegCloseKey (m_hAutoStart);
00067 }
00068
00069 BOOL fsAutorunMgr::IsAutoStart()
00070 {
00071 if (FALSE == OpenAutoStartKey ())
00072 return FALSE;
00073
00074 DWORD dwType;
00075
00076 return ERROR_SUCCESS == RegQueryValueEx (m_hAutoStart, _T ("Free Download Manager"), NULL,
00077 &dwType, NULL, NULL);
00078 }