Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
12 KiB

  1. #if !defined(AFX_PAGESTARTUP_H__928475DA_B332_47F4_8180_5C8B79DFC203__INCLUDED_)
  2. #define AFX_PAGESTARTUP_H__928475DA_B332_47F4_8180_5C8B79DFC203__INCLUDED_
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. #include "PageBase.h"
  7. #include "MSConfigState.h"
  8. //============================================================================
  9. // The CStartupItem class is used to encapsulate an individual startup
  10. // item. Pointers to these objects are maintained in the list.
  11. //============================================================================
  12. class CStartupItem
  13. {
  14. public:
  15. //------------------------------------------------------------------------
  16. // Constructor and destructor.
  17. //------------------------------------------------------------------------
  18. CStartupItem() { }
  19. virtual ~CStartupItem() { }
  20. //------------------------------------------------------------------------
  21. // If the derived classes use the base class member variables, these won't
  22. // need to be overridden.
  23. //------------------------------------------------------------------------
  24. virtual void GetDisplayInfo(CString & strItem, CString & strLocation, CString & strCommand)
  25. {
  26. strItem = m_strItem;
  27. strLocation = m_strLocation;
  28. strCommand = m_strCommand;
  29. }
  30. virtual BOOL IsLive()
  31. {
  32. return m_fLive;
  33. }
  34. //------------------------------------------------------------------------
  35. // Set whether or not the startup item is enabled. If disabling the
  36. // startup item, add a registry entry so it will be loaded again.
  37. // If enabling the startup item, delete the registry entry.
  38. //
  39. // Of course, do the appropriate thing to registry keys, etc.
  40. //------------------------------------------------------------------------
  41. virtual BOOL SetEnable(BOOL fEnable) = 0;
  42. protected:
  43. BOOL m_fLive;
  44. CString m_strItem;
  45. CString m_strLocation;
  46. CString m_strCommand;
  47. };
  48. //============================================================================
  49. // The CStartupItemRegistry class is used to encapsulate an individual startup
  50. // item stored in the registry.
  51. //============================================================================
  52. class CStartupItemRegistry : public CStartupItem
  53. {
  54. public:
  55. //------------------------------------------------------------------------
  56. // Overridden methods for this type of startup item.
  57. //------------------------------------------------------------------------
  58. CStartupItemRegistry();
  59. CStartupItemRegistry(HKEY hkey, LPCTSTR szKey, LPCTSTR szName, LPCTSTR szValueName, LPCTSTR szValue);
  60. CStartupItemRegistry(LPCTSTR szKey, LPCTSTR szName, LPCTSTR szValueName, LPCTSTR szValue);
  61. BOOL SetEnable(BOOL fEnable);
  62. //------------------------------------------------------------------------
  63. // Functions for this subclass.
  64. //------------------------------------------------------------------------
  65. BOOL Create(LPCTSTR szKeyName, HKEY hkey);
  66. static void RemovePersistedEntries();
  67. private:
  68. HKEY m_hkey;
  69. CString m_strKey;
  70. CString m_strValueName;
  71. BOOL m_fIniMapping;
  72. };
  73. //============================================================================
  74. // The CStartupItemFolder class is used to encapsulate an individual startup
  75. // stored in the startup folder.
  76. //============================================================================
  77. class CStartupItemFolder : public CStartupItem
  78. {
  79. public:
  80. //------------------------------------------------------------------------
  81. // Class used to get information about a shortcut from a function running
  82. // in a different thread.
  83. //------------------------------------------------------------------------
  84. class CIconInfo
  85. {
  86. public:
  87. TCHAR szPath[MAX_PATH * 2];
  88. TCHAR szTarget[MAX_PATH * 2];
  89. TCHAR szArgs[MAX_PATH * 2];
  90. HRESULT hResult;
  91. };
  92. public:
  93. //------------------------------------------------------------------------
  94. // Overridden methods for this type of startup item.
  95. //------------------------------------------------------------------------
  96. CStartupItemFolder();
  97. BOOL SetEnable(BOOL fEnable);
  98. //------------------------------------------------------------------------
  99. // Functions for this subclass.
  100. //------------------------------------------------------------------------
  101. BOOL Create(LPCTSTR szKeyName, HKEY hkey);
  102. BOOL Create(const WIN32_FIND_DATA & fd, HKEY hkey, LPCTSTR szRegPathToFolder, LPCTSTR szFolder, LPCTSTR szDir);
  103. static void RemovePersistedEntries();
  104. HRESULT GetIconInfo(CIconInfo & info);
  105. private:
  106. CString m_strFilePath;
  107. CString m_strBackupPath;
  108. };
  109. //============================================================================
  110. // The class which implements the startup tab.
  111. //============================================================================
  112. class CPageStartup : public CPropertyPage, public CPageBase
  113. {
  114. DECLARE_DYNCREATE(CPageStartup)
  115. // Construction
  116. public:
  117. CPageStartup();
  118. ~CPageStartup();
  119. // Dialog Data
  120. //{{AFX_DATA(CPageStartup)
  121. enum { IDD = IDD_PAGESTARTUP };
  122. // NOTE - ClassWizard will add data members here.
  123. // DO NOT EDIT what you see in these blocks of generated code !
  124. //}}AFX_DATA
  125. // Overrides
  126. // ClassWizard generate virtual function overrides
  127. //{{AFX_VIRTUAL(CPageStartup)
  128. protected:
  129. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  130. //}}AFX_VIRTUAL
  131. // Implementation
  132. protected:
  133. // Generated message map functions
  134. //{{AFX_MSG(CPageStartup)
  135. virtual BOOL OnInitDialog();
  136. afx_msg void OnDestroy();
  137. afx_msg void OnItemChangedList(NMHDR* pNMHDR, LRESULT* pResult);
  138. afx_msg void OnButtonDisableAll();
  139. afx_msg void OnButtonEnableAll();
  140. afx_msg void OnSetFocusList(NMHDR* pNMHDR, LRESULT* pResult);
  141. afx_msg void OnButtonRestore();
  142. //}}AFX_MSG
  143. DECLARE_MESSAGE_MAP()
  144. public:
  145. //=========================================================================
  146. // Functions overridden from CPageBase
  147. //=========================================================================
  148. TabState GetCurrentTabState();
  149. BOOL OnApply();
  150. void CommitChanges();
  151. void SetNormal();
  152. void SetDiagnostic();
  153. LPCTSTR GetName() { return _T("startup"); };
  154. private:
  155. //=========================================================================
  156. // Functions specific to this tab.
  157. //=========================================================================
  158. void LoadStartupList();
  159. void LoadStartupListLiveItems();
  160. void LoadStartupListLiveItemsRunKey();
  161. void LoadStartupListLiveItemsStartup();
  162. void LoadStartupListLiveItemsWinIniKey();
  163. void LoadStartupListDisabledItems();
  164. void GetCommandName(CString & strCommand);
  165. void InsertStartupItem(CStartupItem * pItem);
  166. void EmptyList(BOOL fFreeMemoryOnly);
  167. void SetEnableForList(BOOL fEnable);
  168. HWND GetDlgItemHWND(UINT nID)
  169. {
  170. HWND hwnd = NULL;
  171. CWnd * pWnd = GetDlgItem(nID);
  172. if (pWnd)
  173. hwnd = pWnd->m_hWnd;
  174. ASSERT(hwnd);
  175. return hwnd;
  176. }
  177. private:
  178. BOOL m_fModified;
  179. void SetModified(BOOL bChanged = TRUE)
  180. {
  181. m_fModified = bChanged;
  182. CPropertyPage::SetModified(bChanged);
  183. }
  184. //=========================================================================
  185. // Member variables.
  186. //=========================================================================
  187. CWindow m_list;
  188. int m_iNextPosition;
  189. BOOL m_fIgnoreListChanges;
  190. TabState m_stateRequested; // save the requested state in case there are no startup items
  191. };
  192. //============================================================================
  193. // CRestoreStartup implements a dialog box which allows the user to restore
  194. // startup items disabled during upgrade.
  195. //============================================================================
  196. #define DISABLED_KEY _T("Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\DisabledRunKeys")
  197. #define ENABLED_KEY _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")
  198. #define DISABLED_STARTUP _T("\\Disabled Startup")
  199. class CRestoreStartup : public CDialog
  200. {
  201. // Construction
  202. public:
  203. CRestoreStartup(CWnd* pParent = NULL); // standard constructor
  204. // Dialog Data
  205. //{{AFX_DATA(CRestoreStartup)
  206. enum { IDD = IDD_RESTORE };
  207. // NOTE: the ClassWizard will add data members here
  208. //}}AFX_DATA
  209. // Overrides
  210. // ClassWizard generated virtual function overrides
  211. //{{AFX_VIRTUAL(CRestoreStartup)
  212. protected:
  213. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  214. //}}AFX_VIRTUAL
  215. // Implementation
  216. public:
  217. static BOOL AreItemsToRestore();
  218. private:
  219. //-------------------------------------------------------------------------
  220. // These classes are used to represent the various types of disabled
  221. // startup items we might restore. CStartupDisabled is an abstract base.
  222. //-------------------------------------------------------------------------
  223. class CStartupDisabled
  224. {
  225. public:
  226. CStartupDisabled() {};
  227. virtual ~CStartupDisabled() {};
  228. virtual void GetColumnCaptions(CString & strItem, CString & strLocation) = 0;
  229. virtual void Restore() = 0;
  230. };
  231. //-------------------------------------------------------------------------
  232. // CStartupDisabledRegistry represents Run key items in the registry that
  233. // were disabled.
  234. //-------------------------------------------------------------------------
  235. class CStartupDisabledRegistry : public CStartupDisabled
  236. {
  237. public:
  238. CStartupDisabledRegistry(LPCTSTR szValueName, LPCTSTR szValue, LPCTSTR szLocation, HKEY hkeyBase) :
  239. m_strValueName(szValueName),
  240. m_strValue(szValue),
  241. m_strLocation(szLocation),
  242. m_hkeyBase(hkeyBase) {};
  243. ~CStartupDisabledRegistry() {};
  244. void GetColumnCaptions(CString & strItem, CString & strLocation)
  245. {
  246. strItem = m_strValueName + CString(_T(" = ")) + m_strValue;
  247. strLocation = ((m_hkeyBase == HKEY_LOCAL_MACHINE) ? CString(_T("HKLM\\")) : CString(_T("HKCU\\"))) + m_strLocation;
  248. }
  249. void Restore()
  250. {
  251. // Create the value in the Run registry key.
  252. CRegKey regkey;
  253. if (ERROR_SUCCESS != regkey.Open(m_hkeyBase, m_strLocation, KEY_WRITE))
  254. return;
  255. BOOL fSet = (ERROR_SUCCESS == regkey.SetValue(m_strValue, m_strValueName));
  256. regkey.Close();
  257. // Delete it from the disabled location.
  258. if (fSet)
  259. {
  260. if (ERROR_SUCCESS != regkey.Open(m_hkeyBase, DISABLED_KEY, KEY_WRITE))
  261. return;
  262. regkey.DeleteValue(m_strValueName);
  263. regkey.Close();
  264. }
  265. }
  266. private:
  267. CString m_strValueName;
  268. CString m_strValue;
  269. CString m_strLocation;
  270. HKEY m_hkeyBase;
  271. };
  272. //-------------------------------------------------------------------------
  273. // CStartupDisabledStartup represents startup group items that were
  274. // disabled.
  275. //-------------------------------------------------------------------------
  276. class CStartupDisabledStartup : public CStartupDisabled
  277. {
  278. public:
  279. CStartupDisabledStartup(LPCTSTR szFile, LPCTSTR szDestination, LPCTSTR szCurrentLocation) :
  280. m_strFile(szFile),
  281. m_strDestination(szDestination),
  282. m_strCurrentLocation(szCurrentLocation) {};
  283. ~CStartupDisabledStartup() {};
  284. void GetColumnCaptions(CString & strItem, CString & strLocation)
  285. {
  286. strItem = m_strFile;
  287. strLocation = m_strDestination;
  288. }
  289. void Restore()
  290. {
  291. // Move the file to the startup directory.
  292. CString strExisting(m_strCurrentLocation);
  293. if (strExisting.Right(1) != CString(_T("\\")))
  294. strExisting += CString(_T("\\"));
  295. strExisting += m_strFile;
  296. CString strDestination(m_strDestination);
  297. if (strDestination.Right(1) != CString(_T("\\")))
  298. strDestination += CString(_T("\\"));
  299. strDestination += m_strFile;
  300. ::MoveFileEx(strExisting, strDestination, 0);
  301. }
  302. private:
  303. CString m_strFile;
  304. CString m_strDestination;
  305. CString m_strCurrentLocation;
  306. };
  307. private:
  308. CWindow m_list;
  309. int m_iNextPosition;
  310. private:
  311. void InsertDisabledStartupItem(CStartupDisabled * pItem);
  312. BOOL LoadDisabledStartupGroup();
  313. BOOL LoadDisabledRegistry();
  314. BOOL LoadDisabledItemList();
  315. void EmptyList();
  316. void SetOKState();
  317. protected:
  318. // Generated message map functions
  319. //{{AFX_MSG(CRestoreStartup)
  320. virtual BOOL OnInitDialog();
  321. afx_msg void OnDestroy();
  322. virtual void OnOK();
  323. afx_msg void OnItemChangedRestoreList(NMHDR* pNMHDR, LRESULT* pResult);
  324. //}}AFX_MSG
  325. DECLARE_MESSAGE_MAP()
  326. };
  327. //{{AFX_INSERT_LOCATION}}
  328. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  329. #endif // !defined(AFX_PAGESTARTUP_H__928475DA_B332_47F4_8180_5C8B79DFC203__INCLUDED_)