|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1993 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: registry.c ! 8: ! 9: Abstract: ! 10: ! 11: This file implements the apis for DRWTSN32 to access the registry. ! 12: All access to the registry are done in this file. If additional ! 13: registry control is needed then a function should be added in this file ! 14: and exposed to the other files in DRWTSN32. ! 15: ! 16: Author: ! 17: ! 18: Wesley Witt (wesw) 1-May-1993 ! 19: ! 20: Environment: ! 21: ! 22: User Mode ! 23: ! 24: --*/ ! 25: ! 26: #include <windows.h> ! 27: #include <stdlib.h> ! 28: #include <stdio.h> ! 29: #include <string.h> ! 30: ! 31: #include "drwatson.h" ! 32: #include "proto.h" ! 33: #include "messages.h" ! 34: ! 35: ! 36: // ! 37: // string constants for accessing the registry ! 38: // there is a string constant here for each key and each value ! 39: // that is accessed in the registry. ! 40: // ! 41: #define DRWATSON_EXE_NAME "drwtsn32.exe" ! 42: #define REGKEY_SOFTWARE "software\\microsoft" ! 43: #define REGKEY_MESSAGEFILE "EventMessageFile" ! 44: #define REGKEY_TYPESSUPP "TypesSupported" ! 45: #define REGKEY_SYSTEMROOT "%SystemRoot%\\System32\\" ! 46: #define REGKEY_EVENTLOG "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" ! 47: #define REGKEY_APPNAME "ApplicationName" ! 48: #define REGKEY_FUNCTION "FunctionName" ! 49: #define REGKEY_EXCEPTIONCODE "ExceptionCode" ! 50: #define REGKEY_ADDRESS "Address" ! 51: #define REGKEY_LOG_PATH "LogFilePath" ! 52: #define REGKEY_DUMPSYMBOLS "DumpSymbols" ! 53: #define REGKEY_DUMPALLTHREADS "DumpAllThreads" ! 54: #define REGKEY_APPENDTOLOGFILE "AppendToLogFile" ! 55: #define REGKEY_INSTRUCTIONS "Instructions" ! 56: #define REGKEY_VISUAL "VisualNotification" ! 57: #define REGKEY_SOUND "SoundNotification" ! 58: #define REGKEY_WAVE_FILE "WaveFile" ! 59: #define REGKEY_NUM_CRASHES "NumberOfCrashes" ! 60: #define REGKEY_MAX_CRASHES "MaximumCrashes" ! 61: #define REGKEY_CURRENTVERSION "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" ! 62: #define REGKEY_CURRENT_BUILD "CurrentBuild" ! 63: #define REGKEY_CURRENT_TYPE "CurrentType" ! 64: #define REGKEY_REG_ORGANIZATION "RegisteredOrganization" ! 65: #define REGKEY_REG_OWNER "RegisteredOwner" ! 66: #define REGKEY_AEDEBUG "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug" ! 67: #define REGKEY_AUTO "Auto" ! 68: #define REGKEY_DEBUGGER "Debugger" ! 69: ! 70: ! 71: // ! 72: // local prototypes ! 73: // ! 74: void RegSetDWORD( HKEY hkey, char *szSubKey, DWORD dwValue ); ! 75: void RegSetBOOL( HKEY hkey, char *szSubKey, BOOL dwValue ); ! 76: void RegSetSZ( HKEY hkey, char *szSubKey, char *szValue ); ! 77: void RegSetEXPANDSZ( HKEY hkey, char *szSubKey, char *szValue ); ! 78: BOOL RegQueryBOOL( HKEY hkey, char *szSubKey ); ! 79: DWORD RegQueryDWORD( HKEY hkey, char *szSubKey ); ! 80: void RegQuerySZ( HKEY hkey, char *szSubKey, char *szValue ); ! 81: BOOL RegSaveAllValues( HKEY hKeyDrWatson, POPTIONS o ); ! 82: BOOL RegGetAllValues( POPTIONS o, HKEY hKeyDrWatson ); ! 83: BOOL RegInitializeDefaults( HKEY hKeyDrWatson ); ! 84: HKEY RegGetAppKey( void ); ! 85: BOOL RegCreateEventSource( void ); ! 86: ! 87: ! 88: ! 89: BOOL ! 90: RegGetAllValues( POPTIONS o, HKEY hKeyDrWatson ) ! 91: ! 92: /*++ ! 93: ! 94: Routine Description: ! 95: ! 96: This functions retrieves all registry data for DRWTSN32 and puts ! 97: the data in the OPTIONS structure passed in. ! 98: ! 99: Arguments: ! 100: ! 101: o - pointer to an OPTIONS structure ! 102: hKeyDrWatson - handle to a registry key for DRWTSN32 registry data ! 103: ! 104: Return Value: ! 105: ! 106: TRUE - retrieved all data without error ! 107: FALSE - errors occurred and did not get all data ! 108: ! 109: --*/ ! 110: ! 111: { ! 112: RegQuerySZ( hKeyDrWatson, REGKEY_LOG_PATH, o->szLogPath ); ! 113: RegQuerySZ( hKeyDrWatson, REGKEY_WAVE_FILE, o->szWaveFile ); ! 114: o->fDumpSymbols = RegQueryBOOL( hKeyDrWatson, REGKEY_DUMPSYMBOLS ); ! 115: o->fDumpAllThreads = RegQueryBOOL( hKeyDrWatson, REGKEY_DUMPALLTHREADS ); ! 116: o->fAppendToLogFile = RegQueryBOOL( hKeyDrWatson, REGKEY_APPENDTOLOGFILE ); ! 117: o->fVisual = RegQueryBOOL( hKeyDrWatson, REGKEY_VISUAL ); ! 118: o->fSound = RegQueryBOOL( hKeyDrWatson, REGKEY_SOUND ); ! 119: o->dwInstructions = RegQueryDWORD( hKeyDrWatson, REGKEY_INSTRUCTIONS ); ! 120: o->dwMaxCrashes = RegQueryDWORD( hKeyDrWatson, REGKEY_MAX_CRASHES ); ! 121: ! 122: return TRUE; ! 123: } ! 124: ! 125: BOOL ! 126: RegSaveAllValues( HKEY hKeyDrWatson, POPTIONS o ) ! 127: ! 128: /*++ ! 129: ! 130: Routine Description: ! 131: ! 132: This functions saves all registry data for DRWTSN32 that is passed ! 133: in via the OPTIONS structure. ! 134: ! 135: Arguments: ! 136: ! 137: hKeyDrWatson - handle to a registry key for DRWTSN32 registry data ! 138: o - pointer to an OPTIONS structure ! 139: ! 140: Return Value: ! 141: ! 142: TRUE - saved all data without error ! 143: FALSE - errors occurred and did not save all data ! 144: ! 145: --*/ ! 146: ! 147: { ! 148: RegSetSZ( hKeyDrWatson, REGKEY_LOG_PATH, o->szLogPath ); ! 149: RegSetSZ( hKeyDrWatson, REGKEY_WAVE_FILE, o->szWaveFile ); ! 150: RegSetBOOL( hKeyDrWatson, REGKEY_DUMPSYMBOLS, o->fDumpSymbols ); ! 151: RegSetBOOL( hKeyDrWatson, REGKEY_DUMPALLTHREADS, o->fDumpAllThreads ); ! 152: RegSetBOOL( hKeyDrWatson, REGKEY_APPENDTOLOGFILE, o->fAppendToLogFile ); ! 153: RegSetBOOL( hKeyDrWatson, REGKEY_VISUAL, o->fVisual ); ! 154: RegSetBOOL( hKeyDrWatson, REGKEY_SOUND, o->fSound ); ! 155: RegSetDWORD( hKeyDrWatson, REGKEY_INSTRUCTIONS, o->dwInstructions ); ! 156: RegSetDWORD( hKeyDrWatson, REGKEY_MAX_CRASHES, o->dwMaxCrashes ); ! 157: ! 158: return TRUE; ! 159: } ! 160: ! 161: BOOL ! 162: RegInitializeDefaults( HKEY hKeyDrWatson ) ! 163: ! 164: /*++ ! 165: ! 166: Routine Description: ! 167: ! 168: This functions initializes the registry with the default values. ! 169: ! 170: Arguments: ! 171: ! 172: hKeyDrWatson - handle to a registry key for DRWTSN32 registry data ! 173: ! 174: Return Value: ! 175: ! 176: TRUE - saved all data without error ! 177: FALSE - errors occurred and did not save all data ! 178: ! 179: --*/ ! 180: ! 181: { ! 182: OPTIONS o; ! 183: ! 184: GetWindowsDirectory( o.szLogPath, sizeof(o.szLogPath) ); ! 185: o.szWaveFile[0] = '\0'; ! 186: o.fDumpSymbols = FALSE; ! 187: o.fDumpAllThreads = TRUE; ! 188: o.fAppendToLogFile = TRUE; ! 189: o.fVisual = TRUE; ! 190: o.fSound = FALSE; ! 191: o.dwInstructions = 10; ! 192: o.dwMaxCrashes = 10; ! 193: ! 194: RegSetNumCrashes( 0 ); ! 195: ! 196: RegSaveAllValues( hKeyDrWatson, &o ); ! 197: ! 198: RegCreateEventSource(); ! 199: ! 200: return TRUE; ! 201: } ! 202: ! 203: BOOL ! 204: RegCreateEventSource( void ) ! 205: ! 206: /*++ ! 207: ! 208: Routine Description: ! 209: ! 210: This function creates an event source in the registry. The event ! 211: source is used by the event viewer to display the data in a ! 212: presentable manner. ! 213: ! 214: Arguments: ! 215: ! 216: None. ! 217: ! 218: Return Value: ! 219: ! 220: TRUE - saved all data without error ! 221: FALSE - errors occurred and did not save all data ! 222: ! 223: --*/ ! 224: ! 225: { ! 226: HKEY hk; ! 227: char szBuf[1024]; ! 228: DWORD dwDisp; ! 229: char szAppName[MAX_PATH]; ! 230: ! 231: GetAppName( szAppName, sizeof(szAppName) ); ! 232: strcpy( szBuf, REGKEY_EVENTLOG ); ! 233: strcat( szBuf, szAppName ); ! 234: if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, ! 235: szBuf, ! 236: 0, ! 237: NULL, ! 238: REG_OPTION_NON_VOLATILE, ! 239: KEY_QUERY_VALUE | KEY_SET_VALUE, ! 240: NULL, ! 241: &hk, ! 242: &dwDisp ! 243: )) { ! 244: return FALSE; ! 245: } ! 246: ! 247: if (dwDisp == REG_OPENED_EXISTING_KEY) { ! 248: RegCloseKey(hk); ! 249: return TRUE; ! 250: } ! 251: ! 252: strcpy( szBuf, REGKEY_SYSTEMROOT ); ! 253: strcat( szBuf, DRWATSON_EXE_NAME ); ! 254: RegSetEXPANDSZ( hk, REGKEY_MESSAGEFILE, szBuf ); ! 255: RegSetDWORD( hk, REGKEY_TYPESSUPP, EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE ); ! 256: ! 257: RegCloseKey(hk); ! 258: ! 259: return TRUE; ! 260: } ! 261: ! 262: HKEY ! 263: RegGetAppKey( void ) ! 264: ! 265: /*++ ! 266: ! 267: Routine Description: ! 268: ! 269: This function gets a handle to the DRWTSN32 registry key. ! 270: ! 271: Arguments: ! 272: ! 273: None. ! 274: ! 275: Return Value: ! 276: ! 277: Valid handle - handle opened ok ! 278: NULL - could not open the handle ! 279: ! 280: --*/ ! 281: ! 282: { ! 283: DWORD rc; ! 284: DWORD dwDisp; ! 285: HKEY hKeyDrWatson; ! 286: HKEY hKeyMicrosoft; ! 287: char szAppName[MAX_PATH]; ! 288: ! 289: rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE, ! 290: REGKEY_SOFTWARE, ! 291: 0, ! 292: KEY_QUERY_VALUE | KEY_SET_VALUE | ! 293: KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, ! 294: &hKeyMicrosoft ! 295: ); ! 296: ! 297: if (rc != ERROR_SUCCESS) { ! 298: return NULL; ! 299: } ! 300: ! 301: GetAppName( szAppName, sizeof(szAppName) ); ! 302: ! 303: rc = RegCreateKeyEx( hKeyMicrosoft, ! 304: szAppName, ! 305: 0, ! 306: NULL, ! 307: REG_OPTION_NON_VOLATILE, ! 308: KEY_READ | KEY_WRITE, ! 309: NULL, ! 310: &hKeyDrWatson, ! 311: &dwDisp ! 312: ); ! 313: ! 314: if (rc != ERROR_SUCCESS) { ! 315: return NULL; ! 316: } ! 317: ! 318: if (dwDisp == REG_CREATED_NEW_KEY) { ! 319: RegInitializeDefaults( hKeyDrWatson ); ! 320: } ! 321: ! 322: return hKeyDrWatson; ! 323: } ! 324: ! 325: BOOL ! 326: RegInitialize( POPTIONS o ) ! 327: ! 328: /*++ ! 329: ! 330: Routine Description: ! 331: ! 332: This function is used to initialize the OPTIONS structure passed in ! 333: with the current values in the registry. Note that if the registry ! 334: is empty then the defaults are stored in the registry and also ! 335: returned in the OPTIONS structure. ! 336: ! 337: Arguments: ! 338: ! 339: None. ! 340: ! 341: Return Value: ! 342: ! 343: TRUE - all data was retrieved ok ! 344: NULL - could not get all data ! 345: ! 346: --*/ ! 347: ! 348: { ! 349: HKEY hKeyDrWatson; ! 350: ! 351: hKeyDrWatson = RegGetAppKey(); ! 352: Assert( hKeyDrWatson != NULL ); ! 353: ! 354: if (!RegGetAllValues( o, hKeyDrWatson )) { ! 355: return FALSE; ! 356: } ! 357: ! 358: RegCloseKey( hKeyDrWatson ); ! 359: ! 360: return TRUE; ! 361: } ! 362: ! 363: BOOL ! 364: RegSave( POPTIONS o ) ! 365: ! 366: /*++ ! 367: ! 368: Routine Description: ! 369: ! 370: This function is used to save the data in the OPTIONS structure ! 371: to the registry. ! 372: ! 373: Arguments: ! 374: ! 375: o - pointer to an OPTIONS structure ! 376: ! 377: Return Value: ! 378: ! 379: TRUE - all data was saved ok ! 380: NULL - could not save all data ! 381: ! 382: --*/ ! 383: ! 384: { ! 385: HKEY hKeyDrWatson; ! 386: ! 387: hKeyDrWatson = RegGetAppKey(); ! 388: Assert( hKeyDrWatson != NULL ); ! 389: RegSaveAllValues( hKeyDrWatson, o ); ! 390: RegCloseKey( hKeyDrWatson ); ! 391: ! 392: return TRUE; ! 393: } ! 394: ! 395: void ! 396: RegSetNumCrashes( DWORD dwNumCrashes ) ! 397: ! 398: /*++ ! 399: ! 400: Routine Description: ! 401: ! 402: This function changes the value in the registry that contains the ! 403: number of crashes that have occurred. ! 404: ! 405: Arguments: ! 406: ! 407: dwNumCrashes - the number of craches to save ! 408: ! 409: Return Value: ! 410: ! 411: None. ! 412: ! 413: --*/ ! 414: ! 415: { ! 416: HKEY hKeyDrWatson; ! 417: ! 418: hKeyDrWatson = RegGetAppKey(); ! 419: Assert( hKeyDrWatson != NULL ); ! 420: RegSetDWORD( hKeyDrWatson, REGKEY_NUM_CRASHES, dwNumCrashes ); ! 421: RegCloseKey( hKeyDrWatson ); ! 422: ! 423: return; ! 424: } ! 425: ! 426: DWORD ! 427: RegGetNumCrashes( void ) ! 428: ! 429: /*++ ! 430: ! 431: Routine Description: ! 432: ! 433: This function get the value in the registry that contains the ! 434: number of crashes that have occurred. ! 435: ! 436: Arguments: ! 437: ! 438: None. ! 439: ! 440: Return Value: ! 441: ! 442: the number of craches that have occurred ! 443: ! 444: --*/ ! 445: ! 446: { ! 447: HKEY hKeyDrWatson; ! 448: DWORD dwNumCrashes; ! 449: ! 450: hKeyDrWatson = RegGetAppKey(); ! 451: Assert( hKeyDrWatson != NULL ); ! 452: dwNumCrashes = RegQueryDWORD( hKeyDrWatson, REGKEY_NUM_CRASHES ); ! 453: RegCloseKey( hKeyDrWatson ); ! 454: ! 455: return dwNumCrashes; ! 456: } ! 457: ! 458: BOOLEAN ! 459: RegInstallDrWatson( void ) ! 460: ! 461: /*++ ! 462: ! 463: Routine Description: ! 464: ! 465: This function gets a handle to the DRWTSN32 registry key. ! 466: ! 467: Arguments: ! 468: ! 469: None. ! 470: ! 471: Return Value: ! 472: ! 473: Valid handle - handle opened ok ! 474: NULL - could not open the handle ! 475: ! 476: --*/ ! 477: ! 478: { ! 479: DWORD rc; ! 480: HKEY hKeyMicrosoft; ! 481: ! 482: rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE, ! 483: REGKEY_AEDEBUG, ! 484: 0, ! 485: KEY_QUERY_VALUE | KEY_SET_VALUE, ! 486: &hKeyMicrosoft ! 487: ); ! 488: ! 489: if (rc != ERROR_SUCCESS) { ! 490: return FALSE; ! 491: } ! 492: ! 493: RegSetSZ( hKeyMicrosoft, REGKEY_AUTO, "1" ); ! 494: RegSetSZ( hKeyMicrosoft, REGKEY_DEBUGGER, "drwtsn32 -p %ld -e %ld -g" ); ! 495: ! 496: RegCloseKey( hKeyMicrosoft ); ! 497: ! 498: return TRUE; ! 499: } ! 500: ! 501: void ! 502: RegSetDWORD( HKEY hkey, char *szSubKey, DWORD dwValue ) ! 503: ! 504: /*++ ! 505: ! 506: Routine Description: ! 507: ! 508: This function changes a DWORD value in the registry using the ! 509: hkey and szSubKey as the registry key info. ! 510: ! 511: Arguments: ! 512: ! 513: hkey - handle to a registry key ! 514: szSubKey - pointer to a subkey string ! 515: dwValue - new registry value ! 516: ! 517: Return Value: ! 518: ! 519: None. ! 520: ! 521: --*/ ! 522: ! 523: { ! 524: DWORD rc; ! 525: ! 526: rc = RegSetValueEx( hkey, szSubKey, 0, REG_DWORD, (LPBYTE)&dwValue, 4 ); ! 527: Assert( rc == ERROR_SUCCESS ); ! 528: } ! 529: ! 530: void ! 531: RegSetBOOL( HKEY hkey, char *szSubKey, BOOL dwValue ) ! 532: ! 533: /*++ ! 534: ! 535: Routine Description: ! 536: ! 537: This function changes a BOOL value in the registry using the ! 538: hkey and szSubKey as the registry key info. ! 539: ! 540: Arguments: ! 541: ! 542: hkey - handle to a registry key ! 543: szSubKey - pointer to a subkey string ! 544: dwValue - new registry value ! 545: ! 546: Return Value: ! 547: ! 548: None. ! 549: ! 550: --*/ ! 551: ! 552: { ! 553: DWORD rc; ! 554: ! 555: rc = RegSetValueEx( hkey, szSubKey, 0, REG_DWORD, (LPBYTE)&dwValue, 4 ); ! 556: Assert( rc == ERROR_SUCCESS ); ! 557: } ! 558: ! 559: void ! 560: RegSetSZ( HKEY hkey, char *szSubKey, char *szValue ) ! 561: ! 562: /*++ ! 563: ! 564: Routine Description: ! 565: ! 566: This function changes a SZ value in the registry using the ! 567: hkey and szSubKey as the registry key info. ! 568: ! 569: Arguments: ! 570: ! 571: hkey - handle to a registry key ! 572: szSubKey - pointer to a subkey string ! 573: szValue - new registry value ! 574: ! 575: Return Value: ! 576: ! 577: None. ! 578: ! 579: --*/ ! 580: ! 581: { ! 582: DWORD rc; ! 583: ! 584: rc = RegSetValueEx( hkey, szSubKey, 0, REG_SZ, szValue, strlen(szValue)+1 ); ! 585: Assert( rc == ERROR_SUCCESS ); ! 586: } ! 587: ! 588: void ! 589: RegSetEXPANDSZ( HKEY hkey, char *szSubKey, char *szValue ) ! 590: ! 591: /*++ ! 592: ! 593: Routine Description: ! 594: ! 595: This function changes a SZ value in the registry using the ! 596: hkey and szSubKey as the registry key info. ! 597: ! 598: Arguments: ! 599: ! 600: hkey - handle to a registry key ! 601: szSubKey - pointer to a subkey string ! 602: szValue - new registry value ! 603: ! 604: Return Value: ! 605: ! 606: None. ! 607: ! 608: --*/ ! 609: ! 610: { ! 611: DWORD rc; ! 612: ! 613: rc = RegSetValueEx( hkey, szSubKey, 0, REG_EXPAND_SZ, szValue, strlen(szValue)+1 ); ! 614: Assert( rc == ERROR_SUCCESS ); ! 615: } ! 616: ! 617: BOOL ! 618: RegQueryBOOL( HKEY hkey, char *szSubKey ) ! 619: ! 620: /*++ ! 621: ! 622: Routine Description: ! 623: ! 624: This function queries BOOL value in the registry using the ! 625: hkey and szSubKey as the registry key info. If the value is not ! 626: found in the registry, it is added with a FALSE value. ! 627: ! 628: Arguments: ! 629: ! 630: hkey - handle to a registry key ! 631: szSubKey - pointer to a subkey string ! 632: ! 633: Return Value: ! 634: ! 635: TRUE or FALSE. ! 636: ! 637: --*/ ! 638: ! 639: { ! 640: DWORD rc; ! 641: DWORD len; ! 642: DWORD dwType; ! 643: BOOL fValue; ! 644: ! 645: len = 4; ! 646: rc = RegQueryValueEx( hkey, szSubKey, 0, &dwType, (LPBYTE)&fValue, &len ); ! 647: if (rc != ERROR_SUCCESS) { ! 648: if (rc == ERROR_FILE_NOT_FOUND) { ! 649: fValue = FALSE; ! 650: RegSetBOOL( hkey, szSubKey, fValue ); ! 651: } ! 652: else { ! 653: Assert( rc == ERROR_SUCCESS ); ! 654: } ! 655: } ! 656: else { ! 657: Assert( dwType == REG_DWORD ); ! 658: } ! 659: ! 660: return fValue; ! 661: } ! 662: ! 663: DWORD ! 664: RegQueryDWORD( HKEY hkey, char *szSubKey ) ! 665: ! 666: /*++ ! 667: ! 668: Routine Description: ! 669: ! 670: This function queries BOOL value in the registry using the ! 671: hkey and szSubKey as the registry key info. If the value is not ! 672: found in the registry, it is added with a zero value. ! 673: ! 674: Arguments: ! 675: ! 676: hkey - handle to a registry key ! 677: szSubKey - pointer to a subkey string ! 678: ! 679: Return Value: ! 680: ! 681: registry value ! 682: ! 683: --*/ ! 684: ! 685: { ! 686: DWORD rc; ! 687: DWORD len; ! 688: DWORD dwType; ! 689: DWORD fValue; ! 690: ! 691: len = 4; ! 692: rc = RegQueryValueEx( hkey, szSubKey, 0, &dwType, (LPBYTE)&fValue, &len ); ! 693: if (rc != ERROR_SUCCESS) { ! 694: if (rc == ERROR_FILE_NOT_FOUND) { ! 695: fValue = 0; ! 696: RegSetDWORD( hkey, szSubKey, fValue ); ! 697: } ! 698: else { ! 699: Assert( rc == ERROR_SUCCESS ); ! 700: } ! 701: } ! 702: else { ! 703: Assert( dwType == REG_DWORD ); ! 704: } ! 705: ! 706: return fValue; ! 707: } ! 708: ! 709: void ! 710: RegQuerySZ( HKEY hkey, char *szSubKey, char *szValue ) ! 711: ! 712: /*++ ! 713: ! 714: Routine Description: ! 715: ! 716: This function queries BOOL value in the registry using the ! 717: hkey and szSubKey as the registry key info. If the value is not ! 718: found in the registry, it is added with a zero value. ! 719: ! 720: Arguments: ! 721: ! 722: hkey - handle to a registry key ! 723: szSubKey - pointer to a subkey string ! 724: ! 725: Return Value: ! 726: ! 727: registry value ! 728: ! 729: --*/ ! 730: ! 731: { ! 732: DWORD rc; ! 733: DWORD len; ! 734: DWORD dwType; ! 735: char buf[1024]; ! 736: ! 737: len = sizeof(buf); ! 738: rc = RegQueryValueEx( hkey, szSubKey, 0, &dwType, (LPBYTE)buf, &len ); ! 739: if (rc != ERROR_SUCCESS) { ! 740: if (rc == ERROR_FILE_NOT_FOUND) { ! 741: buf[0] = 0; ! 742: RegSetSZ( hkey, szSubKey, buf ); ! 743: } ! 744: else { ! 745: Assert( rc == ERROR_SUCCESS ); ! 746: } ! 747: } ! 748: else { ! 749: Assert( dwType == REG_SZ ); ! 750: } ! 751: ! 752: strcpy( szValue, buf ); ! 753: } ! 754: ! 755: void ! 756: RegLogCurrentVersion( void ) ! 757: { ! 758: char buf[1024]; ! 759: DWORD rc; ! 760: HKEY hKeyCurrentVersion; ! 761: ! 762: rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE, ! 763: REGKEY_CURRENTVERSION, ! 764: 0, ! 765: KEY_QUERY_VALUE, ! 766: &hKeyCurrentVersion ! 767: ); ! 768: ! 769: if (rc != ERROR_SUCCESS) { ! 770: return; ! 771: } ! 772: ! 773: RegQuerySZ( hKeyCurrentVersion,REGKEY_CURRENT_BUILD, buf ); ! 774: lprintf( MSG_CURRENT_BUILD, buf ); ! 775: RegQuerySZ( hKeyCurrentVersion,REGKEY_CURRENT_TYPE, buf ); ! 776: lprintf( MSG_CURRENT_TYPE, buf ); ! 777: RegQuerySZ( hKeyCurrentVersion,REGKEY_REG_ORGANIZATION, buf ); ! 778: lprintf( MSG_REG_ORGANIZATION, buf ); ! 779: RegQuerySZ( hKeyCurrentVersion,REGKEY_REG_OWNER, buf ); ! 780: lprintf( MSG_REG_OWNER, buf ); ! 781: ! 782: return; ! 783: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.