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.

103 lines
2.6 KiB

  1. use Win32::Registry;
  2. my ($type, $value, $uc, $urt);
  3. my $version = "";
  4. my $ms = "";
  5. ###
  6. ### It appears that if you install recent URT builds and then uninstall,
  7. ### the entire .NETFramework key gets blown away. Thus, we'll create it if
  8. ### so necessary.
  9. ###
  10. if (!$::HKEY_LOCAL_MACHINE->Open('SOFTWARE\Microsoft\.NETFramework', $urt)) {
  11. ###
  12. ### This cannot fail (right?).
  13. ###
  14. if (!$::HKEY_LOCAL_MACHINE->Open('SOFTWARE\Microsoft', $ms)) {
  15. die "Couldn't open HKLM\Software\Microsoft key: $!\n";
  16. }
  17. $ms->Create('.NETFramework', $value);
  18. $::HKEY_LOCAL_MACHINE->Open('SOFTWARE\Microsoft\.NETFramework', $urt);
  19. }
  20. if ($urt->Open('policy\v1.0', $policy)) {
  21. ###
  22. ### This machine has some version of the URT installed.
  23. ###
  24. $policy->GetValues(\%values);
  25. foreach (sort(keys(%values))) {
  26. if (/^\d+$/) {
  27. $version = $_;
  28. if ($_ == $ARGV[1]) {
  29. last;
  30. }
  31. }
  32. }
  33. ###
  34. ### If no "backup" of this key exists, make one.
  35. ###
  36. if (!$::HKEY_LOCAL_MACHINE->Open('SOFTWARE\Microsoft\.NETFramework.BAK', $uc)) {
  37. $::HKEY_LOCAL_MACHINE->Open('SOFTWARE\Microsoft', $ms) unless ($ms);
  38. $ms->Create('.NETFramework.BAK', $target);
  39. &BackupKey($urt, $target);
  40. }
  41. if ($urt->QueryValueEx("InstallRoot", $type, $value)) {
  42. if ($value eq $ARGV[0]) {
  43. if ($version != $ARGV[1]) {
  44. ###
  45. ### The InstallRoot matches ours but the version is different, nuke the
  46. ### GAC of things we might have stored there.
  47. system("$ENV{'URTINSTALL'}\\gacclean.cmd");
  48. exit(0);
  49. }
  50. #
  51. # InstallRoot matches as does version - we're done.
  52. #
  53. exit(2);
  54. } else {
  55. if ($version == $ARGV[1]) {
  56. #
  57. # InstallRoot differs, but version matches - assume all is well for now.
  58. #
  59. exit (2);
  60. }
  61. }
  62. }
  63. }
  64. # No record of install or the install path and version doesn't match.
  65. exit(0);
  66. ###
  67. ### Makes a deep copy of a particular reg key.
  68. ###
  69. sub BackupKey($$)
  70. {
  71. my $srckey = shift;
  72. my $targetkey = shift;
  73. my ($subskey, $subtkey, @keys, %values);
  74. $srckey->GetKeys(\@keys);
  75. foreach (@keys) {
  76. $srckey->Open($_, $subskey);
  77. $targetkey->Create($_, $subtkey);
  78. BackupKey($subskey, $subtkey);
  79. }
  80. $srckey->GetValues(\%values);
  81. foreach (keys(%values)) {
  82. $targetkey->SetValueEx($_, 0, $values{$_}->[1], $values{$_}->[2]);
  83. }
  84. }
  85. __END__