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.

218 lines
5.8 KiB

  1. #
  2. # Uninstall.pl
  3. #
  4. # Author: Michael Smith ([email protected])
  5. #
  6. # Copyright � 1998 ActiveState Tool Corp., all rights reserved.
  7. #
  8. ###########################################################
  9. use Win32::Registry;
  10. use File::Find;
  11. use MetabaseConfig;
  12. my $data_file = $ARGV[0];
  13. my $ENVIRONMENT_KEY = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
  14. ReadData();
  15. UninstallDependents();
  16. Warn();
  17. CleanPath();
  18. RemoveIISVirtDirs();
  19. RemoveIISScriptMaps();
  20. RemoveLinesFromFiles();
  21. RemoveDirectories();
  22. RemoveFiles();
  23. CallInstallShield();
  24. print <<"EOF";
  25. \007
  26. \007
  27. Note: If you intend to re-install ActivePerl, you *must* reboot your system
  28. before doing so.
  29. Press any key to exit...
  30. EOF
  31. exit(0);
  32. sub ReadData {
  33. print "Reading uninstall data...\n";
  34. my $data = '';
  35. $rv = open(DATA, "<$data_file");
  36. if($rv) {
  37. map($data .= $_, <DATA>);
  38. close(DATA);
  39. eval($data);
  40. }else{
  41. die "Error reading uninstallation data file. Aborting!!";
  42. }
  43. }
  44. sub Warn {
  45. print "This will uninstall $app_name. Do you wish to continue?\n";
  46. print "[y|N] ==>";
  47. my $response = '';
  48. while(($response = <STDIN>) !~ /^[\nyn]/i){};
  49. if($response !~ /^y/i) {
  50. print "Aborting $app_name uninstallation!\n";
  51. exit(0);
  52. }
  53. }
  54. sub UninstallDependents {
  55. my $RegObj = 0;
  56. my $UninstallString = '';
  57. my $type = 0;
  58. my $rv = 0;
  59. foreach $dependent (@$dependents) {
  60. print "$dependent is dependent on $app_name\n" .
  61. "and will not function correctly without it.\n" .
  62. "Would you like to uninstall $dependent?\n" .
  63. "[y|n] ==>";
  64. while(($response = <STDIN>) !~ /[yn]/i){};
  65. if($response =~ /y/i) {
  66. $rv = $HKEY_LOCAL_MACHINE->Open("software\\microsoft\\windows\\currentversion\\uninstall\\$dependent", $RegObj);
  67. if($rv) {
  68. $rv = $RegObj->QueryValueEx("UninstallString", $type, $UninstallString);
  69. if($rv) {
  70. $RegObj->Close();
  71. print $UninstallString;
  72. print "Uninstalling $dependent...\n";
  73. $rv = (system($UninstallString) ? 0 : 1);
  74. }
  75. }
  76. if(!$rv) {
  77. print "Error uninstalling $dependent!\n\n";
  78. }
  79. }
  80. }
  81. }
  82. sub CleanPath {
  83. if(@$path_info) {
  84. print "Cleaning PATH...\n";
  85. my $path = '';
  86. if(Win32::IsWinNT) {
  87. my $Environment = 0;
  88. if($HKEY_LOCAL_MACHINE->Open($ENVIRONMENT_KEY, $Environment)) {
  89. if($Environment->QueryValueEx("PATH", $type, $path)) {
  90. for $dir (@$path_info) {
  91. $dir =~ s/\\/\\\\/g;
  92. $path =~ s/$dir;?//ig;
  93. }
  94. $Environment->SetValueEx("PATH", -1, $type, $path);
  95. }
  96. }
  97. } else {
  98. my $file = "$ENV{'SystemDrive'}/autoexec.bat";
  99. if(open(FILE, "<$file")) {
  100. my @statements = <FILE>;
  101. close(FILE);
  102. my $path = '';
  103. for $statement (@statements) {
  104. if($statement =~ /\s+path\s?=/i) {
  105. $path = $statement;
  106. for $dir (@$path_info) {
  107. $dir =~ s/\\/\\\\/g;
  108. $path =~ s/$dir;?//ig;
  109. }
  110. }
  111. }
  112. if(open(FILE, ">$file")) {
  113. print FILE @statements;
  114. close(FILE);
  115. }
  116. }
  117. }
  118. }
  119. }
  120. sub RemoveIISVirtDirs {
  121. if(@$iis_virt_dir) {
  122. print "Removing IIS4 virtual directories...\n";
  123. for $virt_dir (@$iis_virt_dir) {
  124. $rv = MetabaseConfig::DeleteVirDir(1, $virt_dir);
  125. if($rv =~ /^Error/i){
  126. print "$rv\n";
  127. system('pause');
  128. }
  129. }
  130. }
  131. }
  132. sub RemoveIISScriptMaps {
  133. if(keys %$iis_script_map) {
  134. print "Removing IIS4 script maps...\n";
  135. my $virt_dir = '';
  136. for $key (keys %$iis_script_map) {
  137. print "Virtual Directory ==> $key\n";
  138. for $script_map (@{$iis_script_map->{$key}}) {
  139. print "\t$key ==> $script_map\n";
  140. $virt_dir = $key;
  141. $virt_dir = ($virt_dir eq '.' ? '' : $virt_dir);
  142. $rv = MetabaseConfig::RemoveFileExtMapping(1, $virt_dir, $script_map);
  143. if($rv =~ /^Error/i){
  144. print "$rv\n";
  145. system('pause');
  146. }
  147. }
  148. }
  149. }
  150. }
  151. sub RemoveLinesFromFiles {
  152. my $file;
  153. foreach $file (keys %$lines_in_file) {
  154. open(FILE, "<$file") or next;
  155. my @lines = <FILE>;
  156. close(FILE);
  157. open(FILE, ">$file") or next;
  158. LINE: foreach $line (@lines) {
  159. chomp $line;
  160. for ($offset = 0; $offset <= $#{$$lines_in_file{$file}}; $offset++) {
  161. if ($line eq $$lines_in_file{$file}[$offset]) {
  162. splice(@{$$lines_in_file{$file}}, $offset, 1);
  163. next LINE;
  164. }
  165. }
  166. print FILE "$line\n";
  167. }
  168. close(FILE);
  169. }
  170. }
  171. sub RemoveDirectories {
  172. if(@$directory) {
  173. print "Removing directories...\n";
  174. for $dir (@$directory) {
  175. finddepth(\&DeleteFiles, $dir);
  176. rmdir($dir);
  177. }
  178. }
  179. }
  180. sub RemoveFiles {
  181. if(@$file) {
  182. print "Removing files...\n";
  183. for $file (@$file) {
  184. unlink($file);
  185. }
  186. }
  187. }
  188. sub CallInstallShield {
  189. print "Calling InstallShield...\n";
  190. system("start $is_uninstall_string");
  191. }
  192. sub DeleteFiles {
  193. if(-d $File::Find::name) {
  194. rmdir("$File::Find::name");
  195. } else {
  196. unlink("$File::Find::name");
  197. }
  198. }