Source code of Windows XP (NT5)
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.

432 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Precomp.h
  5. Abstract:
  6. Precompiled header file. Contains constants,
  7. function prototypes, macros, and structures used
  8. throughout the app.
  9. Notes:
  10. Unicode only.
  11. History:
  12. 03/02/2001 rparsons Created
  13. --*/
  14. #ifndef _X86_
  15. #define _X86_
  16. #endif
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <imagehlp.h>
  22. #include <shlwapi.h>
  23. #include <aclapi.h>
  24. #include <shellapi.h>
  25. #include <setupapi.h>
  26. extern "C" {
  27. #include <spapip.h>
  28. #include <sfcapip.h>
  29. }
  30. #include <stdio.h>
  31. #include <stdarg.h>
  32. #include <mscat.h>
  33. #include "resource.h"
  34. #include "eventlog.h"
  35. #include "registry.h"
  36. #include "enumdir.h"
  37. #include "cqueue.h"
  38. #include "wumsg.h"
  39. #define ACCESS_READ 1
  40. #define ACCESS_WRITE 2
  41. #define ERROR 0
  42. #define WARNING 1
  43. #define TRACE 2
  44. #define MAX_QUEUE_SIZE MAX_PATH*2
  45. #define INF_FILE_NAMEW L"wuinst.inf"
  46. #define INF_FILE_NAMEA "wuinst.inf"
  47. #define UNINST_INF_FILE_NAMEW L"wuuninst.inf"
  48. #define UNINST_INF_FILE_NAMEA "wuuninst.inf"
  49. #define INF_MASTER_SECTIONS "Sections"
  50. //
  51. // Section names for install INF
  52. //
  53. #define INF_CAT_SECTION_NAME "CatalogsToInstall"
  54. #define INF_BACKUP_FILES "Backup.Files"
  55. #define INF_BACKUP_REGISTRY "Backup.Registry"
  56. #define INF_COPY_FILES "Copy.Files"
  57. #define INF_REGISTRATIONS "Registrations"
  58. #define INF_ADD_REGISTRY "Add.Registry.Keys"
  59. #define INF_VERSION_INFO "Registry.Data"
  60. //
  61. // Section names for uninstall INF
  62. //
  63. #define INF_RESTORE_FILES "Restore.Files"
  64. #define INF_RESTORE_REGISTRY "Restore.Registry.Keys"
  65. #define INF_RESTORE_REGISTRYW L"Restore.Registry.Keys"
  66. #define INF_UNREGISTRATIONS "UnRegistrations"
  67. #define INF_UNREGISTRATIONSW L"UnRegistrations"
  68. //
  69. // Common to both
  70. //
  71. #define INF_PROCESSES_TO_RUN "ProcessesToRun"
  72. #define INF_DELETE_REGISTRY "Delete.Registry.Keys"
  73. #define INF_DELETE_REGISTRYW L"Delete.Registry.Keys"
  74. #define INF_EXCLUDE "Exclusions"
  75. #define dwBackupFiles ((DWORD)0x0001)
  76. #define dwBackupRegistry ((DWORD)0x0002)
  77. #define dwDeleteRegistry ((DWORD)0x0003)
  78. #define dwCopyFiles ((DWORD)0x0004)
  79. #define dwRegistrations ((DWORD)0x0005)
  80. #define dwExclusionsInstall ((DWORD)0x0006)
  81. #define dwExclusionsUninstall ((DWORD)0x0007)
  82. #define dwRestoreFiles ((DWORD)0x0008)
  83. #define dwRestoreRegistry ((DWORD)0x0009)
  84. #define dwUnRegistrations ((DWORD)0x0010)
  85. #define dwAddRegistry ((DWORD)0x0011)
  86. #define REG_DISPLAY_NAME L"DisplayName"
  87. #define REG_UNINSTALL_STRING L"UninstallString"
  88. #define UNINSTALL_SWITCH L"-u"
  89. #define REG_PROT_RENAMES L"AllowProtectedRenames"
  90. #define REG_ACTIVE_SETUP L"SOFTWARE\\Microsoft\\Active Setup\\Installed Components"
  91. #define REG_UNINSTALL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
  92. #define REG_WINFP_PATH L"SOFTWARE\\Policies\\Microsoft\\Windows NT\\Windows File Protection"
  93. #define REG_WINLOGON_PATH L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"
  94. #define REG_INSTALL_SOURCES L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup"
  95. #define REG_SESSION_MANAGER L"System\\CurrentControlSet\\Control\\Session Manager"
  96. #define LOAD_STRING_FAILED L"Unable to load a string from the module."
  97. #define MALLOC(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s))
  98. #define REALLOC(s,b) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s),(b))
  99. #define FREE(b) HeapFree(GetProcessHeap(),0,(b))
  100. //
  101. // Structures
  102. //
  103. typedef struct _tagSETUPINFO {
  104. HINSTANCE hInstance;
  105. HINF hInf;
  106. UINT nErrorLevel;
  107. BOOL fInstall;
  108. BOOL fQuiet;
  109. BOOL fForceInstall;
  110. BOOL fNoReboot;
  111. BOOL fNoUninstall;
  112. BOOL fEventSourceCreated;
  113. BOOL fNeedToAdjustACL;
  114. BOOL fOnWin2K;
  115. BOOL fCanUninstall;
  116. BOOL fSourceDirAdded;
  117. BOOL fUpdateDllCache;
  118. WCHAR wszDebugOut[2048];
  119. LPWSTR lpwUninstallINFPath;
  120. LPWSTR lpwInstallINFPath;
  121. LPWSTR lpwExtractPath;
  122. LPWSTR lpwMessageBoxTitle;
  123. LPWSTR lpwPrettyAppName;
  124. LPWSTR lpwInstallDirectory;
  125. LPWSTR lpwUninstallDirectory;
  126. LPWSTR lpwWindowsDirectory;
  127. LPWSTR lpwSystem32Directory;
  128. LPWSTR lpwEventLogSourceName;
  129. DWORD dwRequiredFreeSpaceNoUninstall;
  130. DWORD dwRequiredFreeSpaceWithUninstall;
  131. DWORDLONG dwlUpdateVersion;
  132. CQueue BackupFileQueue;
  133. CQueue BackupRegistryQueue;
  134. CQueue CopyFileQueue;
  135. CQueue DeleteRegistryQueue;
  136. CQueue RegistrationQueue;
  137. CQueue ExclusionQueue;
  138. CQueue RestoreRegistryQueue;
  139. CQueue RestoreFileQueue;
  140. CQueue AddRegistryQueue;
  141. } SETUP_INFO, *LPSETUP_INFO;
  142. //
  143. // Functions contained in wumain.cpp
  144. //
  145. BOOL DoInstallation();
  146. BOOL DoUninstallation();
  147. //
  148. // Functions contained in wuinst.cpp
  149. //
  150. int InstallCheckVersion();
  151. BOOL InstallBackupFiles();
  152. BOOL InstallCopyFiles();
  153. BOOL InstallWriteUninstallKey();
  154. BOOL InstallRunINFProcesses();
  155. BOOL InstallGetSectionsFromINF();
  156. BOOL InstallBackupRegistryKeys();
  157. BOOL InstallRegistryData();
  158. BOOL InstallCatalogFiles(
  159. IN HINF hInf,
  160. IN LPCWSTR lpwSourcePath
  161. );
  162. BOOL
  163. InstallWFPFile(
  164. IN LPCWSTR lpwSourceFileName,
  165. IN LPCWSTR lpwDestFileName,
  166. IN LPCWSTR lpwDestFileNamePath,
  167. IN BOOL fUpdateDllCache
  168. );
  169. BOOL
  170. InstallPrepareDirectory(
  171. IN LPWSTR lpwDirectoryPath,
  172. IN DWORD dwAttributes
  173. );
  174. //
  175. // Functions contained in wufns.cpp
  176. //
  177. BOOL CommonDeleteRegistryKeys();
  178. BOOL CommonEnableProtectedRenames();
  179. BOOL CommonRegisterServers(
  180. IN BOOL fRegister
  181. );
  182. BOOL
  183. CommonRemoveDirectoryAndFiles(
  184. IN LPCWSTR lpwDirectoryPath,
  185. IN PVOID pEnumerateParameter,
  186. IN BOOL fRemoveDirectory,
  187. IN BOOL fRemoveSubDirs
  188. );
  189. LPWSTR
  190. GetNextToken(
  191. IN LPWSTR lpwSourceString,
  192. IN LPCWSTR lpwSeparator
  193. );
  194. BOOL
  195. ForceMove(
  196. IN LPCWSTR lpwSourceFileName,
  197. IN LPCWSTR lpwDestFileName
  198. );
  199. BOOL
  200. ForceDelete(
  201. IN LPCWSTR lpwFileName
  202. );
  203. BOOL
  204. ForceCopy(
  205. IN LPCWSTR lpwSourceFileName,
  206. IN LPCWSTR lpwDestFileName
  207. );
  208. BOOL
  209. IsFileProtected(
  210. IN LPCWSTR lpwFileName
  211. );
  212. DWORD
  213. pInstallCatalogFile(
  214. IN LPCWSTR lpwCatalogFullPath,
  215. IN LPCWSTR lpwNewBaseName
  216. );
  217. BOOL
  218. GetVersionInfoFromImage(
  219. IN LPCWSTR lpwFileName,
  220. OUT PDWORDLONG pdwVersion
  221. );
  222. LPWSTR
  223. CopyTempFile(
  224. IN LPCWSTR lpwSrcFileName,
  225. IN LPCWSTR lpwDestDir
  226. );
  227. BOOL
  228. ParseCommandLine();
  229. BOOL
  230. IsAnotherInstanceRunning(
  231. IN LPCWSTR lpwInstanceName
  232. );
  233. BOOL
  234. AdjustDirectoryPerms(
  235. IN LPWSTR lpwDirPath
  236. );
  237. BOOL
  238. DeleteOneFile(
  239. IN LPCWSTR lpwPath,
  240. IN PWIN32_FIND_DATA pFindFileData,
  241. IN PVOID pEnumerateParameter
  242. );
  243. BOOL
  244. MirrorDirectoryPerms(
  245. IN LPWSTR lpwSourceDir,
  246. IN LPWSTR lpwDestDir
  247. );
  248. DWORD
  249. GetCatVersion(
  250. IN LPWSTR lpwCatName
  251. );
  252. LPWSTR
  253. GetCurWorkingDirectory();
  254. int
  255. IsUserAnAdministrator();
  256. void
  257. pUnicodeToAnsi(
  258. IN LPCWSTR lpwUnicodeString,
  259. IN OUT LPSTR lpAnsiString,
  260. IN int nLen
  261. );
  262. void
  263. pAnsiToUnicode(
  264. IN LPCSTR lpAnsiString,
  265. IN OUT LPWSTR lpwUnicodeString,
  266. IN int nLen
  267. );
  268. #if DBG
  269. void _cdecl Print(
  270. IN UINT uLevel,
  271. IN LPWSTR lpwFmt,
  272. IN ...
  273. );
  274. #else
  275. #define Print
  276. #endif
  277. BOOL
  278. WUInitialize();
  279. void
  280. WUCleanup();
  281. DWORDLONG
  282. GetDiskSpaceFreeOnNTDrive();
  283. BOOL
  284. DisplayErrMsg(
  285. IN HWND hWnd,
  286. IN DWORD dwMessageId,
  287. IN LPWSTR lpwMessageArray
  288. );
  289. BOOL
  290. GetInfValue(
  291. IN HINF hInf,
  292. IN LPCSTR lpSectionName,
  293. IN LPCSTR lpKeyName,
  294. OUT PDWORD pdwValue
  295. );
  296. BOOL
  297. VersionStringToNumber(
  298. IN LPCWSTR lpwVersionString,
  299. IN OUT DWORDLONG *lpVersionNumber
  300. );
  301. BOOL
  302. LaunchProcessAndWait(
  303. IN LPCWSTR lpwCommandLine,
  304. OUT PDWORD pdwReturnCode
  305. );
  306. BOOL
  307. ModifyTokenPrivilege(
  308. IN LPCWSTR lpwPrivilege,
  309. IN BOOL fEnable
  310. );
  311. BOOL
  312. ShutdownSystem(
  313. IN BOOL fForceClose,
  314. IN BOOL fReboot
  315. );
  316. BOOL SaveEntryToINF(
  317. IN LPCWSTR lpwSectionName,
  318. IN LPCWSTR lpwKeyName,
  319. IN LPCWSTR lpwEntryName,
  320. IN LPCWSTR lpwFileName
  321. );
  322. //
  323. // Functions contained in wulog.cpp
  324. //
  325. void
  326. LogWUEvent(
  327. IN WORD wType,
  328. IN DWORD dwEventID,
  329. IN WORD wNumStrings,
  330. IN LPCWSTR *lpwStrings
  331. );
  332. BOOL
  333. LogEventDisplayError(
  334. IN WORD wType,
  335. IN DWORD dwEventID,
  336. IN BOOL fDisplayErr,
  337. IN BOOL fCritical
  338. );
  339. //
  340. // Functions contained in wuuninst.cpp
  341. //
  342. BOOL UninstallGetSectionsFromINF();
  343. BOOL UninstallRestoreRegistryKeys();
  344. BOOL UninstallRemoveFiles();
  345. BOOL UninstallRestoreFiles();
  346. void UninstallCustomWorker();
  347. void
  348. UninstallDeleteSubKey(
  349. IN LPCWSTR lpwKey,
  350. IN LPCWSTR lpwSubKey
  351. );
  352. BOOL
  353. UninstallWFPFile(
  354. IN LPCWSTR lpwSourceFileName,
  355. IN LPCWSTR lpwDestFileName,
  356. IN LPCWSTR lpwDestFileNamePath,
  357. IN BOOL fUpdateDllCache
  358. );