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.

225 lines
7.8 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: wuaulib.h
  6. //
  7. // Creator: PeterWi
  8. //
  9. // Purpose: library function declarations.
  10. //
  11. //=======================================================================
  12. #pragma once
  13. #include <tchar.h>
  14. #include <wchar.h>
  15. #include <timeutil.h>
  16. #include "WUTestKeys.h"
  17. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  18. // Defs for boolean AU options
  19. #define AUOPTION_UNSPECIFIED 0
  20. #define AUOPTION_AUTOUPDATE_DISABLE 1
  21. #define AUOPTION_PREDOWNLOAD_NOTIFY 2
  22. #define AUOPTION_INSTALLONLY_NOTIFY 3
  23. #define AUOPTION_SCHEDULED 4
  24. #define AUOPTION_ADMIN_MIN AUOPTION_AUTOUPDATE_DISABLE
  25. #define AUOPTION_DOMAIN_MIN AUOPTION_PREDOWNLOAD_NOTIFY
  26. #define AUOPTION_MAX AUOPTION_SCHEDULED
  27. // download status
  28. #define DWNLDSTATUS_NOT_DOWNLOADING 0
  29. #define DWNLDSTATUS_DOWNLOADING 1
  30. #define DWNLDSTATUS_PAUSED 2
  31. #define DWNLDSTATUS_CHECKING_CONNECTION 3
  32. //////////////////////Client (WUAUCLT) exit codes //////////////////////////
  33. #define CDWWUAUCLT_UNSPECIFY -1
  34. #define CDWWUAUCLT_OK 1000
  35. #define CDWWUAUCLT_RELAUNCHNOW 1001
  36. #define CDWWUAUCLT_RELAUNCHLATER 1002 //ask service to launch client
  37. #define CDWWUAUCLT_ENDSESSION 1003 // user logs off or system shuts down
  38. #define CDWWUAUCLT_FATAL_ERROR 1004
  39. #define CDWWUAUCLT_INSTALLNOW 1005
  40. #define CDWWUAUCLT_REBOOTNOW 1007
  41. #define CDWWUAUCLT_REBOOTLATER 1008
  42. #define CDWWUAUCLT_REBOOTNEEDED 1009 //user hasn't made decision as weather to reboot or not
  43. #define CDWWUAUCLT_REBOOTTIMEOUT 1010 //reboot warning dialog times out
  44. //////////////////////Prompt Dlg defs//////////////////////////////////////
  45. #define AUPROMPTDLG_TOTAL_TIME_ELAPSE AU_FIVE_MINS // For 5 mins 300
  46. //////////////////////No Active Admin Session found//////////////////////////
  47. #define DWNO_ACTIVE_ADMIN_SESSION_FOUND -1 // No Active Admin Session Found
  48. #define DWNO_ACTIVE_ADMIN_SESSION_SERVICE_FINISHED -2 // No Active Admin Sesion found due to Service Finishing or because caller routine needs to finish service
  49. #define DWSYSTEM_ACCOUNT -3
  50. class AU_ENV_VARS {
  51. public:
  52. static const int s_AUENVVARCOUNT = 6;
  53. static const int s_AUENVVARBUFSIZE = 100;
  54. BOOL m_fRebootWarningMode ; //regular mode otherwise
  55. BOOL m_fEnableYes; //for reboot warning dialog
  56. BOOL m_fEnableNo; //for reboot warning dialog
  57. BOOL m_fManualReboot; //for reboot warning dialog
  58. DWORD m_dwStartTickCount; //for reboot warning dialog, in milli secs
  59. TCHAR m_szClientExitEvtName[s_AUENVVARBUFSIZE];
  60. public:
  61. BOOL ReadIn(void);
  62. BOOL WriteOut(LPTSTR szEnvBuf, //at least size of 4*AUEVVARBUFSIZE
  63. size_t IN cchEnvBuf,
  64. BOOL IN fEnableYes = TRUE,
  65. BOOL IN fEnableNo = TRUE,
  66. BOOL IN fManualReboot = FALSE,
  67. DWORD IN dwStartTickCount = 0,
  68. LPCTSTR IN szClientExitEvtName = NULL);
  69. private:
  70. static const LPCTSTR s_AUENVVARNAMES[s_AUENVVARCOUNT];
  71. HRESULT GetStringValue(int index, LPTSTR buf, DWORD dwCchSize);
  72. BOOL GetBOOLEnvironmentVar(LPCTSTR szEnvVar, BOOL *pfVal);
  73. BOOL GetDWordEnvironmentVar(LPCTSTR szEnvVar, DWORD *pdwVal);
  74. BOOL GetStringEnvironmentVar(LPCTSTR szzEnvVar, LPTSTR szBuf, DWORD dwSize);
  75. };
  76. //////////////// The following functions are all called from the outside! ///////////////////////
  77. /////////////////////////////////////////////////////////////////////
  78. // cfreg.cpp - Functions to handle registry keys
  79. /////////////////////////////////////////////////////////////////////
  80. BOOL fRegKeyCreate(LPCTSTR tszKey, DWORD dwOptions);
  81. BOOL fRegKeyExists(LPCTSTR tszSubKey, HKEY hRootKey = HKEY_LOCAL_MACHINE);
  82. inline HRESULT String2FileTime(LPCTSTR pszDateTime, FILETIME *pft)
  83. {
  84. SYSTEMTIME st;
  85. HRESULT hr = String2SystemTime(pszDateTime, &st);
  86. if ( SUCCEEDED(hr) )
  87. {
  88. if ( !SystemTimeToFileTime(&st, pft) )
  89. {
  90. hr = HRESULT_FROM_WIN32(GetLastError());
  91. }
  92. }
  93. return hr;
  94. }
  95. inline HRESULT FileTime2String(FILETIME & ft, LPTSTR pszDateTime, size_t cchSize)
  96. {
  97. SYSTEMTIME st;
  98. HRESULT hr;
  99. if ( !FileTimeToSystemTime(&ft, &st) )
  100. {
  101. hr = HRESULT_FROM_WIN32(GetLastError());
  102. }
  103. else
  104. {
  105. hr = SystemTime2String(st, pszDateTime, cchSize);
  106. }
  107. return hr;
  108. }
  109. BOOL FHiddenItemsExist();
  110. HRESULT setAddedTimeout(DWORD timeout, LPCTSTR strkey);
  111. HRESULT getAddedTimeout(DWORD *pdwTimeDiff, LPCTSTR strkey);
  112. extern const TCHAR AUREGKEY_REBOOT_REQUIRED[]; // = _T("Software\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired");
  113. inline BOOL fSetRebootFlag(void)
  114. {
  115. return fRegKeyCreate(AUREGKEY_REBOOT_REQUIRED, REG_OPTION_VOLATILE);
  116. }
  117. inline BOOL fRegKeyDelete(LPCTSTR tszKey)
  118. {
  119. return (ERROR_SUCCESS == RegDeleteKey(HKEY_LOCAL_MACHINE, tszKey));
  120. }
  121. inline BOOL fCheckRebootFlag(void)
  122. {
  123. return fRegKeyExists(AUREGKEY_REBOOT_REQUIRED);
  124. }
  125. /////////////////////////////////////////////////////////////////////
  126. // helpers.cpp
  127. /////////////////////////////////////////////////////////////////////
  128. DWORD getTimeOut();
  129. HRESULT TimeAddSeconds(SYSTEMTIME tmBase, int iSeconds, SYSTEMTIME* pTimeNew);
  130. inline void setTimeOut(DWORD dwTimeOut)
  131. {
  132. SetRegDWordValue(_T("TimeOut"), dwTimeOut);
  133. }
  134. BOOL IsRTFDownloaded(BSTR bstrRTFPath, LANGID langid);
  135. BOOL FHiddenItemsExist(void);
  136. BOOL RemoveHiddenItems(void);
  137. void DisableUserInput(HWND hwnd);
  138. BOOL Hours2LocalizedString(SYSTEMTIME *pst, LPTSTR ptszBuffer, DWORD cbSize);
  139. BOOL FillHrsCombo(HWND hwnd, DWORD dwSchedInstallTime);
  140. BOOL FillDaysCombo(HINSTANCE hInstance, HWND hwnd, DWORD dwSchedInstallDay, UINT uMinResId, UINT uMaxResId);
  141. BOOL fAccessibleToAU(void);
  142. BOOL IsWin2K(void);
  143. extern const LPTSTR HIDDEN_ITEMS_FILE;
  144. //////////////////////////////////////////////////////////////////////////////////////
  145. // platform.cpp
  146. //////////////////////////////////////////////////////////////////////////////////////
  147. void GetOSName(LPTSTR _szOSName);
  148. UINT DetectPlatformID(void);
  149. HRESULT GetOSVersionStr(LPTSTR tszbuf, UINT uSize);
  150. BOOL fIsPersonalOrProfessional(void);
  151. HRESULT GetFileVersionStr(LPCTSTR tszFile, LPTSTR tszbuf, UINT uSize);
  152. const TCHAR g_szPropDialogPtr[] = TEXT("AutoUpdateProp_DialogPtr");
  153. const TCHAR g_szHelpFile[] = _T("wuauhelp.chm::/auw2ktt.txt"); //TEXT("sysdm.hlp"); //used on both w2k and xp.
  154. const TCHAR gtszAUOverviewUrl[] = _T("wuauhelp.chm"); //default
  155. const TCHAR gtszAUW2kSchedInstallUrl[] = _T("wuauhelp.chm::/w2k_autoupdate_sched.htm");
  156. const TCHAR gtszAUXPSchedInstallUrl[] = _T("wuauhelp.chm::/autoupdate_sched.htm");
  157. const TCHAR REG_AUNOAUTOREBOOTWITHLOGGEDONUSERS[] = _T("NoAutoRebootWithLoggedOnUsers"); //REG_DWORD
  158. //////////////////////////////////////////////////////////////////////////////////////
  159. // DEBUG STUFF //
  160. //////////////////////////////////////////////////////////////////////////////////////
  161. #ifdef DBG
  162. //===== DBG ==========================================================================
  163. void _cdecl WUAUTrace(char* pszFormat, ...);
  164. #define DEBUGMSG WUAUTrace
  165. inline BOOL fAUAssertBreak(void)
  166. {
  167. static DWORD dwVal = -1;
  168. if (-1 != dwVal)
  169. {
  170. return 1 == dwVal;
  171. }
  172. if (FAILED(GetRegDWordValue(_T("AssertBreak"), &dwVal)))
  173. { //if key is not there, don't read again and again
  174. dwVal = 0;
  175. }
  176. return 1 == dwVal;
  177. }
  178. #define AUASSERT(x) { if (!(x) && fAUAssertBreak()) DebugBreak();}
  179. #else // !DBG
  180. //===== !DBG ==========================================================================
  181. inline void _cdecl WUAUTrace(char* , ...) {}
  182. #define DEBUGMSG WUAUTrace
  183. #define AUASSERT(x)
  184. #endif // DBG
  185. //=====================================================================================