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.

100 lines
2.5 KiB

  1. //***************************************************************************
  2. //
  3. // UTILS.CPP
  4. //
  5. // Module: WMI Instance provider code for boot parameters
  6. //
  7. // Purpose: General purpose utilities.
  8. //
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. //***************************************************************************
  12. #include <objbase.h>
  13. #include "bootini.h"
  14. LPTSTR IDS_RegBootDirKey = _T("BootDir");
  15. LPTSTR IDS_BootIni = _T("boot.ini");
  16. LPTSTR IDS_CBootIni = _T("c:\\boot.ini");
  17. LPTSTR IDS_RegCurrentNTVersionSetup = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup");
  18. PCHAR
  19. GetBootFileName(
  20. )
  21. {
  22. HKEY h_key;
  23. LPTSTR data = NULL;
  24. DWORD cbdata;
  25. DWORD type;
  26. LONG ret;
  27. ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  28. IDS_RegCurrentNTVersionSetup,
  29. 0,
  30. KEY_READ,
  31. &h_key
  32. );
  33. if (ret != ERROR_SUCCESS) {
  34. return NULL;
  35. }
  36. cbdata = 0;
  37. ret = RegQueryValueEx(h_key,
  38. IDS_RegBootDirKey,
  39. NULL,
  40. &type,
  41. (LPBYTE) data,
  42. &cbdata
  43. );
  44. if(ret == ERROR_MORE_DATA){
  45. data = (LPTSTR) BPAlloc(cbdata +
  46. (_tcslen(IDS_BootIni)+1)*sizeof(TCHAR));
  47. ret=RegQueryValueEx(h_key,
  48. IDS_RegBootDirKey,
  49. NULL,
  50. &type,
  51. (LPBYTE) data,
  52. &cbdata
  53. );
  54. }
  55. else{
  56. data = (LPTSTR) BPAlloc((_tcslen(IDS_CBootIni)+1)*sizeof(TCHAR));
  57. }
  58. if(data){
  59. _tcscat(data, IDS_CBootIni);
  60. }
  61. else{
  62. return NULL;
  63. }
  64. return data;
  65. }
  66. HANDLE GetFileHandle(PCHAR data,
  67. DWORD dwCreationDisposition,
  68. DWORD dwAccess
  69. )
  70. {
  71. LONG ret;
  72. if(!data){
  73. return INVALID_HANDLE_VALUE;
  74. }
  75. HANDLE h = CreateFile(data,
  76. dwAccess,
  77. FILE_SHARE_READ, // Exclusive Write Access
  78. NULL,
  79. dwCreationDisposition,
  80. 0,
  81. NULL
  82. ) ;
  83. if(INVALID_HANDLE_VALUE==h){
  84. ret=GetLastError();
  85. }
  86. return h;
  87. }