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.

267 lines
7.6 KiB

  1. /*
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. UnAttend.cpp
  5. Abstract:
  6. Reads entries from the ini file and adds them to the registry.We assume that the
  7. ini file key name and registry key name are the same.
  8. Revision History:
  9. created a-josem 12/11/00
  10. revised a-josem 12/12/00 Changed TCHAR to WCHAR, moved the global variables to
  11. local scope.
  12. */
  13. #include "UnAttend.h"
  14. /*
  15. This generic structure has the Key Name, datatype of the key and iterate says if
  16. the Key Name is to be appended with 1,2,3.. or used directly.
  17. */
  18. struct RegEntries
  19. {
  20. WCHAR strIniKey[MAX_PATH];//Name of the key in the Ini file
  21. WCHAR strKey[MAX_PATH]; //Name of the key in the registry
  22. DWORD dwType; //Type of the key to be used when writing into the registry
  23. BOOL bIterate; //TRUE or FALSE for iterating 1,2,3,....
  24. };
  25. #define ARRAYSIZE(a) (sizeof(a)/sizeof(*a))
  26. //Section name in the registry.
  27. static const WCHAR strSection[] = L"PCHealth";
  28. static const WCHAR strErrorReportingSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\";
  29. static const RegEntries ErrorReportingRegEntries[] =
  30. {
  31. {L"ER_Display_UI",L"ShowUI",REG_DWORD,FALSE},
  32. {L"ER_Enable_Kernel_Errors",L"IncludeKernelFaults",REG_DWORD,FALSE},
  33. {L"ER_Enable_Reporting",L"DoReport",REG_DWORD,FALSE},
  34. {L"ER_Enable_Windows_Components",L"IncludeWindowsApps",REG_DWORD,FALSE},
  35. {L"ER_Include_MSApps",L"IncludeMicrosoftApps",REG_DWORD,FALSE},
  36. {L"ER_ Force_Queue_Mode",L"ForceQueueMode",REG_DWORD,FALSE},
  37. {L"ER_ Include_Shutdowns_Errs",L"IncludeShutdownsErrs",REG_DWORD,FALSE},
  38. };
  39. static const WCHAR strExclusionSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\ExclusionList\\";
  40. static const RegEntries ExclusionRegEntries[] =
  41. {
  42. {L"ER_Exclude_EXE",L"",REG_DWORD,TRUE}
  43. };
  44. static const WCHAR strInclusionSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\InclusionList\\";
  45. static const RegEntries InclusionRegEntries[] =
  46. {
  47. {L"ER_Include_EXE",L"",REG_DWORD,TRUE}
  48. };
  49. static const WCHAR strDWSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\DW\\";
  50. static const RegEntries DWRegEntries[] =
  51. {
  52. {L"ER_Report_Path",L"DWFileTreeRoot",REG_SZ,FALSE},
  53. {L"ER_No_External_URLs",L"DWNoExternalURL",REG_DWORD,FALSE},
  54. {L"ER_No_File_Collection",L"DWNoFileCollection",REG_DWORD,FALSE},
  55. {L"ER_No_Data_Collection",L"DWNoSecondLevelCollection",REG_DWORD,FALSE},
  56. };
  57. static const WCHAR strTerminalServerSubKey[] = L"SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\";
  58. static const RegEntries TerminalServerRegEntries[] =
  59. {
  60. {L"RA_AllowToGetHelp",L"fAllowToGetHelp",REG_DWORD,FALSE},
  61. {L"RA_AllowUnSolicited",L"fAllowUnsolicited",REG_DWORD,FALSE},
  62. {L"RA_AllowFullControl",L"fAllowFullControl",REG_DWORD,FALSE},
  63. {L"RA_AllowRemoteAssistance",L"fAllowRemoteAssistance",REG_DWORD,FALSE},
  64. {L"RA_MaxTicketExpiry",L"MaxTicketExpiry",REG_DWORD,FALSE},
  65. };
  66. /*++
  67. Routine Description:
  68. Reads ini file and adds those values in the registry
  69. Arguments:
  70. lpstrSubKey - SubKey under which the entries are to be made.
  71. arrRegEntries - Array of RegEntries structure
  72. nCount - Count of elements in the array.
  73. Return Value:
  74. TRUE or FALSE depending on the Registry key opening.
  75. --*/
  76. static BOOL UnAttendedSetup(LPCWSTR lpstrSubKey,const RegEntries *arrRegEntries,int nCount)
  77. {
  78. //Ini File Path Temprorary path will be overwritten.
  79. WCHAR strFilePath[MAX_PATH];// = L"C:\\PCHealth.ini";
  80. BOOL fRetVal = TRUE;
  81. HKEY hKey = NULL;
  82. //The Key already exists just open the key.
  83. // BUGBUG: Change this to Create
  84. // Did the changes
  85. DWORD dwDisposition = 0;
  86. if (ERROR_SUCCESS != ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,lpstrSubKey,0,NULL,
  87. REG_OPTION_VOLATILE,KEY_WRITE,NULL,&hKey,&dwDisposition))
  88. {
  89. fRetVal = FALSE;
  90. goto doneUnAttend;
  91. }
  92. //Comment out the following three lines for testing purposes.
  93. GetSystemDirectory(strFilePath,MAX_PATH);
  94. lstrcat(strFilePath,TEXT("\\"));
  95. lstrcat(strFilePath,WINNT_GUI_FILE);
  96. ///////
  97. WCHAR strRetVal[MAX_PATH];
  98. for (int nIndex = 0; nIndex < nCount; nIndex++)
  99. {
  100. if (arrRegEntries[nIndex].bIterate == FALSE)
  101. {
  102. if (GetPrivateProfileString(strSection,arrRegEntries[nIndex].strIniKey,
  103. NULL,strRetVal,MAX_PATH,strFilePath) != 0)
  104. {
  105. if (arrRegEntries[nIndex].dwType == REG_DWORD)
  106. {
  107. DWORD nVal = 0;
  108. nVal = _wtoi(strRetVal);
  109. RegSetValueEx(hKey,arrRegEntries[nIndex].strKey,0,REG_DWORD,
  110. (unsigned char *)&nVal,sizeof(DWORD));
  111. }
  112. else if (arrRegEntries[nIndex].dwType == REG_SZ)
  113. {
  114. RegSetValueEx(hKey,arrRegEntries[nIndex].strKey,0,REG_SZ,
  115. (LPBYTE)strRetVal, (lstrlen(strRetVal) + 1) * sizeof(WCHAR) );
  116. }
  117. }
  118. }
  119. else
  120. {
  121. if(arrRegEntries[nIndex].dwType == REG_DWORD)
  122. {
  123. int nCount = 0;
  124. int nFileIndex = 0;
  125. do
  126. {
  127. WCHAR strFileTagName[MAX_PATH];
  128. WCHAR strI[10];
  129. lstrcpy(strFileTagName,arrRegEntries[nIndex].strIniKey);
  130. _itow(++nFileIndex,strI,10);
  131. lstrcat(strFileTagName,strI);
  132. nCount = GetPrivateProfileString(strSection,strFileTagName,0,
  133. strRetVal,MAX_PATH,strFilePath);
  134. if (nCount)
  135. {
  136. DWORD dwVal = 1;
  137. RegSetValueEx(hKey,strRetVal,0,REG_DWORD,
  138. (unsigned char*)&dwVal,sizeof(DWORD));
  139. }
  140. }while(nCount);
  141. }
  142. }
  143. }
  144. doneUnAttend:
  145. if (hKey)
  146. RegCloseKey(hKey);
  147. return fRetVal;
  148. }
  149. /*++
  150. Routine Description:
  151. Handles the special case of ER_Enable_Application
  152. Arguments:
  153. lpstrSubKey - SubKey under which the entries are to be made.
  154. Return Value:
  155. TRUE or FALSE depending on the Registry key opening.
  156. --*/
  157. static BOOL SpecialCases(LPCWSTR lpstrSubKey)
  158. {
  159. //Ini File Path temprorary path will be overwritten.
  160. WCHAR strFilePath[MAX_PATH];// = L"C:\\PCHealth.ini";
  161. BOOL fRetVal = TRUE;
  162. //Handling special cases
  163. WCHAR strRetVal[MAX_PATH];
  164. HKEY hKey = NULL;
  165. DWORD dwDisposition = 0;
  166. if (ERROR_SUCCESS != ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,lpstrSubKey,0,NULL,
  167. REG_OPTION_VOLATILE,KEY_WRITE,NULL,&hKey,&dwDisposition))
  168. {
  169. fRetVal = FALSE;
  170. goto done;
  171. }
  172. //Comment out the following three lines for testing purposes.
  173. GetSystemDirectory(strFilePath,MAX_PATH);
  174. lstrcat(strFilePath,TEXT("\\"));
  175. lstrcat(strFilePath,WINNT_GUI_FILE);
  176. ///////
  177. if (GetPrivateProfileString(strSection,TEXT("ER_Enable_Applications"),NULL,
  178. strRetVal,MAX_PATH,strFilePath) != 0)
  179. {
  180. DWORD nVal = 0;
  181. if (!lstrcmpi(L"all",strRetVal))
  182. {
  183. nVal = 1;
  184. RegSetValueEx(hKey,L"AllOrNone",0,REG_DWORD,
  185. (unsigned char *)&nVal,sizeof(DWORD));
  186. }
  187. else if (!lstrcmpi(L"Listed",strRetVal))
  188. {
  189. nVal = 0;
  190. RegSetValueEx(hKey,L"AllOrNone",0,REG_DWORD,
  191. (unsigned char *)&nVal,sizeof(DWORD));
  192. }
  193. else if (!lstrcmpi(L"None",strRetVal))
  194. {
  195. nVal = 2;
  196. RegSetValueEx(hKey,L"AllOrNone",0,REG_DWORD,
  197. (unsigned char *)&nVal,sizeof(DWORD));
  198. }
  199. }
  200. done:
  201. if (hKey)
  202. RegCloseKey(hKey);
  203. return fRetVal;
  204. }
  205. /*++
  206. Routine Description:
  207. To be called from Register Server.
  208. Arguments:
  209. None
  210. Return Value:
  211. TRUE or FALSE depending on the Registry key opening.
  212. --*/
  213. BOOL PCHealthUnAttendedSetup()
  214. {
  215. BOOL bRetVal1,bRetVal2,bRetVal3,bRetVal4,bRetVal5;
  216. SpecialCases(strErrorReportingSubKey);
  217. bRetVal1 = UnAttendedSetup(strErrorReportingSubKey,
  218. ErrorReportingRegEntries,ARRAYSIZE(ErrorReportingRegEntries));
  219. bRetVal2 = UnAttendedSetup(strExclusionSubKey,ExclusionRegEntries,
  220. ARRAYSIZE(ExclusionRegEntries));
  221. bRetVal3 = UnAttendedSetup(strInclusionSubKey,InclusionRegEntries,
  222. ARRAYSIZE(InclusionRegEntries));
  223. bRetVal4 = UnAttendedSetup(strDWSubKey,DWRegEntries,ARRAYSIZE(DWRegEntries));
  224. bRetVal5 = UnAttendedSetup(strTerminalServerSubKey,TerminalServerRegEntries,
  225. ARRAYSIZE(TerminalServerRegEntries));
  226. if ((bRetVal1== TRUE) && (bRetVal2 == TRUE) && (bRetVal3 == TRUE) &&
  227. (bRetVal4 == TRUE) && (bRetVal5 == TRUE))
  228. return TRUE;
  229. else
  230. return FALSE;
  231. }